Java Code Examples for org.wso2.carbon.identity.application.common.model.Property#getValue()

The following examples show how to use org.wso2.carbon.identity.application.common.model.Property#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomPasswordProcessor.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Replace original passwords with provided random phrase
 *
 * @param randomPhrase
 * @param properties
 * @return
 */
private RandomPassword[] replaceOriginalPasswordsWithRandomPasswords(String randomPhrase, Property[] properties) {

    ArrayList<RandomPassword> randomPasswordArrayList = new ArrayList<RandomPassword>();
    if (properties != null) {
        for (Property property : properties) {

            if (property == null || property.getName() == null || property.getValue() == null) {
                continue;
            }
            if (property.getName().contains(IdentityApplicationConstants.PASSWORD)) {

                if (log.isDebugEnabled()) {
                    log.debug("Found Password Property :" + property.getValue());
                }
                RandomPassword randomPassword = new RandomPassword();
                randomPassword.setPropertyName(property.getName());
                randomPassword.setPassword(property.getValue());
                randomPassword.setRandomPhrase(randomPhrase);
                randomPasswordArrayList.add(randomPassword);

                property.setValue(randomPhrase);
            }
        }
    }
    return randomPasswordArrayList.toArray(new RandomPassword[randomPasswordArrayList.size()]);
}
 
Example 2
Source File: IdentityApplicationManagementUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public static String getPropertyValue(Property[] properties, String propertyName) {

        Property property = getProperty(properties, propertyName);
        if (property != null) {
            if (StringUtils.isNotBlank(property.getValue())) {
                return property.getValue();
            }
        }
        return null;
    }
 
