use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project identity-api-server by wso2.
the class ServerUserStoreService method getUserStoreByDomainId.
/**
* Retrieve user store by its domain id.
*
* @param domainId the user store domain id.
* @return UserStoreConfigurationsRes.
*/
public UserStoreConfigurationsRes getUserStoreByDomainId(String domainId) {
UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
List<AddUserStorePropertiesRes> propertiesTobeAdd = new ArrayList<>();
try {
UserStoreDTO userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId));
if (userStoreDTO == null) {
throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.ERROR_CODE_NOT_FOUND);
}
List<ClaimAttributeMapping> claimAttributeMappings = getClaimAttributeMappings(ContextLoader.getTenantDomainFromContext(), base64URLDecodeId(domainId));
UserStoreConfigurationsRes userStoreConfigurations = new UserStoreConfigurationsRes();
userStoreConfigurations.setClassName(userStoreDTO.getClassName());
userStoreConfigurations.setDescription(userStoreDTO.getDescription());
userStoreConfigurations.setName(userStoreDTO.getDomainId());
userStoreConfigurations.setTypeId(base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(userStoreDTO.getClassName()))));
userStoreConfigurations.setTypeName(getUserStoreTypeName(userStoreDTO.getClassName()));
PropertyDTO[] dtoProperties = userStoreDTO.getProperties();
for (PropertyDTO propertyDTO : dtoProperties) {
AddUserStorePropertiesRes userStorePropertiesRes = new AddUserStorePropertiesRes();
userStorePropertiesRes.setName(propertyDTO.getName());
userStorePropertiesRes.setValue(propertyDTO.getValue());
propertiesTobeAdd.add(userStorePropertiesRes);
}
userStoreConfigurations.setProperties(propertiesTobeAdd);
try {
userStoreConfigurations.setIsLocal(UserStoreManagerRegistry.isLocalUserStore(userStoreDTO.getClassName()));
userStoreConfigurations.setClaimAttributeMappings(claimAttributeMappings);
} catch (UserStoreException e) {
LOG.error(String.format("Cannot found user store manager type for user store manager: %s", getUserStoreType(userStoreDTO.getClassName())), e);
}
return userStoreConfigurations;
} catch (IdentityUserStoreMgtException e) {
UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_USER_STORE_BY_DOMAIN_ID;
throw handleIdentityUserStoreMgtException(e, errorEnum);
}
}
use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project identity-api-server by wso2.
the class ServerUserStoreService method buildResponseForPatchReplace.
/**
* Construct the response for patch replace.
*
* @param userStoreDTO {@link UserStoreDTO}.
* @param propertyDTOS array of {@link PropertyDTO}.
* @return UserStoreResponse.
*/
private UserStoreResponse buildResponseForPatchReplace(UserStoreDTO userStoreDTO, PropertyDTO[] propertyDTOS) {
UserStoreResponse userStoreResponseDTO = new UserStoreResponse();
userStoreResponseDTO.setId((base64URLEncodeId(userStoreDTO.getDomainId())));
userStoreResponseDTO.setName(userStoreDTO.getDomainId());
userStoreResponseDTO.setTypeId(base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(userStoreDTO.getClassName()))));
userStoreResponseDTO.setTypeName(getUserStoreTypeName(userStoreDTO.getClassName()));
userStoreResponseDTO.setDescription(userStoreDTO.getDescription());
userStoreResponseDTO.setProperties(patchUserStoreProperties(propertyDTOS));
return userStoreResponseDTO;
}
use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project identity-api-server by wso2.
the class ServerUserStoreService method createUserStoreDTO.
/**
* To create UserStoreDTO object for this request.
*
* @param userStoreReq {@link UserStoreReq}.
* @return UserStoreDTO.
*/
private UserStoreDTO createUserStoreDTO(UserStoreReq userStoreReq) {
UserStoreDTO userStoreDTO = new UserStoreDTO();
userStoreDTO.setDomainId(userStoreReq.getName());
userStoreDTO.setClassName(getUserStoreType(base64URLDecodeId(userStoreReq.getTypeId())));
userStoreDTO.setDescription(userStoreReq.getDescription());
userStoreDTO.setProperties(createPropertyListDTO(userStoreReq));
return userStoreDTO;
}
use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project identity-api-server by wso2.
the class ServerUserStoreService method addUserStore.
/**
* Add a userStore {@link UserStoreReq}.
*
* @param userStoreReq {@link UserStoreReq} to insert.
* @return UserStoreResponse
*/
public UserStoreResponse addUserStore(UserStoreReq userStoreReq) {
try {
validateMandatoryProperties(userStoreReq);
if (!isAvailableUserStoreTypes(getAvailableUserStoreTypes(), userStoreReq.getTypeId())) {
throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_USERSTORE_TYPE);
}
String userstoreDomain = userStoreReq.getName();
String tenantDomain = ContextLoader.getTenantDomainFromContext();
List<LocalClaim> localClaimList = new ArrayList<>();
List<ClaimAttributeMapping> claimAttributeMappingList = userStoreReq.getClaimAttributeMappings();
if (claimAttributeMappingList != null) {
localClaimList = createLocalClaimList(userstoreDomain, claimAttributeMappingList);
validateClaimMappings(tenantDomain, localClaimList);
}
UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
UserStoreDTO userStoreDTO = createUserStoreDTO(userStoreReq);
userStoreConfigService.addUserStore(userStoreDTO);
if (claimAttributeMappingList != null) {
updateClaimMappings(userstoreDomain, tenantDomain, localClaimList);
}
return buildUserStoreResponseDTO(userStoreReq);
} catch (IdentityUserStoreMgtException e) {
UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_USER_STORE;
throw handleIdentityUserStoreMgtException(e, errorEnum);
}
}
use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project identity-api-server by wso2.
the class ServerUserStoreService method addUserstoreProperties.
/**
* Add requested user store properties to the response.
*
* @param userStoreDTO userStoreDTO object.
* @param userStoreListResponse userStoreListResponse object.
* @param requestedAttributesList Requested user store properties name list.
*/
private void addUserstoreProperties(UserStoreDTO userStoreDTO, UserStoreListResponse userStoreListResponse, List<String> requestedAttributesList) {
for (PropertyDTO propertyDTO : userStoreDTO.getProperties()) {
if (requestedAttributesList.contains(propertyDTO.getName()) && StringUtils.isNotBlank(propertyDTO.getValue())) {
AddUserStorePropertiesRes addUserStorePropertiesRes = new AddUserStorePropertiesRes();
addUserStorePropertiesRes.setName(propertyDTO.getName());
addUserStorePropertiesRes.setValue(propertyDTO.getValue());
userStoreListResponse.addPropertiesItem(addUserStorePropertiesRes);
}
}
}
Aggregations