Search in sources :

Example 1 with UserBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo in project carbon-identity-framework by wso2.

the class RoleDAOTest method testDeleteUser.

@Test
public void testDeleteUser() throws Exception {
    try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
        Connection connection2 = DAOUtils.getConnection(DB_NAME);
        Connection connection3 = DAOUtils.getConnection(DB_NAME);
        Connection connection4 = DAOUtils.getConnection(DB_NAME);
        Connection connection5 = DAOUtils.getConnection(DB_NAME);
        Connection connection6 = DAOUtils.getConnection(DB_NAME);
        Connection connection7 = DAOUtils.getConnection(DB_NAME)) {
        roleDAO = spy(RoleMgtDAOFactory.getInstance().getRoleDAO());
        mockCacheClearing();
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection1);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection2);
        RoleBasicInfo role = addRole("role1");
        doReturn(true).when(roleDAO, "isExistingRoleName", anyString(), anyString());
        doCallRealMethod().when(roleDAO, "updateUserListOfRole", anyString(), anyCollection(), anyCollection(), anyString());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection3);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection4);
        mockStatic(IdentityUtil.class);
        when(IdentityUtil.getPrimaryDomainName()).thenReturn("PRIMARY");
        doReturn(userNamesList).when(roleDAO, "getUserNamesByIDs", eq(userIDsList), anyString());
        roleDAO.updateUserListOfRole(role.getId(), userIDsList, null, SAMPLE_TENANT_DOMAIN);
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection5);
        doReturn("user1").when(roleDAO, "getUserNameByID", anyString(), anyString());
        roleDAO.deleteUser("userID1", SAMPLE_TENANT_DOMAIN);
        userNamesList.remove("user1");
        mockRealmConfiguration();
        mockStatic(UserCoreUtil.class);
        when(UserCoreUtil.isEveryoneRole(anyString(), any(RealmConfiguration.class))).thenReturn(false);
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection6);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection7);
        doCallRealMethod().when(UserCoreUtil.class, "addDomainToName", anyString(), anyString());
        doReturn("userID1").when(roleDAO, "getUserIDByName", eq(userNamesList.get(0)), anyString());
        List<UserBasicInfo> users = roleDAO.getUserListOfRole(role.getId(), SAMPLE_TENANT_DOMAIN);
        assertEquals(getUserNamesList(users), userNamesList);
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserBasicInfo(org.wso2.carbon.identity.role.mgt.core.UserBasicInfo) Connection(java.sql.Connection) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with UserBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo in project identity-inbound-auth-oauth by wso2-extensions.

the class IdentityOauthEventHandler method handleEvent.

@Override
public void handleEvent(Event event) throws IdentityEventException {
    if (IdentityEventConstants.Event.POST_SET_USER_CLAIMS.equals(event.getEventName()) || IdentityEventConstants.Event.POST_SET_USER_CLAIM.equals(event.getEventName())) {
        String username = (String) event.getEventProperties().get(IdentityEventConstants.EventProperty.USER_NAME);
        UserStoreManager userStoreManager = (UserStoreManager) event.getEventProperties().get(IdentityEventConstants.EventProperty.USER_STORE_MANAGER);
        try {
            revokeTokensOfLockedUser(username, userStoreManager);
            revokeTokensOfDisabledUser(username, userStoreManager);
            OAuthUtil.removeUserClaimsFromCache(username, userStoreManager);
        } catch (UserStoreException e) {
            String errorMsg = "Error occurred while revoking  access token for User : " + username;
            log.error(errorMsg, e);
            throw new IdentityEventException(errorMsg);
        }
    } else if (IdentityEventConstants.Event.POST_UPDATE_USER_LIST_OF_ROLE_EVENT.equals(event.getEventName())) {
        Object userIdList = event.getEventProperties().get(IdentityEventConstants.EventProperty.DELETE_USER_ID_LIST);
        List<String> deletedUserIDList;
        if (userIdList instanceof List<?>) {
            deletedUserIDList = (List<String>) userIdList;
            terminateSession(deletedUserIDList);
        }
    } else if (IdentityEventConstants.Event.PRE_DELETE_ROLE_EVENT.equals(event.getEventName()) || IdentityEventConstants.Event.POST_SET_PERMISSIONS_FOR_ROLE_EVENT.equals(event.getEventName())) {
        String roleId = (String) event.getEventProperties().get(IdentityEventConstants.EventProperty.ROLE_ID);
        String tenantDomain = (String) event.getEventProperties().get(IdentityEventConstants.EventProperty.TENANT_DOMAIN);
        try {
            List<UserBasicInfo> userList = roleDAO.getRole(roleId, tenantDomain).getUsers();
            List<String> userIdList = new ArrayList<>();
            if (userList != null) {
                for (UserBasicInfo userBasicInfo : userList) {
                    userIdList.add(userBasicInfo.getId());
                }
                terminateSession(userIdList);
            }
        } catch (IdentityRoleManagementException e) {
            String errorMsg = "Invaild role id :" + roleId + "in tenant domain " + tenantDomain;
            throw new IdentityEventException(errorMsg);
        }
    }
}
Also used : UserBasicInfo(org.wso2.carbon.identity.role.mgt.core.UserBasicInfo) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) IdentityRoleManagementException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)

