Skip to content
Open
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 @@ -204,6 +204,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.AUTH_ENTITY;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.AUTH_ENTITY_AGENT;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.AdaptiveAuthentication.AUTHENTICATOR_NAME_IN_AUTH_CONFIG;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.Application.CONSOLE_APP;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.Application.CONSOLE_APP_PATH;
Expand Down Expand Up @@ -4016,7 +4018,7 @@
UserSessionException {

try {
if (userStoreManager instanceof AbstractUserStoreManager) {

Check warning on line 4021 in components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this instanceof check and cast with 'instanceof AbstractUserStoreManager abstractuserstoremanager'

See more on https://sonarcloud.io/project/issues?id=wso2_carbon-identity-framework&issues=AZ5nwllx-KgcXNHkRBME&open=AZ5nwllx-KgcXNHkRBME&pullRequest=8118
String userId = ((AbstractUserStoreManager) userStoreManager).getUserIDFromUserName(username);

// If the user id is could not be resolved, probably user does not exist in the user store.
Expand Down Expand Up @@ -4053,7 +4055,7 @@
UserSessionException {

try {
if (userStoreManager instanceof AbstractUserStoreManager) {

Check warning on line 4058 in components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this instanceof check and cast with 'instanceof AbstractUserStoreManager abstractuserstoremanager'

See more on https://sonarcloud.io/project/issues?id=wso2_carbon-identity-framework&issues=AZ5nwllx-KgcXNHkRBMF&open=AZ5nwllx-KgcXNHkRBMF&pullRequest=8118
String userName = ((AbstractUserStoreManager) userStoreManager).getUserNameFromUserID(userId);

if (StringUtils.isBlank(userName)) {
Expand Down Expand Up @@ -4282,6 +4284,11 @@
throws InvalidCredentialsException {

if (IdentityUtil.isEmailUsernameEnabled()) {
if (context != null && context.getProperties() != null
&& context.getProperties().containsKey(AUTH_ENTITY)
&& AUTH_ENTITY_AGENT.equals(context.getProperty(AUTH_ENTITY))) {
return;
}
Comment on lines 4286 to +4291

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 1

Suggested change
if (IdentityUtil.isEmailUsernameEnabled()) {
if (context != null && context.getProperties() != null
&& context.getProperties().containsKey(AUTH_ENTITY)
&& AUTH_ENTITY_AGENT.equals(context.getProperty(AUTH_ENTITY))) {
return;
}
if (IdentityUtil.isEmailUsernameEnabled()) {
if (log.isDebugEnabled()) {
log.debug("Email username validation enabled. Checking username format.");
}
if (context != null && context.getProperties() != null
&& context.getProperties().containsKey(AUTH_ENTITY)
&& AUTH_ENTITY_AGENT.equals(context.getProperty(AUTH_ENTITY))) {
if (log.isDebugEnabled()) {
log.debug("Skipping email username validation for agent authentication entity.");
}
return;
}

String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
if (StringUtils.countMatches(tenantAwareUsername, "@") < 1) {
context.setProperty(CONTEXT_PROP_INVALID_EMAIL_USERNAME, true);
Comment on lines 4293 to 4294

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 2

Suggested change
if (StringUtils.countMatches(tenantAwareUsername, "@") < 1) {
context.setProperty(CONTEXT_PROP_INVALID_EMAIL_USERNAME, true);
if (StringUtils.countMatches(tenantAwareUsername, "@") < 1) {
log.warn("Invalid email username format detected. Username does not contain '@' symbol.");
context.setProperty(CONTEXT_PROP_INVALID_EMAIL_USERNAME, true);

Expand Down
Loading