Skip to content
Snippets Groups Projects
Commit f41d6230 authored by Alok Joshi's avatar Alok Joshi
Browse files

MR suggestions

parent a4627172
No related branches found
No related tags found
1 merge request!553Add cache for entitlements authorize mechanism
Pipeline #304739 failed
...@@ -94,8 +94,9 @@ public class AuthorizationFilter { ...@@ -94,8 +94,9 @@ public class AuthorizationFilter {
} }
private boolean authorizeWithCache(String[] requiredRoles, Groups groups) { private boolean authorizeWithCache(String[] requiredRoles, Groups groups) {
if(groups.any(requiredRoles)) if(groups.any(requiredRoles)) {
return true; return true;
}
return false; return false;
} }
......
// Copyright 2017-2024, SLB // Copyright 2017-2025, SLB
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
......
// Copyright 2017-2024, SLB // Copyright 2017-2025, SLB
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
...@@ -22,6 +22,10 @@ public class MathUtils { ...@@ -22,6 +22,10 @@ public class MathUtils {
*/ */
public static int generateRandomNumberBetweenBounds(int lower, int upper) { public static int generateRandomNumberBetweenBounds(int lower, int upper) {
Random random = new Random(); Random random = new Random();
return random.nextInt(upper - lower) + lower; if (upper > lower) {
return random.nextInt(upper - lower) + lower;
} else {
return random.nextInt(lower - upper) + upper;
}
} }
} }
...@@ -94,7 +94,6 @@ public class AuthorizationFilterTest { ...@@ -94,7 +94,6 @@ public class AuthorizationFilterTest {
final String USER_EMAIL = "test@test.com"; final String USER_EMAIL = "test@test.com";
AuthorizationResponse authorizationResponse = AuthorizationResponse.builder().user(USER_EMAIL).build(); AuthorizationResponse authorizationResponse = AuthorizationResponse.builder().user(USER_EMAIL).build();
when(this.authorizationService.authorizeAny(any(), eq(ROLE1), eq(ROLE2))).thenReturn(authorizationResponse); when(this.authorizationService.authorizeAny(any(), eq(ROLE1), eq(ROLE2))).thenReturn(authorizationResponse);
//when(this.groupVmCache.get("8Z2MjQ==")).thenReturn(null);
assertTrue(this.sut.hasAnyPermission(ROLE1, ROLE2)); assertTrue(this.sut.hasAnyPermission(ROLE1, ROLE2));
verify(headers).put(DpsHeaders.USER_EMAIL, "test@test.com"); verify(headers).put(DpsHeaders.USER_EMAIL, "test@test.com");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment