Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AuthorizationService #187

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/psama/psama.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# after initial login.
APPLICATION_CLIENT_SECRET=
APPLICATION_CLIENT_SECRET_IS_BASE_64=false
STACK_SPECIFIC_APPLICATION_ID=

# Fence IDP Configuration
FENCE_IDP_PROVIDER_IS_ENABLED=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,15 @@ public User createOpenAccessUser(Role openAccessRole) {
// Save the user to get a UUID
user = save(user);
user.setSubject("open_access|" + user.getUuid().toString());
if (openAccessRole != null) {
user.setRoles(Set.of(openAccessRole));
} else {
logger.error("createOpenAccessUser() openAccessRole is null");

if (user.getRoles() == null) {
user.setRoles(new HashSet<>());
}

if (openAccessRole != null) {
user.getRoles().add(openAccessRole);
}

user.setEmail(user.getUuid() + "@open_access.com");
user = save(user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public AuthorizationService(AccessRuleService accessRuleService, @Value("${stric
*/
public boolean isAuthorized(Application application, Object requestBody, User user) {
// create timer
long startTime = System.currentTimeMillis();
String applicationName = application.getName();
String resourceId = "null";
String targetService = "null";
Expand All @@ -98,7 +97,6 @@ public boolean isAuthorized(Application application, Object requestBody, User us
return true;
}

long parseTimeFrame = System.currentTimeMillis();
try {
Map requestBodyMap = (Map) requestBody;
Map queryMap = (Map) requestBodyMap.get("query");
Expand All @@ -122,10 +120,14 @@ public boolean isAuthorized(Application application, Object requestBody, User us
logger.debug("isAuthorized() Stack Trace: ", e1);
return false;
}
logger.info("Parse timeframe {} ms", (System.currentTimeMillis() - parseTimeFrame));

Set<AccessRule> accessRules;
String label = user.getConnection().getLabel();
String label = "";
if (user.getConnection() != null) {
// Open Access doesn't currently use a connection
label = user.getConnection().getLabel();
}

if (!this.strictConnections.contains(label)) {
Set<Privilege> privileges = user.getPrivilegesByApplication(application);
if (privileges == null || privileges.isEmpty()) {
Expand Down Expand Up @@ -174,7 +176,6 @@ public boolean isAuthorized(Application application, Object requestBody, User us
.map(ar -> (ar.getMergedName().isEmpty() ? ar.getName() : ar.getMergedName()))
.collect(Collectors.joining(", ")) + "]");

logger.info("Login time: {}ms", System.currentTimeMillis() - startTime);
return result;
}

Expand Down
Loading