Search in sources :

Example 11 with GroupDAO

use of org.wso2.carbon.identity.scim2.common.DAO.GroupDAO in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMGroupResolver method resolveGroupDomainByGroupId.

@Override
public boolean resolveGroupDomainByGroupId(Group group, int tenantId) throws UserStoreException {
    if (group == null || StringUtils.isBlank(group.getGroupID())) {
        return true;
    }
    String groupId = group.getGroupID();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Retrieving group with id:%s from tenant: %s", groupId, tenantId));
    }
    GroupDAO groupDAO = new GroupDAO();
    String groupName;
    try {
        groupName = groupDAO.getGroupNameById(tenantId, groupId);
    } catch (IdentitySCIMException exception) {
        throw new UserStoreException(String.format("Error occurred while resolving the domain name for " + "group with id: %s in tenant: %s", groupId, tenantId), exception);
    }
    if (StringUtils.isBlank(groupName)) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No group found in IDN_SCIM_GROUP with group id: %s in tenant: %s", groupId, tenantId));
        }
        return true;
    }
    String resolvedDomain = IdentityUtil.extractDomainFromName(groupName);
    if (log.isDebugEnabled()) {
        log.debug(String.format("Domain: %s resolved for group id: %s in tenant: %s", resolvedDomain, groupId, tenantId));
    }
    group.setGroupName(groupName);
    group.setDisplayName(UserCoreUtil.removeDomainFromName(groupName));
    group.setUserStoreDomain(resolvedDomain);
    return true;
}
Also used : UserStoreException(org.wso2.carbon.user.core.UserStoreException) GroupDAO(org.wso2.carbon.identity.scim2.common.DAO.GroupDAO) IdentitySCIMException(org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)

Example 12 with GroupDAO

use of org.wso2.carbon.identity.scim2.common.DAO.GroupDAO in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMGroupHandler method addMandatoryAttributes.

/**
 * When adding a group through management console, we need to make it SCIM compatible, if SCIM
 * enabled in the UserStoreManager config, by adding the READONLY attributes added by Charon.
 *
 * @param groupName
 */
public void addMandatoryAttributes(String groupName) throws IdentitySCIMException {
    Map<String, String> attributes = new HashMap<>();
    String id = UUID.randomUUID().toString();
    attributes.put(SCIMConstants.CommonSchemaConstants.ID_URI, id);
    String createdDate = AttributeUtil.formatDateTime(Instant.now());
    attributes.put(SCIMConstants.CommonSchemaConstants.CREATED_URI, createdDate);
    attributes.put(SCIMConstants.CommonSchemaConstants.LAST_MODIFIED_URI, createdDate);
    attributes.put(SCIMConstants.CommonSchemaConstants.LOCATION_URI, SCIMCommonUtils.getSCIMGroupURL(id));
    GroupDAO groupDAO = new GroupDAO();
    groupDAO.addSCIMGroupAttributes(tenantId, groupName, attributes);
}
Also used : HashMap(java.util.HashMap) GroupDAO(org.wso2.carbon.identity.scim2.common.DAO.GroupDAO)

Example 13 with GroupDAO

use of org.wso2.carbon.identity.scim2.common.DAO.GroupDAO in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMGroupHandler method getGroupWithAttributes.

/**
 * Set the attributes retrieved from the Identity table, in the given group object.
 *
 * @param group
 * @return
 */
public Group getGroupWithAttributes(Group group, String groupName) throws IdentitySCIMException, CharonException, BadRequestException {
    GroupDAO groupDAO = new GroupDAO();
    Map<String, String> attributes = groupDAO.getSCIMGroupAttributes(tenantId, groupName);
    if (attributes.isEmpty()) {
        if (logger.isDebugEnabled()) {
            logger.debug("The group: " + groupName + ", is not a SCIM group. Skipping..");
        }
        return group;
    }
    for (Map.Entry<String, String> entry : attributes.entrySet()) {
        if (SCIMConstants.CommonSchemaConstants.ID_URI.equals(entry.getKey())) {
            group.setId(entry.getValue());
        } else if (SCIMConstants.CommonSchemaConstants.CREATED_URI.equals(entry.getKey())) {
            group.setCreatedDate(Date.from(AttributeUtil.parseDateTime(entry.getValue())));
        } else if (SCIMConstants.CommonSchemaConstants.LAST_MODIFIED_URI.equals(entry.getKey())) {
            group.setLastModified(Date.from(AttributeUtil.parseDateTime(entry.getValue())));
        } else if (SCIMConstants.CommonSchemaConstants.LOCATION_URI.equals(entry.getKey())) {
            group.setLocation(SCIMCommonUtils.getSCIMGroupURL(group.getId()));
        }
    }
    return group;
}
Also used : GroupDAO(org.wso2.carbon.identity.scim2.common.DAO.GroupDAO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with GroupDAO

use of org.wso2.carbon.identity.scim2.common.DAO.GroupDAO in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMGroupHandler method getGroupName.

/**
 * Get the group name by Id.
 *
 * @param id
 * @return
 */
public String getGroupName(String id) throws IdentitySCIMException {
    GroupDAO groupDAO = new GroupDAO();
    String roleName = groupDAO.getGroupNameById(tenantId, id);
    if (roleName == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Role doesn't exist with id: " + id);
        }
        return null;
    } else {
        return roleName;
    }
}
Also used : GroupDAO(org.wso2.carbon.identity.scim2.common.DAO.GroupDAO)

Aggregations

GroupDAO (org.wso2.carbon.identity.scim2.common.DAO.GroupDAO)12 IdentitySCIMException (org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)8 UserStoreException (org.wso2.carbon.user.core.UserStoreException)7 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)6 Group (org.wso2.carbon.user.core.common.Group)6 Map (java.util.Map)5 HashMap (java.util.HashMap)4 IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)2 GroupDAO (org.wso2.carbon.identity.role.mgt.core.dao.GroupDAO)2 AbstractMap (java.util.AbstractMap)1 ExpressionCondition (org.wso2.carbon.user.core.model.ExpressionCondition)1 OperationalCondition (org.wso2.carbon.user.core.model.OperationalCondition)1 CharonException (org.wso2.charon3.core.exceptions.CharonException)1