use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService 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.UserStoreConfigService in project identity-api-server by wso2.
the class ServerUserStoreService method getAvailableUserStoreTypes.
/**
* To retrieve the available user store classes.
*
* @return List<AvailableUserStoreClassesRes>.
*/
public List<AvailableUserStoreClassesRes> getAvailableUserStoreTypes() {
UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
Set<String> classNames;
try {
classNames = userStoreConfigService.getAvailableUserStoreClasses();
List<AvailableUserStoreClassesRes> propertiesToAdd = new ArrayList<>();
Map<String, Boolean> userStoreManagersType = UserStoreManagerRegistry.getUserStoreManagersType();
for (String className : classNames) {
AvailableUserStoreClassesRes availableUserStoreClassesResDTO = new AvailableUserStoreClassesRes();
String typeId = base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(className)));
availableUserStoreClassesResDTO.setClassName(className);
availableUserStoreClassesResDTO.setTypeName(getUserStoreTypeName(className));
availableUserStoreClassesResDTO.setTypeId(typeId);
availableUserStoreClassesResDTO.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + UserStoreConstants.USER_STORE_PATH_COMPONENT + "/meta/types/%s", typeId)).toString());
if (userStoreManagersType.containsKey(className)) {
availableUserStoreClassesResDTO.setIsLocal(userStoreManagersType.get(className));
}
propertiesToAdd.add(availableUserStoreClassesResDTO);
}
return propertiesToAdd;
} catch (IdentityUserStoreMgtException e) {
UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_RETRIEVING_USER_STORE_TYPE;
throw handleIdentityUserStoreMgtException(e, errorEnum);
}
}
use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService in project carbon-identity-framework by wso2.
the class UserStoreConfigComponent method activate.
/**
* @param ctxt
*/
@Activate
protected void activate(ComponentContext ctxt) {
if (log.isDebugEnabled()) {
log.debug("Identity User Store bundle is activated.");
}
try {
BundleContext bundleContext = ctxt.getBundleContext();
AbstractUserStoreDAOFactory fileBasedUserStoreDAOFactory = new FileBasedUserStoreDAOFactory();
AbstractUserStoreDAOFactory databaseBasedUserStoreDAOFactory = new DatabaseBasedUserStoreDAOFactory();
ServiceRegistration serviceRegistration = bundleContext.registerService(AbstractUserStoreDAOFactory.class.getName(), fileBasedUserStoreDAOFactory, null);
bundleContext.registerService(AbstractUserStoreDAOFactory.class.getName(), databaseBasedUserStoreDAOFactory, null);
UserStoreConfigService userStoreConfigService = new UserStoreConfigServiceImpl();
ctxt.getBundleContext().registerService(UserStoreConfigService.class.getName(), userStoreConfigService, null);
UserStoreConfigListenersHolder.getInstance().setUserStoreConfigService(userStoreConfigService);
UserStoreHashProviderConfigListenerImpl userStoreHashProviderListener = new UserStoreHashProviderConfigListenerImpl();
ctxt.getBundleContext().registerService(UserStoreConfigListener.class.getName(), userStoreHashProviderListener, null);
UserStoreConfigListenersHolder.getInstance().setUserStoreConfigListenerService(userStoreHashProviderListener);
if (serviceRegistration != null) {
if (log.isDebugEnabled()) {
log.debug("FileBasedUserStoreDAOFactory is successfully registered.");
}
} else {
log.error("FileBasedUserStoreDAOFactory could not be registered.");
}
readAllowedUserstoreConfiguration();
readUserStoreAttributeMappingConfigs();
} catch (Throwable e) {
log.error("Failed to load user store org.wso2.carbon.identity.user.store.configuration details.", e);
}
if (log.isDebugEnabled()) {
log.debug("Identity User Store-Config bundle is activated.");
}
}
use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService in project identity-api-server by wso2.
the class ServerUserStoreService method editUserStore.
/**
* Update the user store by its domain Id.
*
* @param domainId the domain name to be replaced
* @param userStoreReq {@link UserStoreReq} to edit.
* @return UserStoreResponse.
*/
public UserStoreResponse editUserStore(String domainId, UserStoreReq userStoreReq) {
UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
/*
domainName and typeName are not allowed to edit. iF domain name wanted to update then use
userStoreConfigService.updateUserStoreByDomainName(base64URLDecodeId(domainId),
createUserStoreDTO(userStoreReq, domainId));
*/
try {
validateUserstoreUpdateRequest(domainId, userStoreReq);
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.updateUserStore(createUserStoreDTO(userStoreReq), false);
if (claimAttributeMappingList != null) {
updateClaimMappings(userstoreDomain, tenantDomain, localClaimList);
}
return buildUserStoreResponseDTO(userStoreReq);
} catch (IdentityUserStoreMgtException e) {
UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_USER_STORE;
throw handleIdentityUserStoreMgtException(e, errorEnum);
}
}
use of org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService in project identity-api-server by wso2.
the class ServerUserStoreService method buildUserStoreForPatch.
private UserStoreDTO buildUserStoreForPatch(String domainId, List<PatchDocument> patchDocuments) {
UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
UserStoreDTO userStoreDTO;
try {
userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId));
if (userStoreDTO == null) {
throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.ERROR_CODE_NOT_FOUND);
}
PropertyDTO[] propertyDTOS = userStoreDTO.getProperties();
for (PatchDocument patchDocument : patchDocuments) {
String path = patchDocument.getPath();
String value = patchDocument.getValue();
if (StringUtils.isBlank(path)) {
throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
}
if (path.startsWith(UserStoreConstants.USER_STORE_PROPERTIES)) {
String propName = extractPropertyName(path);
if (StringUtils.isNotEmpty(propName)) {
for (PropertyDTO propertyDTO : propertyDTOS) {
if (propName.equals(propertyDTO.getName())) {
propertyDTO.setValue(value);
}
}
}
} else if (path.equals(UserStoreConstants.USER_STORE_DESCRIPTION)) {
userStoreDTO.setDescription(value);
} else {
throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT);
}
}
userStoreDTO.setProperties(propertyDTOS);
} catch (IdentityUserStoreMgtException e) {
UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_USER_STORE;
throw handleIdentityUserStoreMgtException(e, errorEnum);
}
return userStoreDTO;
}
Aggregations