Example 3 with UserBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManagerTest method getDummyIdentityRole.

private org.wso2.carbon.identity.role.mgt.core.Role getDummyIdentityRole(String roleId, String roleName, String domain, String tenantDomain) {
    org.wso2.carbon.identity.role.mgt.core.Role role = new org.wso2.carbon.identity.role.mgt.core.Role();
    role.setId(roleId);
    role.setPermissions(Arrays.asList("permission", "usermgt"));
    role.setName(roleName);
    role.setDomain(domain);
    role.setTenantDomain(tenantDomain);
    role.setUsers(Arrays.asList(new UserBasicInfo("7646b885-4207-4ca0-bc65-5df82272b6d1", "username1"), new UserBasicInfo("7646b885-4207-4ca0-bc65-5df82272b6d2", "username2")));
    GroupBasicInfo groupBasicInfo1 = new GroupBasicInfo();
    groupBasicInfo1.setName("groupName1");
    groupBasicInfo1.setId("26d3a726-9c00-4f4c-8a4e-f5e310138081");
    GroupBasicInfo groupBasicInfo2 = new GroupBasicInfo();
    groupBasicInfo2.setName("groupName2");
    groupBasicInfo2.setId("26d3a726-9c00-4f4c-8a4e-f5e310138082");
    role.setGroups(Arrays.asList(groupBasicInfo1, groupBasicInfo2));
    return role;
}
Also used : Role(org.wso2.charon3.core.objects.Role) UserBasicInfo(org.wso2.carbon.identity.role.mgt.core.UserBasicInfo) GroupBasicInfo(org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo)

Example 4 with UserBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMRoleManager method getRole.

