Search in sources :

Example 6 with SCIMGroupResolver

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;
}
Also used : Group(org.wso2.carbon.user.core.common.Group) UserStoreException(org.wso2.carbon.user.core.UserStoreException) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) GroupDAO(org.wso2.carbon.identity.scim2.common.DAO.GroupDAO) Map(java.util.Map) IdentitySCIMException(org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)

Example 7 with SCIMGroupResolver

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;
}
Also used : Group(org.wso2.carbon.user.core.common.Group) UserStoreException(org.wso2.carbon.user.core.UserStoreException) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) GroupDAO(org.wso2.carbon.identity.scim2.common.DAO.GroupDAO) Map(java.util.Map) IdentitySCIMException(org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)

Aggregations

GroupDAO (org.wso2.carbon.identity.scim2.common.DAO.GroupDAO)6 IdentitySCIMException (org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)6 UserStoreException (org.wso2.carbon.user.core.UserStoreException)6 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)6 Group (org.wso2.carbon.user.core.common.Group)6 Map (java.util.Map)3 Activate (org.osgi.service.component.annotations.Activate)1 AbstractEventHandler (org.wso2.carbon.identity.event.handler.AbstractEventHandler)1 SCIMUserStoreErrorResolver (org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreErrorResolver)1 SCIMClaimOperationEventHandler (org.wso2.carbon.identity.scim2.common.handlers.SCIMClaimOperationEventHandler)1 DefaultSCIMUserStoreErrorResolver (org.wso2.carbon.identity.scim2.common.impl.DefaultSCIMUserStoreErrorResolver)1 SCIMGroupResolver (org.wso2.carbon.identity.scim2.common.listener.SCIMGroupResolver)1 SCIMTenantMgtListener (org.wso2.carbon.identity.scim2.common.listener.SCIMTenantMgtListener)1 SCIMUserOperationListener (org.wso2.carbon.identity.scim2.common.listener.SCIMUserOperationListener)1 SCIMConfigProcessor (org.wso2.carbon.identity.scim2.common.utils.SCIMConfigProcessor)1 TenantMgtListener (org.wso2.carbon.stratos.common.listeners.TenantMgtListener)1 GroupResolver (org.wso2.carbon.user.core.listener.GroupResolver)1 UserOperationEventListener (org.wso2.carbon.user.core.listener.UserOperationEventListener)1 ExpressionCondition (org.wso2.carbon.user.core.model.ExpressionCondition)1 OperationalCondition (org.wso2.carbon.user.core.model.OperationalCondition)1