-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: manage partners endpoints authorizations
- Loading branch information
Showing
12 changed files
with
56 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...api-tenant/src/main/java/fr/dossierfacile/api/front/config/filter/RateLimitingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...src/main/java/fr/dossierfacile/api/front/config/filter/RateLimitingSupportMailFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
...src/main/java/fr/dossierfacile/api/front/security/CustomWebSecurityExpressionHandler.java
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
...nt/src/main/java/fr/dossierfacile/api/front/security/CustomWebSecurityExpressionRoot.java
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
...tenant/src/main/java/fr/dossierfacile/api/front/security/PartnerAuthorizationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fr.dossierfacile.api.front.security; | ||
|
||
import org.springframework.security.authorization.AuthorizationDecision; | ||
import org.springframework.security.authorization.AuthorizationManager; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.oauth2.jwt.Jwt; | ||
import org.springframework.security.web.access.intercept.RequestAuthorizationContext; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class PartnerAuthorizationManager implements AuthorizationManager<RequestAuthorizationContext> { | ||
private final String authScope; | ||
|
||
public PartnerAuthorizationManager(String scope) { | ||
this.authScope = "SCOPE_" + scope; | ||
} | ||
|
||
private boolean hasScope(Authentication authentication) { | ||
return authentication.getAuthorities().stream().anyMatch(a -> authScope.equals(a.getAuthority())); | ||
} | ||
|
||
private boolean isClient(Authentication authentication) { | ||
try { | ||
return ((Jwt) authentication.getPrincipal()).getClaimAsString("client_id") != null; | ||
} catch (Throwable t) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public AuthorizationDecision check(Supplier<Authentication> authentication, RequestAuthorizationContext object) { | ||
return new AuthorizationDecision(isClient(authentication.get()) && hasScope(authentication.get())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters