Search in sources :

Example 56 with IdentityRoleManagementException

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

the class RoleManagementServiceImpl method getPermissionListOfRole.

@Override
public List<String> getPermissionListOfRole(String roleID, String tenantDomain) throws IdentityRoleManagementException {
    RoleManagementEventPublisherProxy roleManagementEventPublisherProxy = RoleManagementEventPublisherProxy.getInstance();
    roleManagementEventPublisherProxy.publishPreGetPermissionListOfRole(roleID, tenantDomain);
    List<String> permissionListOfRole = roleDAO.getPermissionListOfRole(roleID, tenantDomain);
    roleManagementEventPublisherProxy.publishPostGetPermissionListOfRole(roleID, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug(String.format("%s get list of permissions of role of id : %s successfully.", getUser(tenantDomain), roleID));
    }
    return permissionListOfRole;
}
Also used : RoleManagementEventPublisherProxy(org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)

Example 57 with IdentityRoleManagementException

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

the class GroupIDResolver method getNameByID.

@Override
public String getNameByID(String id, String tenantDomain) throws IdentityRoleManagementException {
    GroupDAO groupDAO = RoleMgtDAOFactory.getInstance().getGroupDAO();
    String groupName = groupDAO.getGroupNameByID(id, tenantDomain);
    if (groupName == null) {
        String errorMessage = "A group doesn't exist with id: " + id + " in the tenantDomain: " + tenantDomain;
        throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
    }
    return groupName;
}
Also used : GroupDAO(org.wso2.carbon.identity.role.mgt.core.dao.GroupDAO) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)

Example 58 with IdentityRoleManagementException

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

the class GroupIDResolver method getIDByName.

@Override
public String getIDByName(String name, String tenantDomain) throws IdentityRoleManagementException {
    GroupDAO groupDAO = RoleMgtDAOFactory.getInstance().getGroupDAO();
    String groupName = groupDAO.getGroupIDByName(name, tenantDomain);
    if (groupName == null) {
        String errorMessage = "A group doesn't exist with name: " + name + " in the tenantDomain: " + tenantDomain;
        throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
    }
    return groupName;
}
Also used : GroupDAO(org.wso2.carbon.identity.role.mgt.core.dao.GroupDAO) IdentityRoleManagementClientException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)

Example 59 with IdentityRoleManagementException

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

the class RoleDAOImpl method getRoles.

@Override
public List<RoleBasicInfo> getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    limit = validateLimit(limit);
    offset = validateOffset(offset);
    validateAttributesForSorting(sortBy, sortOrder);
    List<RoleBasicInfo> roles;
    try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false)) {
        String databaseProductName = connection.getMetaData().getDatabaseProductName();
        try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, getDBTypeSpecificRolesRetrievalQuery(databaseProductName), RoleTableColumns.UM_ID)) {
            statement.setInt(RoleTableColumns.UM_TENANT_ID, tenantId);
            roles = processListRolesQuery(limit, offset, statement, tenantDomain);
        }
    } catch (SQLException e) {
        throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), "Error while listing roles in tenantDomain: " + tenantDomain, e);
    }
    return Collections.unmodifiableList(roles);
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) SQLException(java.sql.SQLException) IdentityRoleManagementServerException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException) Connection(java.sql.Connection) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)

Example 60 with IdentityRoleManagementException

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

the class RoleDAOImpl method deleteUser.

@Override
public void deleteUser(String userID, String tenantDomain) throws IdentityRoleManagementException {
    String userName = getUserNameByID(userID, tenantDomain);
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    String primaryDomainName = IdentityUtil.getPrimaryDomainName();
    if (primaryDomainName != null) {
        primaryDomainName = primaryDomainName.toUpperCase(Locale.ENGLISH);
    }
    try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(true)) {
        try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, DELETE_USER_SQL, RoleTableColumns.UM_ID)) {
            // Add domain if not set.
            userName = UserCoreUtil.addDomainToName(userName, primaryDomainName);
            // Get domain from name.
            String domainName = UserCoreUtil.extractDomainFromName(userName);
            if (domainName != null) {
                domainName = domainName.toUpperCase(Locale.ENGLISH);
            }
            String nameWithoutDomain = UserCoreUtil.removeDomainFromName(userName);
            statement.setString(RoleTableColumns.UM_USER_NAME, nameWithoutDomain);
            statement.setInt(RoleTableColumns.UM_TENANT_ID, tenantId);
            statement.setString(RoleTableColumns.UM_DOMAIN_NAME, domainName);
            statement.executeUpdate();
            IdentityDatabaseUtil.commitUserDBTransaction(connection);
        } catch (SQLException e) {
            IdentityDatabaseUtil.rollbackUserDBTransaction(connection);
            String errorMessage = "Error while removing the user: %s in the tenantDomain: %s";
            throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, userName, tenantDomain), e);
        }
    } catch (SQLException e) {
        String errorMessage = "Error while removing the user: %s in the tenantDomain: %s";
        throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, userName, tenantDomain), e);
    }
    clearUserRolesCache(userName, tenantId);
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) SQLException(java.sql.SQLException) IdentityRoleManagementServerException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException) Connection(java.sql.Connection)

Aggregations

IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)29 IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)23 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Test (org.testng.annotations.Test)20 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)20 Connection (java.sql.Connection)19 SQLException (java.sql.SQLException)19 Matchers.anyString (org.mockito.Matchers.anyString)14 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)14 Role (org.wso2.charon3.core.objects.Role)13 ResultSet (java.sql.ResultSet)12 RoleManagementEventPublisherProxy (org.wso2.carbon.identity.role.mgt.core.RoleManagementEventPublisherProxy)11 ArrayList (java.util.ArrayList)9 CharonException (org.wso2.charon3.core.exceptions.CharonException)8 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)8 Node (org.wso2.charon3.core.utils.codeutils.Node)8 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)8 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)6