use of org.wso2.carbon.identity.scim2.common.listener.SCIMGroupResolver in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMGroupResolver method getGroupByName.
@Override
public boolean getGroupByName(String groupName, List<String> requestedClaims, Group group, UserStoreManager userStoreManager) throws UserStoreException {
int tenantId = userStoreManager.getTenantId();
AbstractUserStoreManager abstractUserStoreManager = ((AbstractUserStoreManager) userStoreManager);
boolean isGroupIdEnabled = abstractUserStoreManager.isUniqueGroupIdEnabled();
/*
* isGroupIdEnabled equal to false indicates that the given userstore only support the legacy behaviour. In
* that case we need to support getting group details from IDN_SCIM_GROUP table.
*/
if (isGroupIdEnabled) {
if (log.isDebugEnabled()) {
log.debug(String.format("SCIMGroupResolver will not be executed for userstore: %s in " + "tenant %s since group id support is available in the userstore manager", abstractUserStoreManager.getRealmConfiguration().getRealmProperty(PROPERTY_DOMAIN_NAME), tenantId));
}
return true;
}
if (log.isDebugEnabled()) {
log.debug(String.format("Retrieving group with name: %s from tenant: %s", groupName, tenantId));
}
Map<String, String> attributes;
GroupDAO groupDAO = new GroupDAO();
try {
// If the group name as the domain separator ( / ), that means, domain is in the name.
if (!groupName.contains(CarbonConstants.DOMAIN_SEPARATOR)) {
String domainName = abstractUserStoreManager.getRealmConfiguration().getUserStoreProperty(UserStoreConfigConstants.DOMAIN_NAME);
groupName = UserCoreUtil.addDomainToName(groupName, domainName);
}
attributes = groupDAO.getSCIMGroupAttributes(tenantId, groupName);
} catch (IdentitySCIMException e) {
throw new UserStoreException(String.format("Error occurred while getting the group attributes of " + "group: %s in tenant: %s", groupName, tenantId), e);
}
if (MapUtils.isEmpty(attributes)) {
if (log.isDebugEnabled()) {
log.debug(String.format("No group found with name: %s in tenant: %s", groupName, tenantId));
}
return true;
}
String groupId = attributes.get(SCIMConstants.CommonSchemaConstants.ID_URI);
String domainName = UserCoreUtil.extractDomainFromName(groupName);
if (group == null) {
group = new Group(groupId, resolveGroupName(groupName, domainName));
} else {
group.setGroupName(groupName);
}
// Set mandatory attributes.
for (Map.Entry<String, String> entry : attributes.entrySet()) {
if (SCIMConstants.CommonSchemaConstants.ID_URI.equals(entry.getKey())) {
group.setGroupID(groupId);
} else if (SCIMConstants.CommonSchemaConstants.CREATED_URI.equals(entry.getKey())) {
group.setCreatedDate(entry.getValue());
} else if (SCIMConstants.CommonSchemaConstants.LAST_MODIFIED_URI.equals(entry.getKey())) {
group.setLastModifiedDate(entry.getValue());
} else if (SCIMConstants.CommonSchemaConstants.LOCATION_URI.equals(entry.getKey())) {
group.setLocation(SCIMCommonUtils.getSCIMGroupURL(groupId));
}
}
group.setDisplayName(UserCoreUtil.removeDomainFromName(groupName));
group.setUserStoreDomain(domainName);
return true;
}
use of org.wso2.carbon.identity.scim2.common.listener.SCIMGroupResolver in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMGroupResolver method getGroupById.
@Override
public boolean getGroupById(String groupID, List<String> requestedClaims, Group group, UserStoreManager userStoreManager) throws UserStoreException {
int tenantId = userStoreManager.getTenantId();
AbstractUserStoreManager abstractUserStoreManager = ((AbstractUserStoreManager) userStoreManager);
boolean isGroupIdEnabled = abstractUserStoreManager.isUniqueGroupIdEnabled();
/*
* isGroupIdEnabled equal to false indicates that the given userstore only support the legacy behaviour. In
* that case we need to support getting group details from IDN_SCIM_GROUP table.
*/
if (isGroupIdEnabled) {
if (log.isDebugEnabled()) {
log.debug(String.format("SCIMGroupResolver will not be executed for userstore: %s in " + "tenant %s since group id support is available in the userstore manager", abstractUserStoreManager.getRealmConfiguration().getRealmProperty(PROPERTY_DOMAIN_NAME), tenantId));
}
return true;
}
if (log.isDebugEnabled()) {
log.debug(String.format("Retrieving group with id: %s from tenant: %s", groupID, tenantId));
}
String groupName;
Map<String, String> attributes;
GroupDAO groupDAO = new GroupDAO();
try {
groupName = groupDAO.getGroupNameById(tenantId, groupID);
if (StringUtils.isBlank(groupName)) {
log.error(String.format("No group found with id: %s in tenant: %s", groupID, tenantId));
return true;
}
attributes = groupDAO.getSCIMGroupAttributes(tenantId, groupName);
} catch (IdentitySCIMException e) {
throw new UserStoreException(String.format("Error occurred while getting the group attributes of " + "group: %s in tenant: %s", groupID, tenantId), e);
}
// At this point there is definitely a matching group for the given id.
String domainName = UserCoreUtil.extractDomainFromName(groupName);
if (group == null) {
group = new Group(groupID, resolveGroupName(groupName, domainName));
} else {
group.setGroupID(groupID);
group.setGroupName(resolveGroupName(groupName, domainName));
}
// Removing the userstore domain name from the display name and setting it as the userstore domain of the group.
group.setDisplayName(UserCoreUtil.removeDomainFromName(groupName));
group.setUserStoreDomain(domainName);
// Set mandatory attributes.
for (Map.Entry<String, String> entry : attributes.entrySet()) {
if (SCIMConstants.CommonSchemaConstants.ID_URI.equals(entry.getKey())) {
group.setGroupID(entry.getValue());
} else if (SCIMConstants.CommonSchemaConstants.CREATED_URI.equals(entry.getKey())) {
group.setCreatedDate(entry.getValue());
} else if (SCIMConstants.CommonSchemaConstants.LAST_MODIFIED_URI.equals(entry.getKey())) {
group.setLastModifiedDate(entry.getValue());
} else if (SCIMConstants.CommonSchemaConstants.LOCATION_URI.equals(entry.getKey())) {
group.setLocation(SCIMCommonUtils.getSCIMGroupURL(groupID));
}
}
return true;
}
Aggregations