Search in sources :

Example 1 with MaskedProperty

use of org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty in project carbon-identity-framework by wso2.

the class FileBasedUserStoreDAOImpl method getUserStores.

@Override
public UserStoreDTO[] getUserStores() throws IdentityUserStoreMgtException {
    RealmConfiguration secondaryRealmConfiguration;
    List<UserStoreDTO> domains = new ArrayList<>();
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        throw new IdentityUserStoreMgtException(errorMessage);
    }
    if (secondaryRealmConfiguration == null) {
        if (log.isDebugEnabled()) {
            log.debug("SecondaryRealmConfiguration is null. Can not find any userStore.");
        }
        return new UserStoreDTO[0];
    } else {
        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();
            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }
            String className = secondaryRealmConfiguration.getUserStoreClass();
            UserStoreDTO userStoreDTO = getUserStoreDTO(secondaryRealmConfiguration, userStoreProperties);
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(secondaryRealmConfiguration, userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));
            // Now revert back to original password.
            for (MaskedProperty maskedProperty : maskedProperties) {
                userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
            }
            domains.add(userStoreDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
        } while (secondaryRealmConfiguration != null);
    }
    return domains.toArray(new UserStoreDTO[domains.size()]);
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) MaskedProperty(org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)

Example 2 with MaskedProperty

use of org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty in project carbon-identity-framework by wso2.

the class SecondaryUserStoreConfigurationUtil method getMaskedProperties.

private static MaskedProperty[] getMaskedProperties(String userStoreClass, String maskValue, RealmConfiguration secondaryRealmConfiguration) {
    // First check for mandatory field with #encrypt
    Property[] mandatoryProperties = getMandatoryProperties(userStoreClass);
    ArrayList<MaskedProperty> maskedProperties = new ArrayList<>();
    for (Property property : mandatoryProperties) {
        String propertyName = property.getName();
        if (property.getDescription().contains(UserStoreConfigurationConstant.ENCRYPT_TEXT)) {
            MaskedProperty maskedProperty = new MaskedProperty();
            maskedProperty.setName(propertyName);
            maskedProperty.setValue(secondaryRealmConfiguration.getUserStoreProperty(propertyName));
            maskedProperty.setMask(maskValue);
            maskedProperties.add(maskedProperty);
        }
    }
    return maskedProperties.toArray(new MaskedProperty[0]);
}
Also used : ArrayList(java.util.ArrayList) MaskedProperty(org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty) MaskedProperty(org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty) Property(org.wso2.carbon.user.api.Property)

Example 3 with MaskedProperty

use of org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty in project carbon-identity-framework by wso2.

the class DatabaseBasedUserStoreDAOImpl method getUserStoreDTO.

private UserStoreDTO getUserStoreDTO(RealmConfiguration realmConfiguration) {
    Map<String, String> userStoreProperties = realmConfiguration.getUserStoreProperties();
    String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
    if (uuid == null) {
        uuid = UUID.randomUUID().toString();
    }
    String className = realmConfiguration.getUserStoreClass();
    UserStoreDTO userStoreDTO = getUserStoreDTO(realmConfiguration, userStoreProperties);
    userStoreProperties.put("Class", className);
    userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
    MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(realmConfiguration, userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);
    userStoreDTO.setProperties(convertMapToArray(userStoreProperties));
    // Now revert back to original password.
    for (MaskedProperty maskedProperty : maskedProperties) {
        userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
    }
    return userStoreDTO;
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) MaskedProperty(org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)

Example 4 with MaskedProperty

use of org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty in project carbon-identity-framework by wso2.

the class FileBasedUserStoreDAOImpl method doGetAllUserStores.

@Override
protected UserStorePersistanceDTO[] doGetAllUserStores() throws IdentityUserStoreMgtException {
    RealmConfiguration secondaryRealmConfiguration;
    List<UserStorePersistanceDTO> userStorePersistanceDAOList = new ArrayList<>();
    UserStorePersistanceDTO userStorePersistanceDTO = new UserStorePersistanceDTO();
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        throw new IdentityUserStoreMgtException(errorMessage);
    }
    if (secondaryRealmConfiguration == null) {
        if (log.isDebugEnabled()) {
            log.debug("SecondaryRealmConfiguration is null. Can not find any userStore.");
        }
        return new UserStorePersistanceDTO[0];
    } else {
        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();
            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }
            String className = secondaryRealmConfiguration.getUserStoreClass();
            UserStoreDTO userStoreDTO = getUserStoreDTO(secondaryRealmConfiguration, userStoreProperties);
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(secondaryRealmConfiguration, userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));
            // Now revert back to original password.
            for (MaskedProperty maskedProperty : maskedProperties) {
                userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
            }
            userStorePersistanceDTO.setUserStoreDTO(userStoreDTO);
            userStorePersistanceDAOList.add(userStorePersistanceDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
        } while (secondaryRealmConfiguration != null);
    }
    return userStorePersistanceDAOList.toArray(new UserStorePersistanceDTO[userStorePersistanceDAOList.size()]);
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStorePersistanceDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO) MaskedProperty(org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)

Aggregations

MaskedProperty (org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)4 ArrayList (java.util.ArrayList)3 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)3 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)2 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 UserStorePersistanceDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO)1 Property (org.wso2.carbon.user.api.Property)1