Example 3
Source File: IdentityProviderManager.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private boolean validateIdPEntityId(FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs,
                                    int tenantId, String tenantDomain) throws IdentityProviderManagementException {

    if (federatedAuthenticatorConfigs != null) {
        for (FederatedAuthenticatorConfig authConfig : federatedAuthenticatorConfigs) {
            if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authConfig.getName()) ||
                    IdentityApplicationConstants.Authenticator.SAML2SSO.NAME.equals(authConfig.getName())) {
                Property[] properties = authConfig.getProperties();
                if (properties != null) {
                    for (Property property : properties) {
                        if (IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID.equals(
                                property.getName())) {
                            if (dao.isIdPAvailableForAuthenticatorProperty(authConfig.getName(),
                                    IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID,
                                    property.getValue(), tenantId)) {
                                String msg =
                                        "An Identity Provider Entity ID has already been registered with the " +
                                                "name '" + property.getValue() + "' for tenant '" + tenantDomain +
                                                "'";
                                throw new IdentityProviderManagementException(msg);
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }
    return true;
}
 
Example 4
Source File: SCIMProvisioningConnector.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Property[] provisioningProperties) throws IdentityProvisioningException {
    scimProvider = new SCIMProvider();

    if (provisioningProperties != null && provisioningProperties.length > 0) {

        for (Property property : provisioningProperties) {

            if (SCIMProvisioningConnectorConstants.SCIM_USER_EP.equals(property.getName())) {
                populateSCIMProvider(property, SCIMConfigConstants.ELEMENT_NAME_USER_ENDPOINT);
            } else if (SCIMProvisioningConnectorConstants.SCIM_GROUP_EP.equals(property.getName())) {
                populateSCIMProvider(property, SCIMConfigConstants.ELEMENT_NAME_GROUP_ENDPOINT);
            } else if (SCIMProvisioningConnectorConstants.SCIM_USERNAME.equals(property.getName())) {
                populateSCIMProvider(property, SCIMConfigConstants.ELEMENT_NAME_USERNAME);
            } else if (SCIMProvisioningConnectorConstants.SCIM_PASSWORD.equals(property.getName())) {
                populateSCIMProvider(property, SCIMConfigConstants.ELEMENT_NAME_PASSWORD);
            } else if (SCIMProvisioningConnectorConstants.SCIM_USERSTORE_DOMAIN.equals(property.getName())) {
                userStoreDomainName = property.getValue() != null ? property.getValue()
                        : property.getDefaultValue();
            }else if (SCIMProvisioningConnectorConstants.SCIM_ENABLE_PASSWORD_PROVISIONING.equals(property.getName())){
                populateSCIMProvider(property, SCIMProvisioningConnectorConstants.SCIM_ENABLE_PASSWORD_PROVISIONING);
            }else if (SCIMProvisioningConnectorConstants.SCIM_DEFAULT_PASSWORD.equals(property.getName())){
                populateSCIMProvider(property, SCIMProvisioningConnectorConstants.SCIM_DEFAULT_PASSWORD);
            }

            if (IdentityProvisioningConstants.JIT_PROVISIONING_ENABLED.equals(property
                    .getName()) && "1".equals(property.getValue())) {
                jitProvisioningEnabled = true;
            }
        }
    }
}
 
Example 5
Source File: SCIMProvisioningConnector.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param property
 * @param scimPropertyName
 * @throws IdentityProvisioningException
 */
private void populateSCIMProvider(Property property, String scimPropertyName)
        throws IdentityProvisioningException {

    if (property.getValue() != null && property.getValue().length() > 0) {
        scimProvider.setProperty(scimPropertyName, property.getValue());
    } else if (property.getDefaultValue() != null) {
        scimProvider.setProperty(scimPropertyName, property.getDefaultValue());
    }
}
 
Example 6
Source File: RandomPasswordProcessor.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Replace original passwords with provided random phrase
 * @param randomPhrase
 * @param properties
 * @return
 */
private RandomPassword[] replaceOriginalPasswordsWithRandomPasswords(String randomPhrase, Property[] properties) {

    ArrayList<RandomPassword> randomPasswordArrayList = new ArrayList<RandomPassword>();
    if (properties != null) {
        for (Property property : properties) {

            if (property == null || property.getName() == null || property.getValue() == null) {
                continue;
            }
            if (property.getName().contains(IdentityApplicationConstants.PASSWORD)) {

                if (log.isDebugEnabled()){
                    log.debug("Found Password Property :" + property.getValue());
                }
                RandomPassword randomPassword = new RandomPassword();
                randomPassword.setPropertyName(property.getName());
                randomPassword.setPassword(property.getValue());
                randomPassword.setRandomPhrase(randomPhrase);
                randomPasswordArrayList.add(randomPassword);

                property.setValue(randomPhrase);
            }
        }
    }
    return randomPasswordArrayList.toArray(new RandomPassword[randomPasswordArrayList.size()]);
}
 
Example 7
Source File: IdentityApplicationManagementUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static String getPropertyValue(Property[] properties, String propertyName) {

        Property property = getProperty(properties, propertyName);
        if (property != null) {
            if (StringUtils.isNotBlank(property.getValue())) {
                return property.getValue();
            }
        }
        return null;
    }
 
Example 8
Source File: IdentityProviderManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private boolean validateIdPEntityId(FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs,
                                    int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    if (federatedAuthenticatorConfigs != null) {
        for (FederatedAuthenticatorConfig authConfig : federatedAuthenticatorConfigs) {
            if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authConfig.getName()) ||
                    IdentityApplicationConstants.Authenticator.SAML2SSO.NAME.equals(authConfig.getName())) {
                Property[] properties = authConfig.getProperties();
                if (properties != null) {
                    for (Property property : properties) {
                        if (IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID.equals(
                                property.getName())) {
                            if (dao.isIdPAvailableForAuthenticatorProperty(authConfig.getName(),
                                    IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID,
                                    property.getValue(), tenantId)) {
                                String msg = "An Identity Provider Entity Id has already been registered with the " +
                                        "name '" + property.getValue() + "' for tenant '" + tenantDomain + "'";
                                throw new IdentityProviderManagementException(msg);
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }
    return true;
}
 
Example 9
Source File: IdentityApplicationManagementUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
/**
 * @param jsonObj
 * @return Base64 encoded JWT
 */
public static String getSignedJWT(String jsonObj, ServiceProvider serviceProvider) {

    String oauthConsumerSecret = null;

    if (serviceProvider.getInboundAuthenticationConfig() != null
            && serviceProvider.getInboundAuthenticationConfig()
            .getInboundAuthenticationRequestConfigs() != null
            && serviceProvider.getInboundAuthenticationConfig()
            .getInboundAuthenticationRequestConfigs().length > 0) {

        InboundAuthenticationRequestConfig[] authReqConfigs = serviceProvider
                .getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();

        for (InboundAuthenticationRequestConfig authReqConfig : authReqConfigs) {
            if ((IdentityApplicationConstants.OAuth2.NAME).equals(authReqConfig.getInboundAuthType())) {
                if (authReqConfig.getProperties() != null) {
                    for (Property property : authReqConfig.getProperties()) {
                        if ((IdentityApplicationConstants.OAuth2.OAUTH_CONSUMER_SECRET)
                                .equalsIgnoreCase(property.getName())) {
                            oauthConsumerSecret = property.getValue();
                            break;
                        }
                    }
                }
            }
        }

    }

    String jwtBody = "{\"iss\":\"wso2\",\"exp\":" + new Date().getTime() + 3000 + ",\"iat\":"
            + new Date().getTime() + "," + jsonObj + "}";
    String jwtHeader = "{\"typ\":\"JWT\", \"alg\":\"HS256\"}";

    if (oauthConsumerSecret == null) {
        jwtHeader = "{\"typ\":\"JWT\", \"alg\":\"none\"}";
    }

    String base64EncodedHeader = Base64Utils.encode(jwtHeader.getBytes(StandardCharsets.UTF_8));
    String base64EncodedBody = Base64Utils.encode(jwtBody.getBytes(StandardCharsets.UTF_8));

    if (log.isDebugEnabled()) {
        log.debug("JWT Header :" + jwtHeader);
        log.debug("JWT Body :" + jwtBody);
    }

    String assertion = base64EncodedHeader + "." + base64EncodedBody;

    if (oauthConsumerSecret == null) {
        return assertion + ".";
    } else {
        String signedAssertion;
        try {
            signedAssertion = calculateHmacSha1(oauthConsumerSecret, assertion);
            return assertion + "." + signedAssertion;
        } catch (SignatureException e) {
            log.error("Error while signing the assertion", e);
            return assertion + ".";
        }
    }
}
 
Example 10
Source File: IdentityApplicationManagementUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param jsonObj
 * @return Base64 encoded JWT
 */
public static String getSignedJWT(String jsonObj, ServiceProvider serviceProvider) {

    String oauthConsumerSecret = null;

    if (serviceProvider.getInboundAuthenticationConfig() != null
            && serviceProvider.getInboundAuthenticationConfig()
            .getInboundAuthenticationRequestConfigs() != null
            && serviceProvider.getInboundAuthenticationConfig()
            .getInboundAuthenticationRequestConfigs().length > 0) {

        InboundAuthenticationRequestConfig[] authReqConfigs = serviceProvider
                .getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();

        for (InboundAuthenticationRequestConfig authReqConfig : authReqConfigs) {
            if ((IdentityApplicationConstants.OAuth2.NAME).equals(authReqConfig.getInboundAuthType())) {
                if (authReqConfig.getProperties() != null) {
                    for (Property property : authReqConfig.getProperties()) {
                        if ((IdentityApplicationConstants.OAuth2.OAUTH_CONSUMER_SECRET)
                                .equalsIgnoreCase(property.getName())) {
                            oauthConsumerSecret = property.getValue();
                            break;
                        }
                    }
                }
            }
        }

    }

    String jwtBody = "{\"iss\":\"wso2\",\"exp\":" + new Date().getTime() + 3000 + ",\"iat\":"
            + new Date().getTime() + "," + jsonObj + "}";
    String jwtHeader = "{\"typ\":\"JWT\", \"alg\":\"HS256\"}";

    if (oauthConsumerSecret == null) {
        jwtHeader = "{\"typ\":\"JWT\", \"alg\":\"none\"}";
    }

    String base64EncodedHeader = Base64Utils.encode(jwtHeader.getBytes());
    String base64EncodedBody = Base64Utils.encode(jwtBody.getBytes());

    if (log.isDebugEnabled()) {
        log.debug("JWT Header :" + jwtHeader);
        log.debug("JWT Body :" + jwtBody);
    }

    String assertion = base64EncodedHeader + "." + base64EncodedBody;

    if (oauthConsumerSecret == null) {
        return assertion + ".";
    } else {
        String signedAssertion;
        try {
            signedAssertion = calculateHmacSha1(oauthConsumerSecret, assertion);
            return assertion + "." + signedAssertion;
        } catch (SignatureException e) {
            log.error("Error while siging the assertion", e);
            return assertion + ".";
        }
    }
}