Search in sources :

Example 36 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2Util method getIssuerLocation.

/**
 * Used to get the issuer url for a given tenant.
 *
 * @param tenantDomain Tenant domain.
 * @return Token issuer url.
 * @throws IdentityOAuth2Exception IdentityOAuth2Exception.
 */
public static String getIssuerLocation(String tenantDomain) throws IdentityOAuth2Exception {
    /*
        * IMPORTANT:
        * This method should only honor the given tenant.
        * Do not add any auto tenant resolving logic.
        */
    if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
        try {
            startTenantFlow(tenantDomain);
            return ServiceURLBuilder.create().addPath(OAUTH2_TOKEN_EP_URL).build().getAbsolutePublicURL();
        } catch (URLBuilderException e) {
            String errorMsg = String.format("Error while building the absolute url of the context: '%s',  for the" + " tenant domain: '%s'", OAUTH2_TOKEN_EP_URL, tenantDomain);
            throw new IdentityOAuth2Exception(errorMsg, e);
        } finally {
            endTenantFlow();
        }
    } else {
        IdentityProvider identityProvider = getResidentIdp(tenantDomain);
        FederatedAuthenticatorConfig[] fedAuthnConfigs = identityProvider.getFederatedAuthenticatorConfigs();
        // Get OIDC authenticator
        FederatedAuthenticatorConfig oidcAuthenticatorConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(fedAuthnConfigs, IdentityApplicationConstants.Authenticator.OIDC.NAME);
        return IdentityApplicationManagementUtil.getProperty(oidcAuthenticatorConfig.getProperties(), IDP_ENTITY_ID).getValue();
    }
}
Also used : URLBuilderException(org.wso2.carbon.identity.core.URLBuilderException) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 37 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project identity-inbound-auth-oauth by wso2-extensions.

the class SAML2BearerGrantHandler method getTokenEPAliasFromResidentIdp.

private String getTokenEPAliasFromResidentIdp(Assertion assertion, IdentityProvider identityProvider, String tenantDomain) throws IdentityOAuth2Exception {
    String tokenEndpointAlias = null;
    FederatedAuthenticatorConfig[] fedAuthnConfigs = identityProvider.getFederatedAuthenticatorConfigs();
    // Get OpenIDConnect authenticator == OAuth
    // authenticator
    FederatedAuthenticatorConfig oauthAuthenticatorConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(fedAuthnConfigs, IdentityApplicationConstants.Authenticator.OIDC.NAME);
    // Get OAuth token endpoint
    Property oauthProperty = IdentityApplicationManagementUtil.getProperty(oauthAuthenticatorConfig.getProperties(), IdentityApplicationConstants.Authenticator.OIDC.OAUTH2_TOKEN_URL);
    if (oauthProperty != null) {
        tokenEndpointAlias = oauthProperty.getValue();
    }
    return tokenEndpointAlias;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 38 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project product-is by wso2.

the class RiskBasedLoginTestCase method testInit.

@BeforeClass(alwaysRun = true)
public void testInit() throws Exception {
    super.init();
    InputStream webappUrl = getClass().getResourceAsStream(ISIntegrationTest.URL_SEPARATOR + "samples" + ISIntegrationTest.URL_SEPARATOR + "authenticators" + ISIntegrationTest.URL_SEPARATOR + "sample-auth.war");
    InputStream jarUrl = getClass().getResourceAsStream(ISIntegrationTest.URL_SEPARATOR + "samples" + ISIntegrationTest.URL_SEPARATOR + "authenticators" + ISIntegrationTest.URL_SEPARATOR + "org.wso2.carbon.identity.sample.extension.authenticators.jar");
    String authenticatorPathString = Utils.getResidentCarbonHome() + File.separator + "repository" + File.separator + "components" + File.separator + "dropins" + File.separator + "org.wso2.carbon.identity.sample.extension.authenticators.jar";
    File jarDestFile = new File(authenticatorPathString);
    FileOutputStream jarDest = new FileOutputStream(jarDestFile);
    copyFileUsingStream(jarUrl, jarDest);
    log.info("Copied the demo authenticator jar file to " + authenticatorPathString);
    Assert.assertTrue(Files.exists(Paths.get(authenticatorPathString)), "Demo Authenticator is not copied " + "successfully. File path: " + authenticatorPathString);
    String authenticatorWarPathString = Utils.getResidentCarbonHome() + File.separator + "repository" + File.separator + "deployment" + File.separator + "server" + File.separator + "webapps" + File.separator + "sample-auth.war";
    File warDestFile = new File(authenticatorWarPathString);
    FileOutputStream warDest = new FileOutputStream(warDestFile);
    copyFileUsingStream(webappUrl, warDest);
    // Waiting for the war file to deploy.
    String authenticatorWebappPathString = Utils.getResidentCarbonHome() + File.separator + "repository" + File.separator + "deployment" + File.separator + "server" + File.separator + "webapps" + File.separator + "sample-auth";
    waitForWebappToDeploy(authenticatorWebappPathString, 120000L);
    log.info("Copied the demo authenticator war file to " + authenticatorWarPathString);
    Assert.assertTrue(Files.exists(Paths.get(authenticatorWarPathString)), "Demo Authenticator war is not copied " + "successfully. File path: " + authenticatorWarPathString);
    log.info("Restarting the server at: " + isServer.getContextUrls().getBackEndUrl());
    serverConfigurationManager = new ServerConfigurationManager(isServer);
    changeISConfiguration();
    log.info("Restarting the server at: " + isServer.getContextUrls().getBackEndUrl() + " is successful");
    super.init();
    logManger = new AuthenticatorClient(backendURL);
    String cookie = this.logManger.login(isServer.getSuperTenant().getTenantAdmin().getUserName(), isServer.getSuperTenant().getTenantAdmin().getPassword(), isServer.getInstance().getHosts().get("default"));
    oauthAdminClient = new OauthAdminClient(backendURL, cookie);
    ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    applicationManagementServiceClient = new ApplicationManagementServiceClient(sessionCookie, backendURL, configContext);
    webAppAdminClient = new WebAppAdminClient(backendURL, sessionCookie);
    client = HttpClientBuilder.create().disableRedirectHandling().setDefaultCookieStore(cookieStore).build();
    String script = getConditionalAuthScript("RiskBasedLoginScript.js");
    createOauthApp(CALLBACK_URL, PRIMARY_IS_APPLICATION_NAME, oauthAdminClient);
    // Create service provider in primary IS with conditional authentication script enabled.
    createServiceProvider(PRIMARY_IS_APPLICATION_NAME, applicationManagementServiceClient, oauthAdminClient, script);
    microserviceServer = MicroserviceUtil.initMicroserviceServer();
    MicroserviceUtil.deployService(microserviceServer, this);
    superTenantResidentIDP = superTenantIDPMgtClient.getResidentIdP();
    updateResidentIDPProperty(superTenantResidentIDP, "adaptive_authentication.analytics.receiver", "http://localhost:" + microserviceServer.getPort());
    userRiskScores.put(userInfo.getUserName(), 0);
}
Also used : OauthAdminClient(org.wso2.identity.integration.common.clients.oauth.OauthAdminClient) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AuthenticatorClient(org.wso2.carbon.integration.common.admin.client.AuthenticatorClient) InputStream(java.io.InputStream) ServerConfigurationManager(org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager) FileOutputStream(java.io.FileOutputStream) ApplicationManagementServiceClient(org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient) WebAppAdminClient(org.wso2.identity.integration.common.clients.webappmgt.WebAppAdminClient) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 39 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project product-is by wso2.

the class RiskBasedLoginTestCase method createLocalAndOutboundAuthenticationConfig.

protected LocalAndOutboundAuthenticationConfig createLocalAndOutboundAuthenticationConfig() throws Exception {
    LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = super.createLocalAndOutboundAuthenticationConfig();
    AuthenticationStep authenticationStep2 = new AuthenticationStep();
    authenticationStep2.setStepOrder(2);
    LocalAuthenticatorConfig localConfig = new LocalAuthenticatorConfig();
    localConfig.setName("DemoFingerprintAuthenticator");
    localConfig.setDisplayName("Demo Fingerprint Authenticator");
    localConfig.setEnabled(true);
    authenticationStep2.setLocalAuthenticatorConfigs(new LocalAuthenticatorConfig[] { localConfig });
    authenticationStep2.setSubjectStep(false);
    authenticationStep2.setAttributeStep(false);
    localAndOutboundAuthenticationConfig.addAuthenticationSteps(authenticationStep2);
    return localAndOutboundAuthenticationConfig;
}
Also used : LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.xsd.LocalAndOutboundAuthenticationConfig) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig) AuthenticationStep(org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep)

Example 40 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project product-is by wso2.

the class IdentityProviderMgtServiceTestCase method testAddIdp.

