Search in sources :

Example 21 with IdentityRoleManagementServerException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException 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 22 with IdentityRoleManagementServerException

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

the class RoleDAOImpl method setPermissions.

private RoleBasicInfo setPermissions(String roleID, List<String> permissions, String tenantDomain, String roleName) throws IdentityRoleManagementServerException {
    roleName = appendInternalDomain(roleName);
    /*
        Permission list can be empty in case we want to remove the permissions.
        Therefore validating for NULL will be sufficient.
         */
    if (permissions == null) {
        if (log.isDebugEnabled()) {
            log.debug("Permissions list is null. Therefore not proceeding further.");
        }
        return new RoleBasicInfo(roleID, roleName);
    }
    try {
        getUserAdminProxy().setRoleUIPermission(roleName, permissions.toArray(new String[0]));
        clearUserRolesCacheByTenant(IdentityTenantUtil.getTenantId(tenantDomain));
        return new RoleBasicInfo(roleID, roleName);
    } catch (UserAdminException e) {
        throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), "An error occurred when setting permissions for the role: " + roleName, e);
    }
}
Also used : IdentityRoleManagementServerException(org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException) RoleBasicInfo(org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)

Example 23 with IdentityRoleManagementServerException

use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException 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)

Example 24 with IdentityRoleManagementServerException

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

the class RoleDAOImpl method isExistingRoleID.

@Override
public boolean isExistingRoleID(String roleID, String tenantDomain) throws IdentityRoleManagementException {
    boolean isExist = false;
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, IS_ROLE_ID_EXIST_SQL)) {
            statement.setInt(RoleConstants.RoleTableColumns.TENANT_ID, tenantId);
            statement.setString(RoleConstants.RoleTableColumns.ATTR_NAME, RoleConstants.ID_URI);
            statement.setString(RoleConstants.RoleTableColumns.ATTR_VALUE, roleID);
            try (ResultSet resultSet = statement.executeQuery()) {
                if (resultSet.next()) {
                    isExist = resultSet.getInt(1) > 0;
                }
            }
        }
    } catch (SQLException e) {
        String errorMessage = "Error while checking is existing role for role id: %s in the tenantDomain: %s";
        throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleID, tenantDomain), e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Is roleID: " + roleID + " Exist: " + isExist + " in the tenantDomain: " + tenantDomain);
    }
    return isExist;
}
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) ResultSet(java.sql.ResultSet)

Aggregations

IdentityRoleManagementServerException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementServerException)24 Connection (java.sql.Connection)19 SQLException (java.sql.SQLException)19 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)17 IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)13 ResultSet (java.sql.ResultSet)8 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)6 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 ArrayList (java.util.ArrayList)5 UserRealm (org.wso2.carbon.user.api.UserRealm)5 IdentityRoleManagementException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException)3 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)3 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)2 UserAdminException (org.wso2.carbon.user.mgt.common.UserAdminException)2 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 GroupBasicInfo (org.wso2.carbon.identity.role.mgt.core.GroupBasicInfo)1 UserBasicInfo (org.wso2.carbon.identity.role.mgt.core.UserBasicInfo)1 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)1