Skip to content

Commit

Permalink
feat(auth): add sso frontend endpoint (#6273)
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-radhakrishnan authored Oct 31, 2022
1 parent 9e6489f commit 4b31204
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 15 deletions.
13 changes: 13 additions & 0 deletions datahub-frontend/app/controllers/AuthenticationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
public class AuthenticationController extends Controller {

private static final String AUTH_REDIRECT_URI_PARAM = "redirect_uri";
private static final String ERROR_MESSAGE_URI_PARAM = "error_msg";
private static final String SSO_DISABLED_ERROR_MESSAGE = "SSO is not configured";

private final Logger _logger = LoggerFactory.getLogger(AuthenticationController.class.getName());
private final Config _configs;
Expand Down Expand Up @@ -102,6 +104,17 @@ public Result authenticate(Http.Request request) {
: DEFAULT_SESSION_TTL_HOURS));
}

/**
* Redirect to the identity provider for authentication.
*/
@Nonnull
public Result sso() {
if (_ssoManager.isSsoEnabled()) {
return redirectToIdentityProvider();
}
return redirect(LOGIN_ROUTE + String.format("?%s=%s", ERROR_MESSAGE_URI_PARAM, SSO_DISABLED_ERROR_MESSAGE));
}

/**
* Log in a user based on a username + password.
*
Expand Down
15 changes: 4 additions & 11 deletions datahub-frontend/app/controllers/CentralLogoutController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,15 @@
*/
@Slf4j
public class CentralLogoutController extends LogoutController {

private static final String AUTH_BASE_URL_CONFIG_PATH = "auth.baseUrl";
private static final String DEFAULT_BASE_URL_PATH = "/";
private static final String DEFAULT_BASE_URL_PATH = "/login";
private static Boolean _isOidcEnabled = false;

@Inject
public CentralLogoutController(Config config) {

String authBaseUrl = config.hasPath(AUTH_BASE_URL_CONFIG_PATH)
? config.getString(AUTH_BASE_URL_CONFIG_PATH)
: DEFAULT_BASE_URL_PATH;

_isOidcEnabled = config.hasPath("auth.oidc.enabled") && config.getBoolean("auth.oidc.enabled");

setDefaultUrl(authBaseUrl);
setLogoutUrlPattern(authBaseUrl + ".*");
setDefaultUrl(DEFAULT_BASE_URL_PATH);
setLogoutUrlPattern(DEFAULT_BASE_URL_PATH + ".*");
setLocalLogout(true);
setCentralLogout(true);

Expand All @@ -50,6 +43,6 @@ public Result executeLogout() throws ExecutionException, InterruptedException {
+ "or refer to server logs for more information.")));
}
}
return redirect("/").withNewSession();
return redirect(DEFAULT_BASE_URL_PATH).withNewSession();
}
}
1 change: 1 addition & 0 deletions datahub-frontend/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GET /config co

# Authentication in React
GET /authenticate controllers.AuthenticationController.authenticate(request: Request)
GET /sso controllers.AuthenticationController.sso()
POST /logIn controllers.AuthenticationController.logIn(request: Request)
POST /signUp controllers.AuthenticationController.signUp(request: Request)
POST /resetNativeUserCredentials controllers.AuthenticationController.resetNativeUserCredentials(request: Request)
Expand Down
12 changes: 11 additions & 1 deletion datahub-web-react/src/app/analytics/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export enum EventType {
UpdateIngestionSourceEvent,
DeleteIngestionSourceEvent,
ExecuteIngestionSourceEvent,
SsoEvent,
}

/**
Expand Down Expand Up @@ -349,6 +350,8 @@ export interface CreateDomainEvent extends BaseEvent {
type: EventType.CreateDomainEvent;
}

// Managed Ingestion Events

export interface CreateIngestionSourceEvent extends BaseEvent {
type: EventType.CreateIngestionSourceEvent;
sourceType: string;
Expand All @@ -369,6 +372,11 @@ export interface ExecuteIngestionSourceEvent extends BaseEvent {
type: EventType.ExecuteIngestionSourceEvent;
}

// TODO: Find a way to use this event
export interface SsoEvent extends BaseEvent {
type: EventType.SsoEvent;
}

/**
* Event consisting of a union of specific event types.
*/
Expand Down Expand Up @@ -414,4 +422,6 @@ export type Event =
| CreateIngestionSourceEvent
| UpdateIngestionSourceEvent
| DeleteIngestionSourceEvent
| ExecuteIngestionSourceEvent;
| ExecuteIngestionSourceEvent
| ShowStandardHomepageEvent
| SsoEvent;
35 changes: 32 additions & 3 deletions datahub-web-react/src/app/auth/LogIn.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useCallback, useState } from 'react';
import * as QueryString from 'query-string';
import { Input, Button, Form, message, Image } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import { Input, Button, Form, message, Image, Divider } from 'antd';
import { UserOutlined, LockOutlined, LoginOutlined } from '@ant-design/icons';
import { useReactiveVar } from '@apollo/client';
import styled, { useTheme } from 'styled-components';
import styled, { useTheme } from 'styled-components/macro';
import { Redirect, useLocation } from 'react-router';
import styles from './login.module.css';
import { Message } from '../shared/Message';
Expand Down Expand Up @@ -38,6 +38,29 @@ const FormInput = styled(Input)`
}
`;

const SsoDivider = styled(Divider)`
background-color: white;
`;

const SsoButton = styled(Button)`
&&& {
align-self: center;
display: flex;
justify-content: center;
align-items: center;
padding: 5.6px 11px;
gap: 4px;
}
`;

const LoginLogo = styled(LoginOutlined)`
padding-top: 7px;
`;

const SsoTextSpan = styled.span`
padding-top: 6px;
`;

export type LogInProps = Record<string, never>;

export const LogIn: React.VFC<LogInProps> = () => {
Expand Down Expand Up @@ -128,6 +151,12 @@ export const LogIn: React.VFC<LogInProps> = () => {
}}
</Form.Item>
</Form>
<SsoDivider />
<SsoButton type="primary" href="/sso" block htmlType="submit" className={styles.sso_button}>
<LoginLogo />
<SsoTextSpan>Sign in with SSO</SsoTextSpan>
<span />
</SsoButton>
</div>
</div>
</div>
Expand Down
14 changes: 14 additions & 0 deletions datahub-web-react/src/app/auth/login.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@
background-color: transparent;
border: 1px solid #555555;
}

.sso_button {
color: #EEEEEE;
background-color: #171717;
border: 1px solid #555555;
height: 40px;
font-size: 14px;
}

.sso_button:hover {
color: black;
background-color: white;
border: 1px solid #555555;
}

0 comments on commit 4b31204

Please sign in to comment.