Skip to content

Commit

Permalink
Fix get scope id using scope name.
Browse files Browse the repository at this point in the history
  • Loading branch information
dushaniw committed May 5, 2020
1 parent 95f3b97 commit 9dde5ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* This class represent the ApiMgtDAO.
Expand Down Expand Up @@ -15191,7 +15190,7 @@ public void addResourceScopes(API api, Set<URITemplate> uriTemplates, String ten
for (URITemplate uriTemplate : uriTemplates) {
String resourceKey = APIUtil.getResourceKey(api, uriTemplate);
for (Scope scope : uriTemplate.retrieveAllScopes()) {
int scopeId = getResourceScopeIdByName(scope.getKey(), tenantId, connection);
int scopeId = getOAuthScopeIdByName(scope.getKey(), tenantId, connection);
addScopeStmt.setString(1, resourceKey);
addScopeStmt.setInt(2, scopeId);
addScopeStmt.setInt(3, tenantId);
Expand All @@ -15212,12 +15211,12 @@ public void addResourceScopes(API api, Set<URITemplate> uriTemplates, String ten
/**
* Get resource scope Id by scope name. KM operation. //TODO: remove after KM seperation
*/
public int getResourceScopeIdByName(String scopeName, int tenantId, Connection connection) throws SQLException,
public int getOAuthScopeIdByName(String scopeName, int tenantId, Connection connection) throws SQLException,
APIManagementException {

int scopeId = -1;
try (PreparedStatement getScopeIdStmt =
connection.prepareStatement(SQLConstants.GET_OAUTH2_RESOURCE_SCOPE_ID_BY_NAME_SQL)) {
connection.prepareStatement(SQLConstants.GET_OAUTH2_SCOPE_ID_BY_NAME_SQL)) {
getScopeIdStmt.setString(1, scopeName);
getScopeIdStmt.setInt(2, tenantId);
try (ResultSet rs = getScopeIdStmt.executeQuery()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3520,12 +3520,12 @@ public static class KeyMgtConstants {
public static final String
REMOVE_OAUTH2_RESOURCE_SCOPE_SQL =
" DELETE FROM IDN_OAUTH2_RESOURCE_SCOPE WHERE SCOPE_ID IN "
+ "(SELECT IS.SCOPE_ID FROM IDN_OAUTH2_SCOPE IS WHERE IS.SCOPE_NAME = ? AND IS.TENANT_ID = ?) "
+ "(SELECT SCOPE_ID FROM IDN_OAUTH2_SCOPE WHERE NAME = ? AND TENANT_ID = ?) "
+ "AND RESOURCE_PATH = ?";

public static final String ADD_OAUTH2_RESOURCE_SCOPE_SQL =
"INSERT INTO IDN_OAUTH2_RESOURCE_SCOPE (RESOURCE_PATH, SCOPE_ID, TENANT_ID) VALUES (?,?,?)";

public static final String GET_OAUTH2_RESOURCE_SCOPE_ID_BY_NAME_SQL =
"SELECT SCOPE_ID FROM IDN_OAUTH2_RESOURCE_SCOPE WHERE SCOPE_NAME = ? AND TENANT_ID = ?";
public static final String GET_OAUTH2_SCOPE_ID_BY_NAME_SQL =
"SELECT SCOPE_ID FROM IDN_OAUTH2_SCOPE WHERE NAME = ? AND TENANT_ID = ?";
}

0 comments on commit 9dde5ee

Please sign in to comment.