Search in sources :

Example 16 with IdentityProviderProperty

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty in project identity-governance by wso2-extensions.

the class PostAuthnMissingChallengeQuestionsHandlerTest method testBeforeRequestingChallengeQuestionFlow.

@Test(description = "Test the flow of challenge question post authentication handler before requesting challenge " + "questions from the user")
public void testBeforeRequestingChallengeQuestionFlow() throws Exception {
    AuthenticationContext context = spy(new AuthenticationContext());
    when(context.getTenantDomain()).thenReturn("carbon.super");
    IdentityProvider residentIdp = spy(new IdentityProvider());
    IdentityProviderProperty[] idpProperties = new IdentityProviderProperty[1];
    IdentityProviderProperty idpProp = new IdentityProviderProperty();
    idpProp.setName(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION);
    idpProp.setValue("true");
    idpProperties[0] = idpProp;
    residentIdp.setIdpProperties(idpProperties);
    mockedIdentityProviderManager.when(IdentityProviderManager::getInstance).thenReturn(identityProviderManager);
    when(identityProviderManager.getResidentIdP("carbon.super")).thenReturn(residentIdp);
    SequenceConfig sequenceConfig = spy(new SequenceConfig());
    AuthenticatedUser user = spy(new AuthenticatedUser());
    user.setUserName("admin");
    when(sequenceConfig.getAuthenticatedUser()).thenReturn(user);
    context.setSequenceConfig(sequenceConfig);
    mockedMultitenantUtils.when(() -> MultitenantUtils.getTenantDomain("admin")).thenReturn("carbon.super");
    mockedUtils.when(() -> Utils.getTenantId("carbon.super")).thenReturn(-1234);
    mockedIdentityRecoveryServiceDataHolder.when(IdentityRecoveryServiceDataHolder::getInstance).thenReturn(frameworkServiceDataHolder);
    RealmService realmService = mock(RealmService.class);
    UserStoreManager userStoreManager = mock(UserStoreManager.class);
    UserRealm userRealm = mock(UserRealm.class);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
    when(frameworkServiceDataHolder.getRealmService()).thenReturn(realmService);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    Map<String, String> claimsMap = new HashMap<>();
    when(userStoreManager.getUserClaimValues("admin", new String[] { IdentityRecoveryConstants.CHALLENGE_QUESTION_URI }, UserCoreConstants.DEFAULT_PROFILE)).thenReturn(claimsMap);
    List<ChallengeQuestion> challengeQuestions = new ArrayList<>();
    ChallengeQuestion challengeQuestion = spy(new ChallengeQuestion());
    challengeQuestion.setQuestionSetId("dummy_set");
    challengeQuestion.setQuestionId("dummy_id");
    challengeQuestion.setQuestion("dummy_question");
    challengeQuestions.add(challengeQuestion);
    when(challengeQuestionManager.getAllChallengeQuestions("carbon.super")).thenReturn(challengeQuestions);
    mockedChallengeQuestionManager.when(ChallengeQuestionManager::getInstance).thenReturn(challengeQuestionManager);
    doNothing().doThrow(Exception.class).when(httpServletResponse).sendRedirect((String) any());
    when(configurationFacade.getAuthenticationEndpointURL()).thenReturn("");
    when(ConfigurationFacade.getInstance()).thenReturn(configurationFacade);
    PostAuthnHandlerFlowStatus flowStatus = PostAuthnMissingChallengeQuestionsHandler.getInstance().handle(httpServletRequest, httpServletResponse, context);
    String expectedResult = PostAuthnHandlerFlowStatus.INCOMPLETE.name();
    assertEquals(flowStatus.name(), expectedResult);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) UserRealm(org.wso2.carbon.user.core.UserRealm) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) RealmService(org.wso2.carbon.user.core.service.RealmService) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) PostAuthnHandlerFlowStatus(org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion) Test(org.testng.annotations.Test)

Example 17 with IdentityProviderProperty

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty in project identity-governance by wso2-extensions.

the class PostAuthnMissingChallengeQuestionsHandlerTest method testForNullUser.

