use of org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes 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.api.server.userstore.v1.model.AddUserStorePropertiesRes in project identity-api-server by wso2.
the class ServerUserStoreService method buildUserStorePropertiesRes.
/**
* Build user store properties response of created or updated user store.
*
* @param userStoreReq {@link UserStoreReq} to insert.
* @return List<AddUserStorePropertiesRes>.
*/
private List<AddUserStorePropertiesRes> buildUserStorePropertiesRes(UserStoreReq userStoreReq) {
List<org.wso2.carbon.identity.api.server.userstore.v1.model.Property> values = userStoreReq.getProperties();
List<AddUserStorePropertiesRes> propertiesToAdd = new ArrayList<>();
for (org.wso2.carbon.identity.api.server.userstore.v1.model.Property value : values) {
AddUserStorePropertiesRes addUserStorePropertiesRes = new AddUserStorePropertiesRes();
addUserStorePropertiesRes.setName(value.getName());
addUserStorePropertiesRes.setValue(value.getValue());
propertiesToAdd.add(addUserStorePropertiesRes);
}
return propertiesToAdd;
}
use of org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes 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);
}
}
}
use of org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes in project identity-api-server by wso2.
the class ServerUserStoreService method getPrimaryUserStore.
/**
* Retrieve primary user store.
*
* @return UserStoreConfigurationsRes.
*/
public UserStoreConfigurationsRes getPrimaryUserStore() {
RealmService realmService = UserStoreConfigServiceHolder.getInstance().getRealmService();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
RealmConfiguration realmConfiguration;
try {
realmConfiguration = realmService.getTenantUserRealm(tenantId).getRealmConfiguration();
} catch (UserStoreException exception) {
if (LOG.isDebugEnabled()) {
LOG.debug("Error occurred while getting the RealmConfiguration for tenant: " + tenantId, exception);
}
throw handleException(Response.Status.INTERNAL_SERVER_ERROR, UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_REALM_CONFIG, Integer.toString(tenantId));
}
if (realmConfiguration == null) {
throw handleException(Response.Status.INTERNAL_SERVER_ERROR, UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_PRIMARY_USERSTORE);
}
List<AddUserStorePropertiesRes> propertiesTobeAdd = new ArrayList<>();
UserStoreConfigurationsRes primaryUserstoreConfigs = new UserStoreConfigurationsRes();
primaryUserstoreConfigs.setClassName(realmConfiguration.getUserStoreClass());
primaryUserstoreConfigs.setDescription(realmConfiguration.getDescription());
primaryUserstoreConfigs.setName(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
primaryUserstoreConfigs.setTypeId(base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(realmConfiguration.getUserStoreClass()))));
primaryUserstoreConfigs.setTypeName(getUserStoreTypeName(realmConfiguration.getUserStoreClass()));
Map<String, String> userstoreProps = realmConfiguration.getUserStoreProperties();
if (MapUtils.isNotEmpty(userstoreProps)) {
for (Map.Entry<String, String> entry : userstoreProps.entrySet()) {
AddUserStorePropertiesRes userStorePropertiesRes = new AddUserStorePropertiesRes();
userStorePropertiesRes.setName(entry.getKey());
if (UserStoreConfigConstants.connectionPassword.equals(entry.getKey())) {
userStorePropertiesRes.setValue(UserStoreConstants.USER_STORE_PROPERTY_MASK);
} else {
userStorePropertiesRes.setValue(entry.getValue());
}
propertiesTobeAdd.add(userStorePropertiesRes);
}
}
primaryUserstoreConfigs.setProperties(propertiesTobeAdd);
try {
primaryUserstoreConfigs.setIsLocal(UserStoreManagerRegistry.isLocalUserStore(realmConfiguration.getUserStoreClass()));
List<ClaimAttributeMapping> claimAttributeMappings = getClaimAttributeMappings(ContextLoader.getTenantDomainFromContext(), UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
primaryUserstoreConfigs.setClaimAttributeMappings(claimAttributeMappings);
} catch (UserStoreException e) {
LOG.error(String.format("Cannot found user store manager type for user store manager: %s", getUserStoreType(realmConfiguration.getUserStoreClass())), e);
}
return primaryUserstoreConfigs;
}
use of org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes in project identity-api-server by wso2.
the class ServerUserStoreService method patchUserStoreProperties.
/**
* To construct properties list for patch request.
*
* @param propertyDTOS array of {@link PropertyDTO}
* @return List<AddUserStorePropertiesRes>
*/
private List<AddUserStorePropertiesRes> patchUserStoreProperties(PropertyDTO[] propertyDTOS) {
List<AddUserStorePropertiesRes> propertiesToAdd = new ArrayList<>();
for (PropertyDTO propertyDTO : propertyDTOS) {
AddUserStorePropertiesRes patchUserStoreProperties = new AddUserStorePropertiesRes();
patchUserStoreProperties.setName(propertyDTO.getName());
patchUserStoreProperties.setValue(propertyDTO.getValue());
propertiesToAdd.add(patchUserStoreProperties);
}
return propertiesToAdd;
}
Aggregations