Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide rule-based password expiry for users missing required scopes #7224

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/lemon-pets-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wso2is/admin.validation.v1": patch
"@wso2is/console": patch
---

Disable rule based password expiry for users without required scopes
4 changes: 1 addition & 3 deletions apps/console/src/public/deployment.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,7 @@
"console:loginAndRegistration"
],
"read": [
"internal_governance_view",
PasinduYeshan marked this conversation as resolved.
Show resolved Hide resolved
"internal_group_mgt_view",
"internal_role_mgt_view"
"internal_governance_view"
],
"update": [
"internal_config_update",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export class ValidationConfigConstants {
PASSWORD_MIN_VALUE: 5
};

/**
* These scopes are checked to determine whether to display the new rule-based password expiry configuration UI.
* If these scopes are not available, legacy password expiry configuration will be shown for backward compatibility.
*/
public static readonly RULE_BASED_PASSWORD_EXPIRY_REQUIRED_SCOPES: string[] = [
Copy link
Contributor

@pavinduLakshan pavinduLakshan Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a new feature object for this in the deployment config instead, so that deployment config would be the single source for maintaining scopes on the frontend

"internal_role_mgt_view",
"internal_group_mgt_view"
];
}

/**
Expand Down
22 changes: 16 additions & 6 deletions features/admin.validation.v1/pages/validation-config-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
state?.config?.ui?.isPasswordInputValidationEnabled);
const disabledFeatures: string[] = useSelector((state: AppState) =>
state?.config?.ui?.features?.loginAndRegistration?.disabledFeatures);
const isRuleBasedPasswordExpiryDisabled: boolean = disabledFeatures?.includes("ruleBasedPasswordExpiry");
const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state?.config?.ui?.features);

const [ isSubmitting, setSubmitting ] = useState<boolean>(false);
Expand Down Expand Up @@ -137,6 +136,10 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
const [ legacyPasswordPolicies, setLegacyPasswordPolicies ] = useState<ConnectorPropertyInterface[]>([]);

const isReadOnly: boolean = !useRequiredScopes(featureConfig?.governanceConnectors?.scopes?.update);
const hasScopesForRuleBasedPasswordExpiry: boolean =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's follow the convention.

Suggested change
const hasScopesForRuleBasedPasswordExpiry: boolean =
const hasRuleBasedPasswordExpiryReadPermissions: boolean =

useRequiredScopes(ValidationConfigConstants.RULE_BASED_PASSWORD_EXPIRY_REQUIRED_SCOPES);
const isRuleBasedPasswordExpiryDisabled: boolean = disabledFeatures?.includes("ruleBasedPasswordExpiry")
Copy link
Contributor

@pavinduLakshan pavinduLakshan Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add "ruleBasedPasswordExpiry" string to the feature dictionary and use the constant here.

Ref. impl:

public static readonly FEATURE_DICTIONARY: Map<string, string> = new Map<string, string>()
.set("APPLICATION_ADD", "application.add")
.set("APPLICATION_EDIT", "application.edit")
.set("APPLICATION_EDIT_GENERAL_SETTINGS", "application.edit.generalSettings")
.set("APPLICATION_EDIT_ACCESS_CONFIG", "applications.edit.accessConfiguration")
.set("APPLICATION_EDIT_ATTRIBUTE_MAPPING", "applications.edit.attributeMapping")
.set("APPLICATION_EDIT_SIGN_ON_METHOD_CONFIG", "applications.edit.signOnMethodConfiguration")
.set("APPLICATION_EDIT_PROVISIONING_SETTINGS", "applications.edit.provisioningSettings")
.set("APPLICATION_EDIT_ADVANCED_SETTINGS", "applications.edit.advancedSettings")
.set("APPLICATION_SHARED_ACCESS", "applications.edit.sharedAccess")
.set("APPLICATION_EDIT_INFO", "applications.edit.info")
.set("FAPI_APP_CREATION", "applications.create.fapi")
.set("APPLICATION_NATIVE_AUTHENTICATION", "applications.native.authentication")
.set("APPLICATION_MYACCOUNT_SAAS_SETTINGS", "applications.myaccount.saasMyaccountSettings")
.set("APPLICATION_ADD_MANAGEMENT_APPLICATIONS", "applications.add.managementApplications")
.set("APPLICATIONS_SETTINGS", "applications.settings")
.set("TRUSTED_APPS", "applications.trustedApps")
.set("APPLICATION_ACCESSTOKEN_ATTRIBUTES", "applications.accessTokenAttributes")
.set("APPLICATION_OUTDATED_APP_BANNER", "applications.outdatedAppBanner");

|| !hasScopesForRuleBasedPasswordExpiry;

const {
data: passwordHistoryCountData,
Expand Down Expand Up @@ -600,14 +603,21 @@ export const ValidationConfigEditPage: FunctionComponent<MyAccountSettingsEditPa
): void => {
if (hasPasswordExpiryRuleErrors) return;

const processedFormValues: ValidationFormInterface = {
let processedFormValues: ValidationFormInterface = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep this const and add new object properties.

const obj = {
a: "b",
c: "d"
}

obj.e = "f"

...values,
passwordExpiryEnabled: passwordExpiryEnabled,
passwordExpiryRules: processPasswordExpiryRules(),
passwordExpirySkipFallback: passwordExpirySkipFallback,
passwordExpiryTime: defaultPasswordExpiryTime
passwordExpiryEnabled: passwordExpiryEnabled
};

if (!isRuleBasedPasswordExpiryDisabled) {
processedFormValues = {
...values,
passwordExpiryEnabled: passwordExpiryEnabled,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already added in L608, isn't it?

passwordExpiryRules: processPasswordExpiryRules(),
passwordExpirySkipFallback: passwordExpirySkipFallback,
passwordExpiryTime: defaultPasswordExpiryTime
};
}

const updatePasswordPolicies: Promise<void> = serverConfigurationConfig.processPasswordPoliciesSubmitData(
processedFormValues,
!isPasswordInputValidationEnabled
Expand Down
Loading