Search in sources :

Example 6 with SCIMGroupHandler

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

the class SCIMUserManager method getRoleNamesForGroupsEndpoint.

/**
 * Get role names according to the given domain. If the domain is not specified, roles of all the user
 * stores will be returned.
 *
 * @param domainName Domain name
 * @return Roles List
 * @throws UserStoreException
 * @throws IdentitySCIMException
 */
private Set<String> getRoleNamesForGroupsEndpoint(String domainName) throws UserStoreException, IdentitySCIMException {
    SCIMGroupHandler groupHandler = new SCIMGroupHandler(carbonUM.getTenantId());
    if (StringUtils.isEmpty(domainName)) {
        Set<String> roleNames = new HashSet<>(Arrays.asList(carbonUM.getRoleNames()));
        Set<String> scimRoles = groupHandler.listSCIMRoles();
        List<String> scimDisabledHybridRoles = getSCIMDisabledHybridRoleList(roleNames, scimRoles);
        if (!scimDisabledHybridRoles.isEmpty()) {
            createSCIMAttributesForSCIMDisabledHybridRoles(scimDisabledHybridRoles);
            roleNames.addAll(scimDisabledHybridRoles);
        }
        return roleNames;
    } else {
        // If the domain is specified create a attribute value with the domain name.
        String searchValue = domainName + CarbonConstants.DOMAIN_SEPARATOR + SCIMCommonConstants.ANY;
        List<String> roleList;
        // Retrieve roles using the above search value.
        if (isInternalOrApplicationGroup(domainName)) {
            // Support for hybrid roles listing with domain parameter. ex: domain=Application.
            roleList = filterHybridRoles(domainName, searchValue);
        } else {
            // Retrieve roles using the above attribute value.
            roleList = Arrays.asList(((AbstractUserStoreManager) carbonUM).getRoleNames(searchValue, MAX_ITEM_LIMIT_UNLIMITED, true, true, true));
        }
        Set<String> roleNames = new HashSet<>(roleList);
        Set<String> scimRoles = groupHandler.listSCIMRoles();
        List<String> scimDisabledHybridRoles = getSCIMDisabledHybridRoleList(roleNames, scimRoles);
        if (!scimDisabledHybridRoles.isEmpty()) {
            createSCIMAttributesForSCIMDisabledHybridRoles(scimDisabledHybridRoles);
            roleNames.addAll(scimDisabledHybridRoles);
        }
        return roleNames;
    }
}
Also used : AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) SCIMGroupHandler(org.wso2.carbon.identity.scim2.common.group.SCIMGroupHandler) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 7 with SCIMGroupHandler

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

the class SCIMUserManager method checkForSCIMDisabledHybridRoles.

/**
 * Check for hybrid roles created while SCIM is disabled and create SCIM attributes for them.
 *
 * @param roles Role list.
 * @throws CharonException {@link CharonException}.
 */
private void checkForSCIMDisabledHybridRoles(List<String> roles) throws CharonException {
    try {
        SCIMGroupHandler groupHandler = new SCIMGroupHandler(carbonUM.getTenantId());
        Set<String> scimRoles = groupHandler.listSCIMRoles();
        List<String> scimDisabledHybridRoles = getSCIMDisabledHybridRoleList(new HashSet<>(roles), scimRoles);
        if (!scimDisabledHybridRoles.isEmpty()) {
            createSCIMAttributesForSCIMDisabledHybridRoles(scimDisabledHybridRoles);
        }
    } catch (org.wso2.carbon.user.core.UserStoreException e) {
        throw resolveError(e, "Error in retrieving SCIM Group information from database.");
    } catch (IdentitySCIMException e) {
        throw new CharonException("Error in retrieving SCIM Group information from database.", e);
    }
}
Also used : CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMGroupHandler(org.wso2.carbon.identity.scim2.common.group.SCIMGroupHandler) IdentitySCIMException(org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)

Example 8 with SCIMGroupHandler

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

the class SCIMUserManager method deleteGroup.