@Test(description = "Test the behaviour of the handler if the user is null")
public void testForNullUser() throws Exception {
    AuthenticationContext context = spy(new AuthenticationContext());
    when(context.getTenantDomain()).thenReturn("carbon.super");
    IdentityProvider residentIdp = spy(new IdentityProvider());
    IdentityProviderProperty[] idpProperties = new IdentityProviderProperty[1];
    IdentityProviderProperty idpProp = new IdentityProviderProperty();
    idpProp.setName(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION);
    idpProp.setValue("true");
    idpProperties[0] = idpProp;
    residentIdp.setIdpProperties(idpProperties);
    mockedIdentityProviderManager.when(IdentityProviderManager::getInstance).thenReturn(identityProviderManager);
    when(identityProviderManager.getResidentIdP("carbon.super")).thenReturn(residentIdp);
    SequenceConfig sequenceConfig = spy(new SequenceConfig());
    when(sequenceConfig.getAuthenticatedUser()).thenReturn(null);
    context.setSequenceConfig(sequenceConfig);
    PostAuthnHandlerFlowStatus flowStatus = PostAuthnMissingChallengeQuestionsHandler.getInstance().handle(httpServletRequest, httpServletResponse, context);
    String expectedResult = PostAuthnHandlerFlowStatus.UNSUCCESS_COMPLETED.name();
    assertEquals(flowStatus.name(), expectedResult);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PostAuthnHandlerFlowStatus(org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus) Test(org.testng.annotations.Test)

Example 18 with IdentityProviderProperty

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty in project product-is by wso2.

the class SelfSignUpConsentTest method updateResidentIDPProperty.

private void updateResidentIDPProperty(IdentityProvider residentIdp, String propertyKey, String value, boolean isSuperTenant) throws Exception {
    IdentityProviderProperty[] idpProperties = residentIdp.getIdpProperties();
    for (IdentityProviderProperty providerProperty : idpProperties) {
        if (propertyKey.equalsIgnoreCase(providerProperty.getName())) {
            providerProperty.setValue(value);
        }
    }
    updateResidentIDP(residentIdp, isSuperTenant);
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)

Example 19 with IdentityProviderProperty

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty in project product-is by wso2.

the class OIDCFederatedIdpInitLogoutTest method createIdentityProviderInPrimaryIS.

private void createIdentityProviderInPrimaryIS() throws Exception {
    IdentityProvider identityProvider = new IdentityProvider();
    identityProvider.setIdentityProviderName(PRIMARY_IS_IDP_NAME);
    // Set JWKS Uri to identity provider.
    IdentityProviderProperty jwksUriProperty = new IdentityProviderProperty();
    jwksUriProperty.setName("jwksUri");
    jwksUriProperty.setValue(SECONDARY_IS_JWKS_URI);
    IdentityProviderProperty issuerProperty = new IdentityProviderProperty();
    issuerProperty.setName("idpIssuerName");
    issuerProperty.setValue(SECONDARY_IS_TOKEN_ENDPOINT);
    IdentityProviderProperty[] properties = { jwksUriProperty, issuerProperty };
    identityProvider.setIdpProperties(properties);
    FederatedAuthenticatorConfig oidcAuthnConfig = new FederatedAuthenticatorConfig();
    oidcAuthnConfig.setName(PRIMARY_IS_IDP_AUTHENTICATOR_NAME_OIDC);
    oidcAuthnConfig.setDisplayName("openidconnect");
    oidcAuthnConfig.setEnabled(true);
    oidcAuthnConfig.setProperties(getOIDCAuthnConfigProperties());
    identityProvider.setDefaultAuthenticatorConfig(oidcAuthnConfig);
    identityProvider.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { oidcAuthnConfig });
    JustInTimeProvisioningConfig jitConfig = new JustInTimeProvisioningConfig();
    jitConfig.setProvisioningEnabled(true);
    jitConfig.setProvisioningUserStore("PRIMARY");
    identityProvider.setJustInTimeProvisioningConfig(jitConfig);
    super.addIdentityProvider(PORT_OFFSET_0, identityProvider);
    Assert.assertNotNull(getIdentityProvider(PORT_OFFSET_0, PRIMARY_IS_IDP_NAME), "Failed to create " + "Identity Provider 'trustedIdP' in primary IS");
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig) JustInTimeProvisioningConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.JustInTimeProvisioningConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider)

Example 20 with IdentityProviderProperty

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty in project product-is by wso2.

the class ChallengeQuestionPostAuthnHandlerTestCase method updateResidentIDPProperty.

private void updateResidentIDPProperty(IdentityProvider residentIdp, String propertyKey, String value, boolean isSuperTenant) throws Exception {
    IdentityProviderProperty[] idpProperties = residentIdp.getIdpProperties();
    for (IdentityProviderProperty providerProperty : idpProperties) {
        if (propertyKey.equalsIgnoreCase(providerProperty.getName())) {
            providerProperty.setValue(value);
        }
    }
    updateResidentIDP(residentIdp, isSuperTenant);
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)

Aggregations

IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)43 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)30 ArrayList (java.util.ArrayList)20 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)14 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)9 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)8 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)8 ResultSet (java.sql.ResultSet)7 HashMap (java.util.HashMap)7 Property (org.wso2.carbon.identity.application.common.model.Property)7 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)7 Test (org.testng.annotations.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)5 PostAuthnHandlerFlowStatus (org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus)5 IOException (java.io.IOException)4 List (java.util.List)4 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)4