use of org.wso2.carbon.identity.recovery.endpoint.dto.PropertyDTO in project carbon-identity-framework by wso2.
the class AbstractUserStoreDAO method getUserStoreProperty.
private UserStoreDTO getUserStoreProperty(UserStoreDTO userStoreDTO) throws IdentityUserStoreMgtException {
boolean newState = userStoreDTO.getDisabled();
UserStoreDTO userStoreDTOTemp = getUserStore(userStoreDTO.getDomainId());
if (userStoreDTOTemp != null) {
userStoreDTO = userStoreDTOTemp;
userStoreDTO.setDisabled(newState);
PropertyDTO[] propertyDTO = userStoreDTO.getProperties();
for (PropertyDTO propertyDTOValue : propertyDTO) {
if (propertyDTOValue.getName().equals(DISABLED)) {
propertyDTOValue.setValue(String.valueOf(newState));
}
}
}
return userStoreDTO;
}
use of org.wso2.carbon.identity.recovery.endpoint.dto.PropertyDTO in project carbon-identity-framework by wso2.
the class SecondaryUserStoreConfigurationUtil method addProperties.
/**
* Adds an array of properties
*
* @param propertyDTOs List of user store properties
* @param doc Document
* @param parent Parent element of the properties to be added
*/
private static void addProperties(String userStoreDomain, String userStoreClass, PropertyDTO[] propertyDTOs, Document doc, Element parent, boolean editSecondaryUserStore) throws IdentityUserStoreMgtException {
if (editSecondaryUserStore) {
String uniqueID = getUniqueIDFromUserDTO(propertyDTOs);
if (uniqueID == null) {
throw new IdentityUserStoreMgtException("UniqueID property is not provided.");
}
}
// First check for mandatory field with #encrypt
Property[] mandatoryProperties = getMandatoryProperties(userStoreClass);
Map<String, String> secondaryUserStoreProperties = getSecondaryUserStorePropertiesFromTenantUserRealm(userStoreDomain);
for (PropertyDTO propertyDTO : propertyDTOs) {
String propertyDTOName = propertyDTO.getName();
if (UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT.equalsIgnoreCase(propertyDTOName)) {
continue;
}
String propertyDTOValue = propertyDTO.getValue();
if (propertyDTOValue != null) {
boolean encrypted = false;
if (isPropertyToBeEncrypted(mandatoryProperties, propertyDTOName)) {
propertyDTOValue = getPropertyValueIfMasked(secondaryUserStoreProperties, propertyDTOName, propertyDTOValue);
try {
propertyDTOValue = SecondaryUserStoreConfigurationUtil.encryptPlainText(propertyDTOValue);
encrypted = true;
} catch (IdentityUserStoreMgtException e) {
LOG.error("addProperties failed to encrypt", e);
// its ok to continue from here
}
}
addProperty(propertyDTOName, propertyDTOValue, doc, parent, encrypted);
}
}
}
use of org.wso2.carbon.identity.recovery.endpoint.dto.PropertyDTO in project carbon-identity-framework by wso2.
the class UserStoreHashProviderConfigListenerImpl method validateHashProviderParams.
/**
* Derive the userStoreProperties from UserStoreDTO and Validating HashProvider params.
*
* @param userStoreDTO Data transfer object of userStore properties.
* @throws UserStoreException The exception thrown at validating the hashProvider params.
*/
private void validateHashProviderParams(UserStoreDTO userStoreDTO) throws UserStoreException {
PropertyDTO[] userStoreProperty = userStoreDTO.getProperties();
String userstoreDomainId = userStoreDTO.getDomainId();
String digestFunction = null;
String hashProviderParamsJSON = null;
if (ArrayUtils.isEmpty(userStoreProperty)) {
if (LOG.isDebugEnabled()) {
LOG.debug("No userstore properties found for userstore: " + userstoreDomainId);
}
return;
}
for (PropertyDTO propertyDTO : userStoreProperty) {
if (DIGEST_FUNCTION.equals(propertyDTO.getName())) {
digestFunction = propertyDTO.getValue();
}
if (HASH_PROVIDER_PARAMS_JSON.equals(propertyDTO.getName())) {
hashProviderParamsJSON = propertyDTO.getValue();
}
}
if (StringUtils.isBlank(hashProviderParamsJSON)) {
if (LOG.isDebugEnabled()) {
LOG.debug("No hash provider configurations found for: " + userstoreDomainId);
}
return;
}
// Retrieve the corresponding HashProviderFactory for the defined hashing function.
HashProviderFactory hashProviderFactory = UserStoreConfigListenersHolder.getInstance().getHashProviderFactory(digestFunction);
if (hashProviderFactory == null) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("No HashProviderFactory found digest function : %s for userstore: %s", digestFunction, userstoreDomainId));
}
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("HashProviderFactory: %s found for digest function: %s for userstore: %s", hashProviderFactory.getAlgorithm(), digestFunction, userstoreDomainId));
}
Set<String> hashProviderMetaProperties = hashProviderFactory.getHashProviderConfigProperties();
validateParams(hashProviderParamsJSON, hashProviderMetaProperties);
Map<String, Object> hashProviderPropertiesMap = getHashProviderInitConfigs(hashProviderParamsJSON);
try {
hashProviderFactory.getHashProvider(hashProviderPropertiesMap);
} catch (HashProviderException e) {
throw new UserStoreException("Error occurred while initializing the hashProvider.", e);
}
}
use of org.wso2.carbon.identity.recovery.endpoint.dto.PropertyDTO in project carbon-identity-framework by wso2.
the class PolicyPublisher method populateProperties.
private void populateProperties(PublisherDataHolder holder, PublisherDataHolder oldHolder, Resource resource) {
PublisherPropertyDTO[] propertyDTOs = holder.getPropertyDTOs();
for (PublisherPropertyDTO dto : propertyDTOs) {
if (dto.getId() != null && dto.getValue() != null && dto.getValue().trim().length() > 0) {
ArrayList<String> list = new ArrayList<String>();
if (dto.isSecret()) {
PublisherPropertyDTO propertyDTO = null;
if (oldHolder != null) {
propertyDTO = oldHolder.getPropertyDTO(dto.getId());
}
if (propertyDTO == null || !propertyDTO.getValue().equalsIgnoreCase(dto.getValue())) {
try {
String encryptedValue = CryptoUtil.getDefaultCryptoUtil().encryptAndBase64Encode(dto.getValue().getBytes());
dto.setValue(encryptedValue);
} catch (CryptoException e) {
log.error("Error while encrypting secret value of subscriber. " + "Secret would not be persist.", e);
continue;
}
}
}
list.add(dto.getValue());
list.add(dto.getDisplayName());
list.add(Integer.toString(dto.getDisplayOrder()));
list.add(Boolean.toString(dto.isRequired()));
list.add(Boolean.toString(dto.isSecret()));
resource.setProperty(dto.getId(), list);
}
}
resource.setProperty(PublisherDataHolder.MODULE_NAME, holder.getModuleName());
}
use of org.wso2.carbon.identity.recovery.endpoint.dto.PropertyDTO in project identity-governance by wso2-extensions.
the class LiteApiServiceImpl method litePost.
@Override
public Response litePost(LiteUserRegistrationRequestDTO liteUserRegistrationRequestDTO) {
// reject if username is not present.
if (liteUserRegistrationRequestDTO == null || (StringUtils.isBlank(liteUserRegistrationRequestDTO.getEmail()) && StringUtils.isBlank(liteUserRegistrationRequestDTO.getMobile()))) {
Utils.handleBadRequest(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_BAD_LITE_REGISTER_REQUEST.getMessage(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_BAD_LITE_REGISTER_REQUEST.getCode());
}
String tenantFromContext = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
List<PropertyDTO> properties = new ArrayList<>();
User user = new User();
user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
user.setUserStoreDomain(IdentityUtil.getPrimaryDomainName());
user.setUserName(liteUserRegistrationRequestDTO.getEmail());
PropertyDTO propertyDTO = new PropertyDTO();
propertyDTO.setKey(IdentityRecoveryConstants.IS_LITE_SIGN_UP);
propertyDTO.setValue("true");
properties.add(propertyDTO);
if (StringUtils.isNotBlank(liteUserRegistrationRequestDTO.getRealm())) {
user.setUserStoreDomain(liteUserRegistrationRequestDTO.getRealm());
}
if (StringUtils.isNotBlank(tenantFromContext)) {
user.setTenantDomain(tenantFromContext);
}
UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
NotificationResponseBean notificationResponseBean = null;
properties.addAll(liteUserRegistrationRequestDTO.getProperties());
try {
notificationResponseBean = userSelfRegistrationManager.registerLiteUser(user, Utils.getClaims(liteUserRegistrationRequestDTO.getClaims()), Utils.getProperties(properties));
} catch (IdentityRecoveryClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Client Error while self registering lite user ", e);
}
if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USER_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
Utils.handleConflict(e.getMessage(), e.getErrorCode());
} else {
Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
}
} catch (IdentityRecoveryException e) {
Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
} catch (Throwable throwable) {
Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
}
return buildSuccessfulAPIResponse(notificationResponseBean);
}
Aggregations