@Override
public Role getRole(String roleID, Map<String, Boolean> requiredAttributes) throws BadRequestException, CharonException, NotFoundException {
    try {
        org.wso2.carbon.identity.role.mgt.core.Role role = roleManagementService.getRole(roleID, tenantDomain);
        Role scimRole = new Role();
        scimRole.setId(role.getId());
        scimRole.setDisplayName(role.getName());
        String locationURI = SCIMCommonUtils.getSCIMRoleURL(role.getId());
        scimRole.setLocation(locationURI);
        scimRole.setPermissions(role.getPermissions());
        scimRole.setSchemas();
        if (systemRoles.contains(role.getName())) {
            scimRole.setSystemRole(true);
        }
        if (CollectionUtils.isNotEmpty(role.getUsers())) {
            for (UserBasicInfo userInfo : role.getUsers()) {
                String userLocationURI = SCIMCommonUtils.getSCIMUserURL(userInfo.getId());
                User user = new User();
                user.setUserName(userInfo.getName());
                user.setId(userInfo.getId());
                user.setLocation(userLocationURI);
                scimRole.setUser(user);
            }
        }
        if (CollectionUtils.isNotEmpty(role.getGroups())) {
            for (GroupBasicInfo groupInfo : role.getGroups()) {
                String groupLocationURI = SCIMCommonUtils.getSCIMGroupURL(groupInfo.getId());
                Group group = new Group();
                group.setDisplayName(groupInfo.getName());
                group.setId(groupInfo.getId());
                group.setLocation(groupLocationURI);
                scimRole.setGroup(group);
            }
        }
        return scimRole;
    } catch (IdentityRoleManagementException e) {
        if (StringUtils.equals(ROLE_NOT_FOUND.getCode(), e.getErrorCode())) {
            throw new NotFoundException(e.getMessage());
        }
        throw new CharonException(String.format("Error occurred while getting the role: %s", roleID), e);
    }
}
Also used : Group(org.wso2.charon3.core.objects.Group) User(org.wso2.charon3.core.objects.User) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) Role(org.wso2.charon3.core.objects.Role) UserBasicInfo(org.wso2.carbon.identity.role.mgt.core.UserBasicInfo) GroupBasicInfo(org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo) CharonException(org.wso2.charon3.core.exceptions.CharonException) IdentityRoleManagementException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)

Example 5 with UserBasicInfo

use of org.wso2.carbon.identity.role.mgt.core.UserBasicInfo in project carbon-identity-framework by wso2.

the class RoleDAOTest method testGetUserListOfRole.

@Test
public void testGetUserListOfRole() throws Exception {
    try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
        Connection connection2 = DAOUtils.getConnection(DB_NAME);
        Connection connection3 = DAOUtils.getConnection(DB_NAME);
        Connection connection4 = DAOUtils.getConnection(DB_NAME);
        Connection connection5 = DAOUtils.getConnection(DB_NAME);
        Connection connection6 = DAOUtils.getConnection(DB_NAME)) {
        roleDAO = spy(RoleMgtDAOFactory.getInstance().getRoleDAO());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection1);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection2);
        RoleBasicInfo role = addRole("role1");
        doReturn(true).when(roleDAO, "isExistingRoleName", anyString(), anyString());
        doCallRealMethod().when(roleDAO, "updateUserListOfRole", anyString(), anyCollection(), anyCollection(), anyString());
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection3);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection4);
        mockStatic(IdentityUtil.class);
        when(IdentityUtil.getPrimaryDomainName()).thenReturn("PRIMARY");
        doReturn(userNamesList).when(roleDAO, "getUserNamesByIDs", eq(userIDsList), anyString());
        roleDAO.updateUserListOfRole(role.getId(), userIDsList, null, SAMPLE_TENANT_DOMAIN);
        mockRealmConfiguration();
        mockStatic(UserCoreUtil.class);
        when(UserCoreUtil.isEveryoneRole(anyString(), any(RealmConfiguration.class))).thenReturn(false);
        when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection5);
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection6);
        doCallRealMethod().when(UserCoreUtil.class, "addDomainToName", anyString(), anyString());
        doReturn("userID1").when(roleDAO, "getUserIDByName", eq(userNamesList.get(0)), anyString());
        doReturn("userID2").when(roleDAO, "getUserIDByName", eq(userNamesList.get(1)), anyString());
        List<UserBasicInfo> users = roleDAO.getUserListOfRole(role.getId(), SAMPLE_TENANT_DOMAIN);
        assertEquals(getUserNamesList(users), userNamesList);
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserBasicInfo(org.wso2.carbon.identity.role.mgt.core.UserBasicInfo) Connection(java.sql.Connection) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

UserBasicInfo (org.wso2.carbon.identity.role.mgt.core.UserBasicInfo)7 Connection (java.sql.Connection)3 ArrayList (java.util.ArrayList)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Test (org.testng.annotations.Test)2 GroupBasicInfo (org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo)2 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)2 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)2 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)2 Role (org.wso2.charon3.core.objects.Role)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)1 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)1 IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)1 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)1 RoleManagementEventPublisherProxy (org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)1 UserRealm (org.wso2.carbon.user.api.UserRealm)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1