@Override
public void deleteGroup(String groupId) throws NotFoundException, CharonException {
    if (log.isDebugEnabled()) {
        log.debug("Deleting group: " + groupId);
    }
    try {
        // Set thread local property to signal the downstream SCIMUserOperationListener
        // about the provisioning route.
        SCIMCommonUtils.setThreadLocalIsManagedThroughSCIMEP(true);
        // Get group name by id.
        SCIMGroupHandler groupHandler = new SCIMGroupHandler(carbonUM.getTenantId());
        String groupName = groupHandler.getGroupName(groupId);
        if (groupName != null) {
            String userStoreDomainFromSP = null;
            try {
                userStoreDomainFromSP = getUserStoreDomainFromSP();
            } catch (IdentityApplicationManagementException e) {
                throw new CharonException("Error retrieving User Store name. ", e);
            }
            if (userStoreDomainFromSP != null && !(userStoreDomainFromSP.equalsIgnoreCase(IdentityUtil.extractDomainFromName(groupName)))) {
                throw new CharonException("Group :" + groupName + "is not belong to user store " + userStoreDomainFromSP + "Hence group updating fail");
            }
            String userStoreDomainName = IdentityUtil.extractDomainFromName(groupName);
            if (!isInternalOrApplicationGroup(userStoreDomainName) && StringUtils.isNotBlank(userStoreDomainName) && !isSCIMEnabled(userStoreDomainName)) {
                throw new CharonException("Cannot delete group: " + groupName + " through scim from user store: " + userStoreDomainName + ". SCIM is not enabled for user store: " + userStoreDomainName);
            }
            // delete group in carbon UM
            carbonUM.deleteRole(groupName);
            // we do not update Identity_SCIM DB here since it is updated in SCIMUserOperationListener's methods.
            if (log.isDebugEnabled()) {
                log.debug("Group: " + groupName + " is deleted through SCIM.");
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Group with SCIM id: " + groupId + " doesn't exist in the system.");
            }
            throw new NotFoundException();
        }
    } catch (UserStoreException e) {
        throw resolveError(e, "Error occurred while deleting group " + groupId);
    } catch (IdentitySCIMException e) {
        throw new CharonException("Error occurred while deleting group " + groupId, e);
    }
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) SCIMUserStoreException(org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMGroupHandler(org.wso2.carbon.identity.scim2.common.group.SCIMGroupHandler) IdentitySCIMException(org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)

Example 9 with SCIMGroupHandler

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

the class SCIMUserManager method getGroupOnlyWithMetaAttributes.

/**
 * Get group with only meta attributes.
 *
 * @param groupName
 * @return
 * @throws CharonException
 * @throws IdentitySCIMException
 * @throws org.wso2.carbon.user.core.UserStoreException
 */
private Group getGroupOnlyWithMetaAttributes(String groupName) throws CharonException, IdentitySCIMException, org.wso2.carbon.user.core.UserStoreException, BadRequestException {
    // get other group attributes and set.
    Group group = new Group();
    group.setDisplayName(groupName);
    SCIMGroupHandler groupHandler = new SCIMGroupHandler(carbonUM.getTenantId());
    return groupHandler.getGroupWithAttributes(group, groupName);
}
Also used : Group(org.wso2.charon3.core.objects.Group) SCIMGroupHandler(org.wso2.carbon.identity.scim2.common.group.SCIMGroupHandler)

Example 10 with SCIMGroupHandler

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

the class AdminAttributeUtilTest method testUpdateAdminGroup1.

@Test(expectedExceptions = IdentitySCIMException.class)
public void testUpdateAdminGroup1() throws Exception {
    String roleNameWithDomain = "TESTDOMAIN/admin";
    mockStatic(SCIMCommonComponentHolder.class);
    mockStatic(ClaimsMgtUtil.class);
    mockStatic(IdentityTenantUtil.class);
    mockStatic(UserCoreUtil.class);
    mockStatic(IdentityUtil.class);
    mockStatic(SCIMCommonUtils.class);
    when(SCIMCommonComponentHolder.getRealmService()).thenReturn(realmService);
    when(realmService.getTenantUserRealm(anyInt())).thenReturn(userRealm);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    when(userStoreManager.isSCIMEnabled()).thenReturn(true);
    when(userStoreManager.getTenantId()).thenReturn(1);
    when(userStoreManager.getRealmConfiguration()).thenReturn(realmConfiguration);
    when(realmConfiguration.getAdminRoleName()).thenReturn("admin");
    when(UserCoreUtil.getDomainName((RealmConfiguration) anyObject())).thenReturn("testDomain");
    when(IdentityUtil.getPrimaryDomainName()).thenReturn("TESTDOMAIN");
    when(UserCoreUtil.addDomainToName(anyString(), anyString())).thenReturn(roleNameWithDomain);
    when(SCIMCommonUtils.getGroupNameWithDomain(anyString())).thenReturn(roleNameWithDomain);
    whenNew(SCIMGroupHandler.class).withAnyArguments().thenReturn(scimGroupHandler);
    when(scimGroupHandler.isGroupExisting(anyString())).thenThrow(new IdentitySCIMException("testException"));
    adminAttributeUtil.updateAdminGroup(1);
    verify(scimGroupHandler.isGroupExisting(anyString()));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) IdentitySCIMException(org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SCIMGroupHandler (org.wso2.carbon.identity.scim2.common.group.SCIMGroupHandler)10 IdentitySCIMException (org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Test (org.testng.annotations.Test)5 Group (org.wso2.charon3.core.objects.Group)5 ResultSet (java.sql.ResultSet)4 Date (java.util.Date)4 Matchers.anyString (org.mockito.Matchers.anyString)4 UserStoreException (org.wso2.carbon.user.core.UserStoreException)4 CharonException (org.wso2.charon3.core.exceptions.CharonException)3 HashMap (java.util.HashMap)2 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)2 SCIMUserStoreException (org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreException)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)1