@Test(priority = 2, groups = "wso2.is", description = "Test addIdp operation")
public void testAddIdp() throws Exception {
    String testIdpDescription = "This is test identity provider";
    String testIdpRealmId = "localhost";
    String testFedAuthDispName = "openid";
    String testFedAuthPropName = "OpenIdUrl";
    String testFedAuthPropValue = "https://testDomain:9853/openid";
    String testFedAuthPropName2 = "IsUserIdInClaims";
    String testFedAuthPropValue2 = "false";
    String testFedAuthPropName3 = "RealmId";
    String testFedAuthPropValue3 = "localhost";
    String testProvisionConfName = "scim";
    String testProvisionPropName = "scim-user-ep";
    String testProvisionPropDisplayName = "userEndPoint";
    String testProvisionPropValue = "https://localhost:9853/testProvisionLink";
    String testProvisionPropName2 = "scim-username";
    String testProvisionPropDisplayName2 = "userName";
    String testProvisionPropValue2 = "admin";
    String testProvisionPropName3 = "scim-password";
    String testProvisionPropDisplayName3 = "userPassword";
    String testProvisionPropValue3 = "admin";
    IdentityProvider idProvider = new IdentityProvider();
    FederatedAuthenticatorConfig[] fedAuthConfigs = new FederatedAuthenticatorConfig[1];
    // set idp information
    idProvider.setHomeRealmId(testIdpRealmId);
    idProvider.setEnable(true);
    idProvider.setIdentityProviderDescription(testIdpDescription);
    idProvider.setIdentityProviderName(testIdpName);
    idProvider.setCertificate(sampleCertificate);
    idProvider.setFederationHub(false);
    idProvider.setPrimary(false);
    // Add federated authentication configuration
    FederatedAuthenticatorConfig authConfig = new FederatedAuthenticatorConfig();
    authConfig.setDisplayName(testFedAuthDispName);
    authConfig.setEnabled(true);
    authConfig.setName(testFedAuthName);
    // set properties
    // property 1
    Property fedProp = new Property();
    fedProp.setName(testFedAuthPropName);
    fedProp.setValue(testFedAuthPropValue);
    // property 2
    Property fedProp2 = new Property();
    fedProp2.setName(testFedAuthPropName2);
    fedProp2.setValue(testFedAuthPropValue2);
    // property 3
    Property fedProp3 = new Property();
    fedProp3.setName(testFedAuthPropName3);
    fedProp3.setValue(testFedAuthPropValue3);
    Property[] props = new Property[3];
    props[0] = fedProp;
    props[1] = fedProp2;
    props[2] = fedProp3;
    authConfig.setProperties(props);
    fedAuthConfigs[0] = authConfig;
    idProvider.setFederatedAuthenticatorConfigs(fedAuthConfigs);
    // Set JIT config
    JustInTimeProvisioningConfig jitConfig = new JustInTimeProvisioningConfig();
    jitConfig.setProvisioningEnabled(true);
    idProvider.setJustInTimeProvisioningConfig(jitConfig);
    ProvisioningConnectorConfig provisioningConfig = new ProvisioningConnectorConfig();
    provisioningConfig.setName(testProvisionConfName);
    provisioningConfig.setValid(false);
    provisioningConfig.setBlocking(false);
    provisioningConfig.setEnabled(true);
    // set provisioning properties
    Property provisionProp = new Property();
    provisionProp.setName(testProvisionPropName);
    provisionProp.setDisplayName(testProvisionPropDisplayName);
    provisionProp.setValue(testProvisionPropValue);
    Property provisionProp2 = new Property();
    provisionProp2.setName(testProvisionPropName2);
    provisionProp2.setDisplayName(testProvisionPropDisplayName2);
    provisionProp2.setValue(testProvisionPropValue2);
    Property provisionProp3 = new Property();
    provisionProp3.setName(testProvisionPropName3);
    provisionProp3.setDisplayName(testProvisionPropDisplayName3);
    provisionProp3.setValue(testProvisionPropValue3);
    Property[] provisionProps = new Property[3];
    provisionProps[0] = provisionProp;
    provisionProps[1] = provisionProp2;
    provisionProps[2] = provisionProp3;
    provisioningConfig.setProvisioningProperties(provisionProps);
    ProvisioningConnectorConfig[] provisionConfigs = new ProvisioningConnectorConfig[1];
    provisionConfigs[0] = provisioningConfig;
    idProvider.setProvisioningConnectorConfigs(provisionConfigs);
    // add new identity provider
    idpMgtServiceClient.addIdP(idProvider);
    // check adding idp success
    IdentityProvider addedIdp = idpMgtServiceClient.getIdPByName(testIdpName);
    Assert.assertNotNull(addedIdp, "addIdP or getIdPByName failed");
    Assert.assertEquals(addedIdp.getHomeRealmId(), testIdpRealmId, "addIdP : setting home realm failed");
    Assert.assertEquals(addedIdp.getCertificate(), sampleCertificate, "addIdP : setting certificate failed");
    // idp auto enabled
    Assert.assertEquals(addedIdp.getEnable(), true, "addIdP : idp enable failed");
    Assert.assertEquals(addedIdp.getIdentityProviderDescription(), testIdpDescription, "addIdP : setting description failed");
    Assert.assertEquals(addedIdp.getFederationHub(), false, "addIdP : setting federation hub status failed");
    Assert.assertEquals(addedIdp.getPrimary(), false, "addIdP : setting primary status failed");
    // Check added federated authenticator configs
    FederatedAuthenticatorConfig[] addedFedAuth = addedIdp.getFederatedAuthenticatorConfigs();
    Assert.assertNotNull(addedFedAuth, "federated authenticator not found");
    Assert.assertEquals(addedFedAuth.length, 1, "addIdP : deviation from expected number of federated authenticators");
    Assert.assertEquals(addedFedAuth[0].getName(), testFedAuthName, "addIdP : federated authenticator name setting failed");
    Property[] fedAuthProps = addedFedAuth[0].getProperties();
    Assert.assertNotNull(fedAuthProps, "addIdP : federated authenticator properties not found");
    Assert.assertEquals(fedAuthProps.length, 3, "addIdP : Deviation of expected number of authenticator properties");
    Map<String, Property> propertyMap = new HashMap<String, Property>();
    for (Property fedAuthProp : fedAuthProps) {
        propertyMap.put(fedAuthProp.getName(), fedAuthProp);
    }
    Assert.assertEquals(propertyMap.containsKey(testFedAuthPropName), true, "addIdP : federated authenticator property not found");
    Assert.assertEquals(propertyMap.get(testFedAuthPropName).getValue(), testFedAuthPropValue, "Deviation of federated authenticator property value");
    Assert.assertEquals(propertyMap.containsKey(testFedAuthPropName2), true, "addIdP : federated authenticator property not found");
    Assert.assertEquals(propertyMap.get(testFedAuthPropName2).getValue(), testFedAuthPropValue2, "Deviation of federated authenticator property value");
    Assert.assertEquals(propertyMap.containsKey(testFedAuthPropName3), true, "addIdP : federated authenticator property not found");
    Assert.assertEquals(propertyMap.get(testFedAuthPropName3).getValue(), testFedAuthPropValue3, "Deviation of federated authenticator property value");
    propertyMap.clear();
    // check provisioning connector configs
    ProvisioningConnectorConfig[] provisioningConfigs = addedIdp.getProvisioningConnectorConfigs();
    Assert.assertNotNull(provisioningConfigs, "addIdP : provisioning connector not found");
    Assert.assertEquals(provisioningConfigs.length, 1, "addIdP : Provisioning configuration property adding failed");
    Assert.assertEquals(provisioningConfigs[0].getName(), testProvisionConfName, "addIdP : Provisioning configuration name setting failed");
    Property[] provisioningProps = provisioningConfigs[0].getProvisioningProperties();
    Assert.assertNotNull(provisioningProps, "addIdP : provisioning property not found");
    Assert.assertEquals(provisioningProps.length, 4, "addIdP :Provisioning configuration property setting failed");
    for (Property provisioningProp : provisioningProps) {
        propertyMap.put(provisioningProp.getName(), provisioningProp);
    }
    Assert.assertEquals(propertyMap.containsKey(testProvisionPropName), true, "addIdP : Provisioning configuration property not found : " + testProvisionPropName);
    Assert.assertEquals(propertyMap.get(testProvisionPropName).getValue(), testProvisionPropValue, "addIdP : Provisioning configuration property value failed : " + testProvisionPropName);
    Assert.assertEquals(propertyMap.containsKey(testProvisionPropName2), true, "addIdP : Provisioning configuration property not found : " + testProvisionPropName2);
    Assert.assertEquals(propertyMap.get(testProvisionPropName2).getValue(), testProvisionPropValue2, "addIdP : Provisioning configuration property value failed : " + testProvisionPropName2);
    Assert.assertEquals(propertyMap.containsKey(testProvisionPropName3), true, "addIdP : Provisioning configuration property not found : " + testProvisionPropName3);
    Assert.assertTrue(propertyMap.get(testProvisionPropName3).getValue().contains(RANDOM_PASSWORD_GENERATED), "addIdP : Provisioning configuration property value failed : " + testProvisionPropName3);
    // check jit
    Assert.assertEquals(addedIdp.getJustInTimeProvisioningConfig().getProvisioningEnabled(), true, "addIdP : JIT enabling failed");
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig) HashMap(java.util.HashMap) JustInTimeProvisioningConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.JustInTimeProvisioningConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider) Property(org.wso2.carbon.identity.application.common.model.idp.xsd.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.ProvisioningConnectorConfig) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)27 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)25 Test (org.testng.annotations.Test)23 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)22 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)22 ApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator)19 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)19 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)16 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)15 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)15 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)15 IOException (java.io.IOException)12 Map (java.util.Map)12 FederatedApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator)12 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)11 RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)11 Property (org.wso2.carbon.identity.application.common.model.Property)10 HttpResponse (org.apache.http.HttpResponse)8