Java Code Examples for org.wso2.carbon.identity.core.util.IdentityUtil#isEmailUsernameEnabled()
The following examples show how to use
org.wso2.carbon.identity.core.util.IdentityUtil#isEmailUsernameEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrameworkUtils.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * Preprocess user's username considering authentication context. * * @param username Username of the user. * @param context Authentication context. * @return preprocessed username */ public static String preprocessUsername(String username, AuthenticationContext context) { if (context.getSequenceConfig().getApplicationConfig().isSaaSApp()) { return username; } if (IdentityUtil.isEmailUsernameEnabled()) { if (StringUtils.countMatches(username, "@") == 1) { return username + "@" + context.getTenantDomain(); } } else if (!username.endsWith(context.getTenantDomain())) { return username + "@" + context.getTenantDomain(); } return username; }
Example 2
Source File: FrameworkUtils.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * Validate the username when email username is enabled. * * @param username Username. * @param context Authentication context. * @throws InvalidCredentialsException when username is not an email when email username is enabled. */ public static void validateUsername(String username, AuthenticationContext context) throws InvalidCredentialsException { if (IdentityUtil.isEmailUsernameEnabled()) { String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username); if (StringUtils.countMatches(tenantAwareUsername, "@") < 1) { context.setProperty(CONTEXT_PROP_INVALID_EMAIL_USERNAME, true); throw new InvalidCredentialsException("Invalid username. Username has to be an email."); } } }