use of org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class RoleDAOImpl method deleteGroup.
@Override
public void deleteGroup(String groupID, String tenantDomain) throws IdentityRoleManagementException {
String groupName = getGroupNameByID(groupID, 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_GROUP_SQL, RoleTableColumns.UM_ID)) {
// Add domain if not set.
groupName = UserCoreUtil.addDomainToName(groupName, primaryDomainName);
// Get domain from name.
String domainName = UserCoreUtil.extractDomainFromName(groupName);
if (domainName != null) {
domainName = domainName.toUpperCase(Locale.ENGLISH);
}
String nameWithoutDomain = UserCoreUtil.removeDomainFromName(groupName);
statement.setString(RoleTableColumns.UM_GROUP_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 group: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, groupName, tenantDomain), e);
}
} catch (SQLException e) {
String errorMessage = "Error while removing the group: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, groupName, tenantDomain), e);
}
clearUserRolesCacheByTenant(tenantId);
}
use of org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class RoleDAOImpl method deleteSCIMRole.
protected void deleteSCIMRole(String roleName, String tenantDomain) throws IdentityRoleManagementException {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
// Append internal domain in order to maintain the backward compatibility.
roleName = appendInternalDomain(roleName);
if (log.isDebugEnabled()) {
log.debug("Deleting the role: " + roleName + " for the role: " + roleName + " in the tenantDomain: " + tenantDomain);
}
try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, DELETE_SCIM_ROLE_SQL)) {
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 deleting the the role: %s for the role: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, roleName, tenantDomain), e);
}
} catch (SQLException e) {
String errorMessage = "Error while deleting the the role: %s for the role: %s in the tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, roleName, tenantDomain), e);
}
}
use of org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class RoleDAOImpl method buildRolesList.
private List<RoleBasicInfo> buildRolesList(NamedPreparedStatement statement, String tenantDomain) throws SQLException, IdentityRoleManagementException {
List<RoleBasicInfo> roles = new ArrayList<>();
List<String> roleNames = new ArrayList<>();
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
String roleName = resultSet.getString(1);
roleNames.add(appendInternalDomain(roleName));
}
}
Map<String, String> roleNamesToIDs = getRoleIDsByNames(roleNames, tenantDomain);
// Filter scim disabled roles.
roleNames.removeAll(new ArrayList<>(roleNamesToIDs.keySet()));
// Add roleIDs for scim disabled roles.
for (String roleName : roleNames) {
roleNamesToIDs.put(roleName, addRoleID(roleName, tenantDomain));
}
roleNamesToIDs.forEach((roleName, roleID) -> roles.add(new RoleBasicInfo(roleID, removeInternalDomain(roleName))));
return roles;
}
use of org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class GroupDAOImpl method getGroupIDByName.
@Override
public String getGroupIDByName(String name, String tenantDomain) throws IdentityRoleManagementException {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
String groupID = null;
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, GET_GROUP_ID_BY_NAME_SQL)) {
statement.setInt(RoleConstants.RoleTableColumns.TENANT_ID, tenantId);
statement.setString(RoleConstants.RoleTableColumns.ROLE_NAME, name);
statement.setString(RoleConstants.RoleTableColumns.ATTR_NAME, RoleConstants.ID_URI);
int count = 0;
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
// Handle multiple matching groups.
count++;
if (count > 1) {
String errorMessage = "Invalid scenario. Multiple groups found for the given group name: " + name + " " + "and tenantDomain: " + tenantDomain;
throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
}
groupID = resultSet.getString(1);
}
}
}
} catch (SQLException e) {
String errorMessage = "Error while resolving the group ID for the given group name: " + name + " and tenantDomain: " + tenantDomain;
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), errorMessage, e);
}
return groupID;
}
use of org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class GroupDAOImpl method batchProcessGroupNames.
private Map<String, String> batchProcessGroupNames(List<String> names, String tenantDomain, Connection connection) throws SQLException, IdentityRoleManagementException {
Map<String, String> groupNamesToIDs = new HashMap<>();
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
String groupID;
for (String name : names) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, GET_GROUP_ID_BY_NAME_SQL)) {
statement.setInt(RoleConstants.RoleTableColumns.TENANT_ID, tenantId);
statement.setString(RoleConstants.RoleTableColumns.ROLE_NAME, name);
statement.setString(RoleConstants.RoleTableColumns.ATTR_NAME, RoleConstants.ID_URI);
int count = 0;
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
// Handle multiple matching groups.
count++;
if (count > 1) {
String errorMessage = "Invalid scenario. Multiple groups found for the given group name: " + name + " " + "and tenantDomain: " + tenantDomain;
throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
}
groupID = resultSet.getString(1);
groupNamesToIDs.put(name, groupID);
}
}
}
}
return groupNamesToIDs;
}
Aggregations