Search in sources :

Example 21 with IdentityProviderProperty

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

the class SelfRegistrationTestCase method updateResidentIdP.

@Test(description = "2.1.1")
public void updateResidentIdP() throws Exception {
    IdentityProvider identityProvider = identityProviderMgtServiceClient.getResidentIdP();
    for (IdentityProviderProperty property : identityProvider.getIdpProperties()) {
        if (SELF_REGISTRATION_ENABLE.equals(property.getName())) {
            property.setValue("true");
        } else if (SELF_REGISTRATION_LOCK_ON_CREATION.equals(property.getName())) {
            property.setValue("true");
        } else if (SELF_REGISTRATION_NOTIFICATION_IM.equals(property.getName())) {
            property.setValue("false");
        } else if (SELF_REGISTRATION_RE_CAPTCHA.equals(property.getName())) {
            property.setValue("false");
        } else if (SELF_REGISTRATION_CODE_EXPIRY_TIME.equals(property.getName())) {
            property.setValue("1440");
        }
    }
    // This is to remove invalid authenticators
    updateFederatedAuthenticators(identityProvider);
    identityProviderMgtServiceClient.updateResidentIdP(identityProvider);
    IdentityProvider updatedIdentityProvider = identityProviderMgtServiceClient.getResidentIdP();
    for (IdentityProviderProperty property : updatedIdentityProvider.getIdpProperties()) {
        if (SELF_REGISTRATION_ENABLE.equals(property.getName())) {
            assertEquals(property.getValue(), "true");
        } else if (SELF_REGISTRATION_LOCK_ON_CREATION.equals(property.getName())) {
            assertEquals(property.getValue(), "true");
        } else if (SELF_REGISTRATION_NOTIFICATION_IM.equals(property.getName())) {
            assertEquals(property.getValue(), "false");
        } else if (SELF_REGISTRATION_RE_CAPTCHA.equals(property.getName())) {
            assertEquals(property.getValue(), "false");
        } else if (SELF_REGISTRATION_CODE_EXPIRY_TIME.equals(property.getName())) {
            assertEquals(property.getValue(), "1440");
        }
    }
    // To sync the local caches.
    Thread.sleep(5000);
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider) Test(org.testng.annotations.Test)

Example 22 with IdentityProviderProperty

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

the class ServerIdpManagementService method createIDP.

private IdentityProvider createIDP(IdentityProviderPOSTRequest identityProviderPOSTRequest) {
    String idpJWKSUri = null;
    IdentityProvider idp = new IdentityProvider();
    idp.setIdentityProviderName(identityProviderPOSTRequest.getName());
    idp.setAlias(identityProviderPOSTRequest.getAlias());
    idp.setTemplateId(identityProviderPOSTRequest.getTemplateId());
    idp.setPrimary(false);
    idp.setIdentityProviderDescription(identityProviderPOSTRequest.getDescription());
    idp.setHomeRealmId(identityProviderPOSTRequest.getHomeRealmIdentifier());
    idp.setImageUrl(identityProviderPOSTRequest.getImage());
    if (identityProviderPOSTRequest.getCertificate() != null && StringUtils.isNotBlank(identityProviderPOSTRequest.getCertificate().getJwksUri())) {
        idpJWKSUri = identityProviderPOSTRequest.getCertificate().getJwksUri();
    } else if (identityProviderPOSTRequest.getCertificate() != null && identityProviderPOSTRequest.getCertificate().getCertificates() != null) {
        List<String> certificates = new ArrayList<>();
        for (int certificateNo = 0; certificateNo < identityProviderPOSTRequest.getCertificate().getCertificates().size(); certificateNo++) {
            if (identityProviderPOSTRequest.getCertificate().getCertificates().get(certificateNo).startsWith(IdentityUtil.PEM_BEGIN_CERTFICATE)) {
                certificates.add(identityProviderPOSTRequest.getCertificate().getCertificates().get(certificateNo));
            } else {
                try {
                    certificates.add(base64Decode(identityProviderPOSTRequest.getCertificate().getCertificates().get(certificateNo)));
                } catch (IllegalArgumentException e) {
                    throw handleException(Response.Status.BAD_REQUEST, Constants.ErrorMessage.ERROR_CODE_INVALID_CERTIFICATE_FORMAT, null);
                }
            }
        }
        idp.setCertificate(base64Encode(StringUtils.join(certificates, "")));
    }
    idp.setFederationHub(identityProviderPOSTRequest.getIsFederationHub());
    updateFederatedAuthenticatorConfig(idp, identityProviderPOSTRequest.getFederatedAuthenticators());
    if (identityProviderPOSTRequest.getProvisioning() != null) {
        updateOutboundConnectorConfig(idp, identityProviderPOSTRequest.getProvisioning().getOutboundConnectors());
        updateJIT(idp, identityProviderPOSTRequest.getProvisioning().getJit());
    }
    updateClaims(idp, identityProviderPOSTRequest.getClaims());
    updateRoles(idp, identityProviderPOSTRequest.getRoles());
    List<IdentityProviderProperty> idpProperties = new ArrayList<>();
    if (StringUtils.isNotBlank(idpJWKSUri)) {
        IdentityProviderProperty jwksProperty = new IdentityProviderProperty();
        jwksProperty.setName(Constants.JWKS_URI);
        jwksProperty.setValue(idpJWKSUri);
        idpProperties.add(jwksProperty);
    }
    if (StringUtils.isNotEmpty(identityProviderPOSTRequest.getIdpIssuerName())) {
        IdentityProviderProperty idpIssuerProperty = new IdentityProviderProperty();
        idpIssuerProperty.setName(Constants.IDP_ISSUER_NAME);
        idpIssuerProperty.setValue(identityProviderPOSTRequest.getIdpIssuerName());
        idpProperties.add(idpIssuerProperty);
    }
    idp.setIdpProperties(idpProperties.toArray(new IdentityProviderProperty[0]));
    return idp;
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with IdentityProviderProperty

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

the class ServerConfigManagementService method updateIdPProperty.

private void updateIdPProperty(IdentityProvider identityProvider, String key, String value) {
    List<IdentityProviderProperty> idPProperties = new ArrayList<>(Arrays.asList(identityProvider.getIdpProperties()));
    if (StringUtils.isBlank(value) || !StringUtils.isNumeric(value) || Integer.parseInt(value) <= 0) {
        String message = "Value should be numeric and positive";
        throw handleException(Response.Status.BAD_REQUEST, Constants.ErrorMessage.ERROR_CODE_INVALID_INPUT, message);
    }
    boolean isPropertyFound = false;
    if (CollectionUtils.isNotEmpty(idPProperties)) {
        for (IdentityProviderProperty property : idPProperties) {
            if (StringUtils.equals(key, property.getName())) {
                isPropertyFound = true;
                property.setValue(value);
            }
        }
    }
    if (!isPropertyFound) {
        IdentityProviderProperty property = new IdentityProviderProperty();
        property.setName(key);
        property.setDisplayName(key);
        property.setValue(value);
        idPProperties.add(property);
    }
    identityProvider.setIdpProperties(idPProperties.toArray(new IdentityProviderProperty[0]));
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ArrayList(java.util.ArrayList)

Example 24 with IdentityProviderProperty

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

the class ServerConfigManagementService method getConfigs.

/**
 * Get Server Configs.
 *
 * @return ServerConfig.
 */
public ServerConfig getConfigs() {
    IdentityProvider residentIdP = getResidentIdP();
    UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
    RealmConfig realmConfig = new RealmConfig();
    try {
        if (userRealm != null && userRealm.getRealmConfiguration() != null) {
            realmConfig.adminUser(userRealm.getRealmConfiguration().getAdminUserName());
            realmConfig.adminRole(userRealm.getRealmConfiguration().getAdminRoleName());
            realmConfig.everyoneRole(userRealm.getRealmConfiguration().getEveryOneRoleName());
        }
    } catch (UserStoreException e) {
        log.error("Error while retrieving user-realm information.", e);
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CONFIGS, null);
    }
    String idleSessionTimeout = null;
    IdentityProviderProperty idleSessionProp = IdentityApplicationManagementUtil.getProperty(residentIdP.getIdpProperties(), IdentityApplicationConstants.SESSION_IDLE_TIME_OUT);
    if (idleSessionProp != null) {
        idleSessionTimeout = idleSessionProp.getValue();
    }
    String rememberMePeriod = null;
    IdentityProviderProperty rememberMeProp = IdentityApplicationManagementUtil.getProperty(residentIdP.getIdpProperties(), IdentityApplicationConstants.REMEMBER_ME_TIME_OUT);
    if (rememberMeProp != null) {
        rememberMePeriod = rememberMeProp.getValue();
    }
    String homeRealmIdStr = residentIdP.getHomeRealmId();
    List<String> homeRealmIdentifiers = null;
    if (StringUtils.isNotBlank(homeRealmIdStr)) {
        homeRealmIdentifiers = Arrays.stream(homeRealmIdStr.trim().split("\\s*,\\s*")).collect(Collectors.toList());
    }
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.setRealmConfig(realmConfig);
    serverConfig.setIdleSessionTimeoutPeriod(idleSessionTimeout);
    serverConfig.setRememberMePeriod(rememberMePeriod);
    serverConfig.setHomeRealmIdentifiers(homeRealmIdentifiers);
    serverConfig.setProvisioning(buildProvisioningConfig());
    serverConfig.setAuthenticators(getAuthenticators(null));
    serverConfig.setCors(getCORSConfiguration());
    return serverConfig;
}
Also used : ServerConfig(org.wso2.carbon.identity.api.server.configs.v1.model.ServerConfig) RealmConfig(org.wso2.carbon.identity.api.server.configs.v1.model.RealmConfig) UserRealm(org.wso2.carbon.user.api.UserRealm) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 25 with IdentityProviderProperty

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

the class APIAdminImpl method createIdp.

private IdentityProvider createIdp(KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
    IdentityProvider identityProvider = new IdentityProvider();
    String idpName = sanitizeName(getSubstringOfTen(keyManagerConfigurationDTO.getName()) + "_" + keyManagerConfigurationDTO.getOrganization() + "_" + keyManagerConfigurationDTO.getUuid());
    identityProvider.setIdentityProviderName(idpName);
    identityProvider.setDisplayName(keyManagerConfigurationDTO.getDisplayName());
    identityProvider.setPrimary(Boolean.FALSE);
    identityProvider.setIdentityProviderDescription(keyManagerConfigurationDTO.getDescription());
    identityProvider.setAlias(keyManagerConfigurationDTO.getAlias());
    String certificate = null;
    if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.CERTIFICATE_VALUE)) {
        certificate = (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.CERTIFICATE_VALUE);
    }
    String certificateType = null;
    if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.CERTIFICATE_TYPE)) {
        certificateType = (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.CERTIFICATE_TYPE);
    }
    List<IdentityProviderProperty> idpProperties = new ArrayList<>();
    if (StringUtils.isNotEmpty(certificate) && StringUtils.isNotEmpty(certificateType)) {
        if (APIConstants.KeyManager.CERTIFICATE_TYPE_JWKS_ENDPOINT.equals(certificateType)) {
            if (StringUtils.isNotBlank(certificate)) {
                IdentityProviderProperty jwksProperty = new IdentityProviderProperty();
                jwksProperty.setName(APIConstants.JWKS_URI);
                jwksProperty.setValue(certificate);
                idpProperties.add(jwksProperty);
            }
        } else if (APIConstants.KeyManager.CERTIFICATE_TYPE_PEM_FILE.equals(certificateType)) {
            identityProvider.setCertificate(String.join(certificate, ""));
        }
    }
    if (keyManagerConfigurationDTO.getProperty(APIConstants.KeyManager.ISSUER) != null) {
        IdentityProviderProperty identityProviderProperty = new IdentityProviderProperty();
        identityProviderProperty.setName(IdentityApplicationConstants.IDP_ISSUER_NAME);
        identityProviderProperty.setValue((String) keyManagerConfigurationDTO.getProperty(APIConstants.KeyManager.ISSUER));
        idpProperties.add(identityProviderProperty);
    }
    if (idpProperties.size() > 0) {
        identityProvider.setIdpProperties(idpProperties.toArray(new IdentityProviderProperty[0]));
    }
    identityProvider.setEnable(keyManagerConfigurationDTO.isEnabled());
    Object claims = keyManagerConfigurationDTO.getProperty(APIConstants.KeyManager.CLAIM_MAPPING);
    updateClaims(identityProvider, claims);
    return identityProvider;
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.simple.JSONObject)

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