use of org.wso2.carbon.identity.oauth2.util.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method deleteApplicationByResourceId.
@Override
public void deleteApplicationByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Deleting Application with resourceId: " + resourceId + " in tenantDomain: " + tenantDomain);
}
try (Connection connection = IdentityDatabaseUtil.getDBConnection(true)) {
ServiceProvider application = getApplicationByResourceId(resourceId, tenantDomain);
if (application != null) {
// Delete the application certificate if there is any
deleteApplicationCertificate(connection, application);
try (NamedPreparedStatement deleteAppStatement = new NamedPreparedStatement(connection, REMOVE_APP_FROM_SP_APP_WITH_UUID)) {
deleteAppStatement.setString(ApplicationTableColumns.UUID, resourceId);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
deleteAppStatement.setInt(ApplicationTableColumns.TENANT_ID, tenantId);
deleteAppStatement.execute();
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException ex) {
IdentityDatabaseUtil.rollbackTransaction(connection);
String msg = "Error occurred while deleting application with resourceId: %s in tenantDomain: %s.";
throw new IdentityApplicationManagementException(String.format(msg, resourceId, tenantDomain), ex);
}
} else {
if (log.isDebugEnabled()) {
String msg = "Trying to delete a non-existing application with resourceId: %s in " + "tenantDomain: %s.";
log.debug(String.format(msg, resourceId, tenantDomain));
}
}
} catch (SQLException e) {
String msg = "Error occurred while deleting application with resourceId: %s in tenantDomain: %s.";
throw new IdentityApplicationManagementException(String.format(msg, resourceId, tenantDomain), e);
}
}
use of org.wso2.carbon.identity.oauth2.util.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getCountOfDiscoverableApplications.
@Override
public int getCountOfDiscoverableApplications(String filter, String tenantDomain) throws IdentityApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Getting count of discoverable applications matching filter: " + filter + " in tenantDomain: " + tenantDomain);
}
if (StringUtils.isBlank(filter) || "*".equals(filter)) {
return getCountOfDiscoverableApplications(tenantDomain);
}
int count = 0;
String filterResolvedForSQL = resolveSQLFilter(filter);
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, LOAD_DISCOVERABLE_APP_COUNT_BY_APP_NAME_AND_TENANT)) {
statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
statement.setString(ApplicationTableColumns.APP_NAME, filterResolvedForSQL);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
count = resultSet.getInt(1);
}
}
}
} catch (SQLException e) {
throw new IdentityApplicationManagementServerException("Error while getting count of discoverable " + "applications matching filter:" + filter + " in tenantDomain: " + tenantDomain, e);
}
return count;
}
use of org.wso2.carbon.identity.oauth2.util.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getApplicationBasicInfoByResourceId.
@Override
public ApplicationBasicInfo getApplicationBasicInfoByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Getting application basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain);
}
ApplicationBasicInfo applicationBasicInfo = null;
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, LOAD_APP_BY_TENANT_AND_UUID)) {
statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
statement.setString(ApplicationTableColumns.UUID, resourceId);
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
applicationBasicInfo = buildApplicationBasicInfo(resultSet);
}
}
}
} catch (SQLException e) {
String message = "Error while getting application basic information for resourceId: %s in " + "tenantDomain: %s";
throw new IdentityApplicationManagementException(String.format(message, resourceId, tenantDomain), e);
}
return applicationBasicInfo;
}
use of org.wso2.carbon.identity.oauth2.util.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class RoleDAOImpl method getUserListOfRole.
@Override
public List<UserBasicInfo> getUserListOfRole(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.");
}
List<UserBasicInfo> userList = new ArrayList<>();
String roleName = getRoleNameByID(roleID, tenantDomain);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
try {
UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
if (UserCoreUtil.isEveryoneRole(roleName, userRealm.getRealmConfiguration())) {
List<org.wso2.carbon.user.core.common.User> users = ((AbstractUserStoreManager) userRealm.getUserStoreManager()).listUsersWithID(RoleConstants.WILDCARD_CHARACTER, -1);
for (org.wso2.carbon.user.core.common.User user : users) {
userList.add(new UserBasicInfo(user.getUserID(), user.getDomainQualifiedUsername()));
}
}
} catch (UserStoreException e) {
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), "Error while getting the realmConfiguration.", e);
}
List<String> disabledDomainName = getDisabledDomainNames();
try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, GET_USER_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.isNotEmpty(domain)) {
name = UserCoreUtil.addDomainToName(name, domain);
}
userList.add(new UserBasicInfo(getUserIDByName(name, tenantDomain), name));
}
}
}
}
} catch (SQLException e) {
String errorMessage = "Error while while getting the user list of role for role name: %s in the " + "tenantDomain: %s";
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), String.format(errorMessage, roleName, tenantDomain), e);
}
return userList;
}
use of org.wso2.carbon.identity.oauth2.util.NamedPreparedStatement in project carbon-identity-framework by wso2.
the class RoleDAOImpl method batchProcessRoleNames.
private Map<String, String> batchProcessRoleNames(List<String> roleNames, String tenantDomain, Connection connection) throws SQLException, IdentityRoleManagementException {
Map<String, String> roleNamesToIDs = new HashMap<>();
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
String roleID;
for (String roleName : roleNames) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, GET_ROLE_ID_BY_NAME_SQL)) {
statement.setInt(RoleConstants.RoleTableColumns.TENANT_ID, tenantId);
statement.setString(RoleConstants.RoleTableColumns.ROLE_NAME, roleName);
statement.setString(RoleConstants.RoleTableColumns.ATTR_NAME, RoleConstants.ID_URI);
int count = 0;
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
// Handle multiple matching roles.
count++;
if (count > 1) {
String errorMessage = "Invalid scenario. Multiple roles found for the given role name: " + roleName + " and tenantDomain: " + tenantDomain;
throw new IdentityRoleManagementClientException(INVALID_REQUEST.getCode(), errorMessage);
}
roleID = resultSet.getString(1);
roleNamesToIDs.put(roleName, roleID);
}
}
}
}
return roleNamesToIDs;
}
Aggregations