Java Code Examples for org.wso2.carbon.base.api.ServerConfigurationService#getFirstProperty()

The following examples show how to use org.wso2.carbon.base.api.ServerConfigurationService#getFirstProperty() . 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: SecondaryUserStoreConfigurator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Encrypt a given text.
 *
 * @param plainText Cipher text to be encrypted
 * @return Returns the encrypted text
 * @throws IdentityUserStoreMgtException Encryption failed
 */
public String encryptPlainText(String plainText) throws IdentityUserStoreMgtException {

    boolean isInternalKeyStoreEncryptionEnabled = false;
    boolean isSymmetricKeyEncryptionEnabled = false;
    ServerConfigurationService config =
            UserStoreConfigComponent.getServerConfigurationService();
    if (config != null) {
        String encryptionKeyStore = config.getFirstProperty(ENCRYPTION_KEYSTORE);

        if (INTERNAL_KEYSTORE.equalsIgnoreCase(encryptionKeyStore)) {
            isInternalKeyStoreEncryptionEnabled = true;
        }
        String cryptoProvider = config.getFirstProperty(CRYPTO_PROVIDER);
        if (SYMMETRIC_KEY_CRYPTO_PROVIDER.equalsIgnoreCase(cryptoProvider)) {
            isSymmetricKeyEncryptionEnabled = true;
        }
    }

    if (isInternalKeyStoreEncryptionEnabled && isSymmetricKeyEncryptionEnabled) {

        throw new IdentityUserStoreMgtException(String.format("Userstore encryption can not be supported due to " +
                "conflicting configurations: '%s' and '%s'. When using internal keystore, assymetric crypto " +
                "provider should be used.", INTERNAL_KEYSTORE, SYMMETRIC_KEY_CRYPTO_PROVIDER));
    } else if (isInternalKeyStoreEncryptionEnabled || isSymmetricKeyEncryptionEnabled) {

        try {
            return CryptoUtil.getDefaultCryptoUtil().encryptAndBase64Encode(plainText.getBytes());
        } catch (CryptoException e) {
            String errorMessage = "Error while encrypting the plain text using internal keystore.";
            throw new IdentityUserStoreMgtException(errorMessage, e);
        }
    } else {
        return encryptWithPrimaryKeyStore(config, plainText);
    }
}
 
Example 2
Source File: UserStoreUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Util function to encrypt given plain text using given cipher
 *
 * @param plainTextBytes target plain text to encrypt using the cipher
 * @return Cipher text
 * @throws BadPaddingException
 * @throws IllegalBlockSizeException
 * @throws IOException
 */
public static byte[] encrypt(byte[] plainTextBytes) throws CryptoException {

    boolean isInternalKeyStoreEncryptionEnabled = false;
    boolean isSymmetricKeyEncryptionEnabled = false;
    ServerConfigurationService config =
            UserStoreConfigComponent.getServerConfigurationService();
    if (config != null) {
        String encryptionKeyStore = config.getFirstProperty(UserStoreConfigurationConstants.ENCRYPTION_KEYSTORE);

        if (INTERNAL_KEYSTORE.equalsIgnoreCase(encryptionKeyStore)) {
            isInternalKeyStoreEncryptionEnabled = true;
        }
        String cryptoProvider = config.getFirstProperty(UserStoreConfigurationConstants.CRYPTO_PROVIDER);
        if (UserStoreConfigurationConstants.SYMMETRIC_KEY_CRYPTO_PROVIDER.equalsIgnoreCase(cryptoProvider)) {
            isSymmetricKeyEncryptionEnabled = true;
        }
    }

    if (isInternalKeyStoreEncryptionEnabled && isSymmetricKeyEncryptionEnabled) {

        throw new CryptoException(String.format("Userstore encryption can not be supported due to " +
                        "conflicting configurations: '%s' and '%s'. When using internal keystore, assymetric crypto " +
                        "provider should be used.", UserStoreConfigurationConstants.INTERNAL_KEYSTORE,
                UserStoreConfigurationConstants.SYMMETRIC_KEY_CRYPTO_PROVIDER));
    } else if (isInternalKeyStoreEncryptionEnabled || isSymmetricKeyEncryptionEnabled) {
        return CryptoUtil.getDefaultCryptoUtil().encrypt(plainTextBytes);
    } else {
        return encryptWithPrimaryKeyStore(plainTextBytes);
    }
}
 
Example 3
Source File: CarbonUIServiceComponent.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * This method checks whether the management console is configured to run on the local transport.
 * Check the ServerURL property in the carbon.xml.
 * Set a system property if and only if the system is running on local transport.
 * 
 * @param serverConfiguration Service configuration.
 * @return boolean; true if running on local transport
 */
private boolean checkForLocalTransportMode(ServerConfigurationService serverConfiguration) {
    String serverURL = serverConfiguration.getFirstProperty(CarbonConstants.SERVER_URL);
    if(serverURL != null && (serverURL.startsWith("local") ||
            serverURL.startsWith("Local") || serverURL.startsWith("LOCAL"))) {
        System.setProperty(CarbonConstants.LOCAL_TRANSPORT_MODE_ENABLED, "true");
        return true;
    }
    return false;
}
 
Example 4
Source File: CarbonUIUtil.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * Get a ServerConfiguration Property
 *
 * @param propertyName Name of the property
 * @return the property
 */
public static String getServerConfigurationProperty(String propertyName) {
    try {
        ServerConfigurationService serverConfig = CarbonUIServiceComponent.getServerConfiguration();
        return serverConfig.getFirstProperty(propertyName);
    } catch (Exception e) {
        String msg = "ServerConfiguration Service not available";
        log.error(msg, e);
    }

    return null;
}
 
Example 5
Source File: CarbonUIUtil.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public static String getIndexPageURL(ServerConfigurationService serverConfig) {
    return serverConfig.getFirstProperty(CarbonConstants.INDEX_PAGE_URL);
}