use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project carbon-identity-framework by wso2.
the class RoleDAOImpl method addRoleID.
protected String addRoleID(String roleName, String tenantDomain) throws IdentityRoleManagementException {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
String id = UUID.randomUUID().toString();
// Append internal domain in order to maintain the backward compatibility.
roleName = appendInternalDomain(roleName);
if (log.isDebugEnabled()) {
log.debug("Adding the roleID: " + id + " for the role: " + roleName + " in the tenantDomain: " + tenantDomain);
}
try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, ADD_SCIM_ROLE_ID_SQL)) {
statement.setInt(RoleTableColumns.TENANT_ID, tenantId);
statement.setString(RoleTableColumns.ROLE_NAME, roleName);
statement.setString(RoleTableColumns.ATTR_NAME, RoleConstants.ID_URI);
statement.setString(RoleTableColumns.ATTR_VALUE, id);
statement.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
String errorMessage = "Error while adding the the roleID: %s for the role: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, id, roleName, tenantDomain), e);
}
} catch (SQLException e) {
String errorMessage = "Error while adding the the roleID: %s for the role: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, id, roleName, tenantDomain), e);
}
return id;
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project carbon-identity-framework by wso2.
the class RoleDAOImpl method getRole.
@Override
public Role getRole(String roleID, String tenantDomain) throws IdentityRoleManagementException {
Role role = new Role();
String roleName = getRoleNameByID(roleID, tenantDomain);
role.setId(roleID);
role.setName(roleName);
role.setTenantDomain(tenantDomain);
role.setUsers(getUserListOfRole(roleID, tenantDomain));
role.setGroups(getGroupListOfRole(roleID, tenantDomain));
role.setPermissions(getPermissionListOfRole(roleID, tenantDomain));
return role;
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project carbon-identity-framework by wso2.
the class RoleDAOImpl method getGroupListOfRole.
@Override
public List<GroupBasicInfo> getGroupListOfRole(String roleID, String tenantDomain) throws IdentityRoleManagementException {
if (!isExistingRoleID(roleID, tenantDomain)) {
throw new IdentityRoleManagementClientException(ROLE_NOT_FOUND.getCode(), "Role id: " + roleID + " does not exist in the system.");
}
String roleName = getRoleNameByID(roleID, tenantDomain);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
List<GroupBasicInfo> groupList = new ArrayList<>();
List<String> groupNames = new ArrayList<>();
List<String> disabledDomainName = getDisabledDomainNames();
String primaryDomainName = IdentityUtil.getPrimaryDomainName();
if (primaryDomainName != null) {
primaryDomainName = primaryDomainName.toUpperCase(Locale.ENGLISH);
}
try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, GET_GROUP_LIST_OF_ROLE_SQL, RoleTableColumns.UM_ID)) {
statement.setString(RoleTableColumns.UM_ROLE_NAME, roleName);
statement.setInt(RoleTableColumns.UM_TENANT_ID, tenantId);
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
String name = resultSet.getString(1);
String domain = resultSet.getString(2);
if (!disabledDomainName.contains(domain)) {
if (!StringUtils.equals(primaryDomainName, domain)) {
name = UserCoreUtil.addDomainToName(name, domain);
} else {
name = primaryDomainName + UserCoreConstants.DOMAIN_SEPARATOR + name;
}
groupNames.add(name);
}
}
}
}
} catch (SQLException e) {
String errorMessage = "Error while while getting the group list of role for role name: %s in the " + "tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, tenantDomain), e);
}
Map<String, String> groupNamesToIDs = getGroupIDsByNames(groupNames, tenantDomain);
groupNamesToIDs.forEach((groupName, groupID) -> groupList.add(new GroupBasicInfo(groupID, groupName)));
return groupList;
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project carbon-identity-framework by wso2.
the class RoleDAOImpl method isExistingRoleName.
@Override
public boolean isExistingRoleName(String roleName, String tenantDomain) throws IdentityRoleManagementException {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
boolean isExist = false;
try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, IS_ROLE_EXIST_SQL, RoleTableColumns.UM_ID)) {
statement.setString(RoleTableColumns.UM_ROLE_NAME, removeInternalDomain(roleName));
statement.setInt(RoleTableColumns.UM_TENANT_ID, tenantId);
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 name: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, tenantDomain), e);
}
if (log.isDebugEnabled()) {
log.debug("Is roleName: " + roleName + " Exist: " + isExist + " in the tenantDomain: " + tenantDomain);
}
return isExist;
}
use of org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementException in project carbon-identity-framework by wso2.
the class RoleDAOImpl method updateSCIMRoleName.
protected void updateSCIMRoleName(String roleName, String newRoleName, String tenantDomain) throws IdentityRoleManagementException {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
// Append internal domain in order to maintain the backward compatibility.
roleName = appendInternalDomain(roleName);
newRoleName = appendInternalDomain(newRoleName);
try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, UPDATE_SCIM_ROLE_NAME_SQL)) {
statement.setString(RoleTableColumns.NEW_ROLE_NAME, newRoleName);
statement.setInt(RoleTableColumns.TENANT_ID, tenantId);
statement.setString(RoleTableColumns.ROLE_NAME, roleName);
statement.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
String errorMessage = "Error while updating the the roleName: %s in the tenantDomain: " + "%s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, tenantDomain), e);
}
} catch (SQLException e) {
String errorMessage = "Error while updating the the roleName: %s in the tenantDomain: " + "%s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, tenantDomain), e);
}
}
Aggregations