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

Fix pre process username method when input validation enabled #5018

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@
import static org.wso2.carbon.identity.core.util.IdentityCoreConstants.ORG_WISE_MULTI_ATTRIBUTE_SEPARATOR_ENABLED;
import static org.wso2.carbon.identity.core.util.IdentityCoreConstants.ORG_WISE_MULTI_ATTRIBUTE_SEPARATOR_RESOURCE_NAME;
import static org.wso2.carbon.identity.core.util.IdentityCoreConstants.ORG_WISE_MULTI_ATTRIBUTE_SEPARATOR_RESOURCE_TYPE;
import static org.wso2.carbon.identity.core.util.IdentityTenantUtil.isAppendTenantDomainWithUserName;
import static org.wso2.carbon.identity.core.util.IdentityTenantUtil.isLegacySaaSAuthenticationEnabled;
import static org.wso2.carbon.identity.core.util.IdentityTenantUtil.isTenantQualifiedUrlsEnabled;
import static org.wso2.carbon.identity.core.util.IdentityUtil.getLocalGroupsClaimURI;

/**
Expand Down Expand Up @@ -3068,6 +3070,9 @@ public static String preprocessUsername(String username, AuthenticationContext c
return username;
}
return username + "@" + context.getUserTenantDomain();
} else if (isTenantQualifiedUrlsEnabled() && isAppendTenantDomainWithUserName()) {
// This will be a user with tenant domain as email domain.
return username + "@" + context.getUserTenantDomain();
}
return username;
}
Expand Down Expand Up @@ -3100,6 +3105,9 @@ public static String preprocessUsername(String username, ServiceProvider service
return username;
}
return username + "@" + appTenantDomain;
} else if (isTenantQualifiedUrlsEnabled() && isAppendTenantDomainWithUserName()) {
// This will be a user with tenant domain as email domain.
return username + "@" + appTenantDomain;
}
return username;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class IdentityCoreConstants {

public static final String TENANT_NAME_FROM_CONTEXT = "TenantNameFromContext";
public static final String ENABLE_TENANT_QUALIFIED_URLS = "EnableTenantQualifiedUrls";
public static final String APPEND_TENANT_DOMAIN_IN_USERNAME_PREPROCESSING
= "AppendTenantDomainInUserNamePreprocessing";

public static final String ENABLE_TENANTED_SESSIONS = "EnableTenantedSessions";
public static final String PROXY_CONTEXT_PATH = "ProxyContextPath";
public static final int DEFAULT_HTTPS_PORT = 443;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,17 @@ public static boolean isTenantQualifiedUrlsEnabled() {
return Boolean.parseBoolean(IdentityUtil.getProperty(IdentityCoreConstants.ENABLE_TENANT_QUALIFIED_URLS));
}

/**
* Checks whether to add tenant domain when preprocessing UserNames.
*
* @return true if the config is set to true, false otherwise.
*/
public static boolean isAppendTenantDomainWithUserName() {

return Boolean.parseBoolean(IdentityUtil.getProperty
(IdentityCoreConstants.APPEND_TENANT_DOMAIN_IN_USERNAME_PREPROCESSING));
}


/**
* Checks if the tenanted session support is enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ public String getTenantAwareUsername(String username) {

// Check if the tenant domain matches the email domain
if (tenantDomain.equalsIgnoreCase(emailDomain)) {
boolean isEmailTypeUserName = isEmailAsUserName(tenantDomain);
int lastAtSymbolIndex = username.lastIndexOf('@');

// If it's not an email type username or there are multiple '@' symbols, return the modified username
if (!isEmailTypeUserName || username.indexOf('@') != lastAtSymbolIndex) {
return username.substring(0, lastAtSymbolIndex);
}
return username.substring(0, lastAtSymbolIndex);
}
// Return the username as is
return username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3234,6 +3234,12 @@
-->
<EnableLegacySaaSAuthentication>{{authentication.enable_legacy_saas_mode | default(false)}}</EnableLegacySaaSAuthentication>

<!--
When this property is set to 'true', in user name preprocessing method tenant domain will be added for the email
type user names which have tenant domain as email domain.
-->
<AppendTenantDomainInUserNamePreprocessing>{{authentication.append_tenant_domain_with_user_name | default(false)}}</AppendTenantDomainInUserNamePreprocessing>

<EnablePerUserFunctionalityLocking>{{user.enable_per_user_functionality_locking}}</EnablePerUserFunctionalityLocking>

<TenantContextsToRewrite>
Expand Down
Loading