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);
}
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);
}
}
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);
}
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;
}
Aggregations