Skip to content

Commit

Permalink
login: make userpass login optional
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Nov 25, 2024
1 parent c99cccc commit b67504a
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 49 deletions.
2 changes: 2 additions & 0 deletions src/component-library/demos/01_0_Login_MultiVO.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const ABasicLogin: Story = {
args: {
loginViewModel: {
status: 'success',
userpassEnabled: true,
x509Enabled: false,
oidcEnabled: false,
oidcProviders: [cernOIDCProvider],
Expand Down Expand Up @@ -86,6 +87,7 @@ export const ABasicMultiVOLogin: Story = {
args: {
loginViewModel: {
status: 'success',
userpassEnabled: true,
x509Enabled: true,
oidcEnabled: false,
oidcProviders: [cernOIDCProvider],
Expand Down
1 change: 1 addition & 0 deletions src/component-library/demos/01_1_Login.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const Playbook_InitLogin: Story = {
args: {
loginViewModel: {
status: 'success',
userpassEnabled: true,
x509Enabled: true,
oidcEnabled: true,
oidcProviders: [cernOIDCProvider],
Expand Down
1 change: 1 addition & 0 deletions src/component-library/demos/01_1_Login_OIDC.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const AMultiVOOIDCEnabledLogin: Story = {
args: {
loginViewModel: {
status: 'success',
userpassEnabled: true,
x509Enabled: true,
oidcEnabled: true,
oidcProviders: [cernOIDCProvider],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const Playbook_Multi_Account: Story = {
args: {
loginViewModel: {
status: 'success',
userpassEnabled: true,
x509Enabled: true,
oidcEnabled: true,
oidcProviders: [cernOIDCProvider],
Expand Down
1 change: 1 addition & 0 deletions src/component-library/pages/legacy/Login/Login.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const LoginPage = Template.bind({});
LoginPage.args = {
loginViewModel: {
status: 'success',
userpassEnabled: true,
x509Enabled: true,
oidcEnabled: true,
oidcProviders: [cernOIDCProvider],
Expand Down
98 changes: 50 additions & 48 deletions src/component-library/pages/legacy/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export const Login = ({
oidcSubmitHandler: handleOIDCSubmit,
}: LoginPageProps) => {
const isLoggedIn = loginViewModel.isLoggedIn && loginViewModel.accountActive !== undefined;

const [showUserPassLoginForm, setShowUserPassLoginForm] = useState<boolean>(false);

const [selectedVOTab, setSelectedVOTab] = useState<number>(1);
Expand Down Expand Up @@ -226,59 +225,62 @@ export const Login = ({
)}

<Button label="x509" onClick={() => submitX509(inputAccount)} />

<Button
label="Userpass"
onClick={() => {
setShowUserPassLoginForm(!showUserPassLoginForm);
}}
/>
<form>
<fieldset
className={twMerge('flex flex-col space-y-2', 'mx-2 md:mx-10', showUserPassLoginForm ? '' : 'hidden')}
aria-label="Userpass Login Fields"
id="userpass-form"
>
<div className={twMerge('flex flex-col space-y-1')}>
<LabelledInput
label="Username"
idinput="username-input"
updateFunc={(data: string) => {
setUsername(data);
}}
/>
<LabelledInput
label="Password"
idinput="password-input"
updateFunc={(data: string) => {
setPassword(data);
}}
password={true}
/>
{loginViewModel.userpassEnabled && (
<div id="userpass-login">
<Button
label="Userpass"
onClick={() => {
setShowUserPassLoginForm(!showUserPassLoginForm);
}}
/>
<form>
<fieldset
className={twMerge('flex flex-col space-y-2', 'mx-2 md:mx-10', showUserPassLoginForm ? '' : 'hidden')}
aria-label="Userpass Login Fields"
id="userpass-form"
>
<div className={twMerge('flex flex-col space-y-1')}>
<LabelledInput
label="Username"
idinput="username-input"
updateFunc={(data: string) => {
setUsername(data);
}}
/>
<LabelledInput
label="Password"
idinput="password-input"
updateFunc={(data: string) => {
setPassword(data);
}}
password={true}
/>
<LabelledInput
label="Account"
idinput="account-input"
updateFunc={(data: string) => {
setInputAccount(data);
}}
/>
</div>
<Button label="Login" type="submit" role="button" onClick={() => submitUserPass(inputAccount)} />
</fieldset>
</form>
<fieldset
className={twMerge('mx-2 md:mx-10', !showUserPassLoginForm ? 'block' : 'hidden')}
aria-label="Choose Account Name"
id="all-accounts"
>
<LabelledInput
label="Account"
idinput="account-input"
idinput="account-input-nouserpass"
updateFunc={(data: string) => {
setInputAccount(data);
}}
/>
</div>
<Button label="Login" type="submit" role="button" onClick={() => submitUserPass(inputAccount)} />
</fieldset>
</form>
<fieldset
className={twMerge('mx-2 md:mx-10', !showUserPassLoginForm ? 'block' : 'hidden')}
aria-label="Choose Account Name"
id="all-accounts"
>
<LabelledInput
label="Account"
idinput="account-input-nouserpass"
updateFunc={(data: string) => {
setInputAccount(data);
}}
/>
</fieldset>
</fieldset>
</div>
)}
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/dto/login-config-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BaseDTO } from '@/lib/sdk/dto';
import { OIDCProvider, VO } from '@/lib/core/entity/auth-models';

export interface LoginConfigDTO extends BaseDTO {
userpassEnabled: boolean;
x509Enabled: boolean;
oidcEnabled: boolean;
multiVOEnabled: boolean;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/core/port/secondary/env-config-gateway-output-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export default interface EnvConfigGatewayOutputPort {
*/
x509Enabled(): Promise<boolean>;

/**
* @returns true if userpass is enabled, false otherwise.
*/
userpassEnabled(): Promise<boolean>;

/**
* @returns the URL of the Rucio Auth service
* @throws {@link ConfigNotFound} if RUCIO_AUTH_HOST is not found
Expand Down
4 changes: 4 additions & 0 deletions src/lib/core/use-case/login-config-usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class LoginConfigUseCase
this.envConfigGateway.voList(),
this.envConfigGateway.oidcProviders(),
this.envConfigGateway.rucioAuthHost(),
this.envConfigGateway.userpassEnabled(),
]);
const responseModel: LoginConfigDTO = {
status: 'success',
Expand All @@ -38,6 +39,7 @@ class LoginConfigUseCase
voList: config[3],
oidcProviders: config[4],
rucioAuthHost: config[5],
userpassEnabled: config[6],
};
return responseModel;
} catch (error) {
Expand All @@ -53,6 +55,7 @@ class LoginConfigUseCase
errorName: type,
x509Enabled: false,
oidcEnabled: false,
userpassEnabled: false,
multiVOEnabled: false,
voList: [],
oidcProviders: [],
Expand Down Expand Up @@ -95,6 +98,7 @@ class LoginConfigUseCase
data: {
status: 'success',
x509Enabled: dto.x509Enabled,
userpassEnabled: dto.userpassEnabled,
oidcEnabled: dto.oidcEnabled,
multiVOEnabled: dto.multiVOEnabled,
voList: dto.voList,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/core/usecase-models/login-config-usecase-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { OIDCProvider, VO } from '../entity/auth-models';
/**
* Response Model for {@link LoginConfigOutputPort}
* @property x509Enabled: true if x509 login is enabled
* @property userpassEnabled: true if userpass login is enabled
* @property oidcEnabled: true if oidc login is enabled
* @property oidcProviders: List of oidc providers
* @property multiVOEnabled: true if multi vo login is enabled
* @property voList: List of VOs
*/
export interface LoginConfigResponse extends BaseResponseModel {
x509Enabled: boolean;
userpassEnabled: boolean;
oidcEnabled: boolean;
oidcProviders: OIDCProvider[];
multiVOEnabled: boolean;
Expand Down
8 changes: 8 additions & 0 deletions src/lib/infrastructure/gateway/env-config-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ class EnvConfigGateway implements EnvConfigGatewayOutputPort {
return Promise.resolve(true);
}

async userpassEnabled(): Promise<boolean> {
const value = await this.get('ENABLE_USERPASS_LOGIN');
if (value === 'true' || value === 'True' || value === 'TRUE') {
return Promise.resolve(true);
}
return Promise.resolve(false);
}

async ruleActivity(): Promise<string> {
const value = await this.get('RULE_ACTIVITY');
// Return a default value if the environmental variable is not specified
Expand Down
4 changes: 3 additions & 1 deletion src/lib/infrastructure/presenter/login-config-presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class LoginConfigPresenter
}
const viewModel: LoginViewModel = {
status: 'success',
userpassEnabled: responseModel.userpassEnabled,
x509Enabled: responseModel.x509Enabled,
oidcEnabled: responseModel.oidcEnabled,
multiVOEnabled: responseModel.multiVOEnabled,
Expand All @@ -38,7 +39,8 @@ export default class LoginConfigPresenter
convertErrorModelToViewModel(errorModel: LoginConfigError): { viewModel: LoginViewModel; status: number } {
const viewModel: LoginViewModel = {
status: 'error',
x509Enabled: true,
userpassEnabled: false,
x509Enabled: false,
oidcEnabled: false,
multiVOEnabled: false,
voList: [],
Expand Down

0 comments on commit b67504a

Please sign in to comment.