Skip to content

Commit

Permalink
Merge pull request #5374 from ZiyamSanthosh/master-self-signup-autologin
Browse files Browse the repository at this point in the history
Get tenantDomain from CarbonContext instead of getting from the username
  • Loading branch information
ZiyamSanthosh authored Jan 17, 2024
2 parents a1794bd + 181bd9c commit b34c6df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.authentication.framework.exception.DuplicatedAuthUserException;
import org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException;
import org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException;
Expand Down Expand Up @@ -164,7 +165,8 @@ public static AuthenticatedUser createLocalAuthenticatedUserFromSubjectIdentifie
authenticatedUser.setUserName(MultitenantUtils.getTenantAwareUsername(authenticatedSubjectIdentifier));
}

authenticatedUser.setTenantDomain(MultitenantUtils.getTenantDomain(authenticatedSubjectIdentifier));
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
authenticatedUser.setTenantDomain(tenantDomain);
authenticatedUser.setAuthenticatedSubjectIdentifier(authenticatedSubjectIdentifier);
authenticatedUser.setUserId(authenticatedUser.getLocalUserIdInternal());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.AdminServicesUtil;
import org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest;
import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator;
Expand Down Expand Up @@ -72,13 +73,15 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
import static org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_ID;
import static org.wso2.carbon.identity.core.util.IdentityUtil.getLocalGroupsClaimURI;

/**
* This is a test class for {@link PostAuthAssociationHandler}.
*/
@PrepareForTest({FrameworkUtils.class, ConfigurationFacade.class, ClaimMetadataHandler.class, AdminServicesUtil.class
, IdentityTenantUtil.class})
, IdentityTenantUtil.class, PrivilegedCarbonContext.class})
@PowerMockIgnore({"javax.xml.*", "org.mockito.*"})
public class PostAuthAssociationHandlerTest extends AbstractFrameworkTest {

Expand Down Expand Up @@ -142,6 +145,7 @@ protected void setupSuite() throws Exception {
public void testHandleWithAuthenticatedUserWithFederatedIdpAssociatedToSecondaryUserStore(boolean hasSpRoleMapping)
throws Exception {

mockCarbonContextForTenant();
PowerMockito.spy(AdminServicesUtil.class);
PowerMockito.doReturn(null).when(AdminServicesUtil.class, "getUserRealm");
AuthenticationContext context = processAndGetAuthenticationContext(sp, true, true, hasSpRoleMapping);
Expand Down Expand Up @@ -239,4 +243,14 @@ private boolean isSpRoleMappingSuccessful(Map<ClaimMapping, String> authenticate
}
return false;
}

private void mockCarbonContextForTenant() {

mockStatic(PrivilegedCarbonContext.class);
PrivilegedCarbonContext privilegedCarbonContext = mock(PrivilegedCarbonContext.class);
when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
when(privilegedCarbonContext.getTenantDomain()).thenReturn(SUPER_TENANT_DOMAIN_NAME);
when(privilegedCarbonContext.getTenantId()).thenReturn(SUPER_TENANT_ID);
when(privilegedCarbonContext.getUsername()).thenReturn("admin");
}
}

0 comments on commit b34c6df

Please sign in to comment.