55import access .manage .*;
66import access .model .EntityType ;
77import access .model .Environment ;
8- import access .model .Institution ;
98import access .model .User ;
10- import access .security .InstitutionAdmin ;
119import com .fasterxml .jackson .core .type .TypeReference ;
1210import com .fasterxml .jackson .databind .ObjectMapper ;
1311import lombok .SneakyThrows ;
2018import org .springframework .core .io .UrlResource ;
2119import org .springframework .http .MediaType ;
2220import org .springframework .http .ResponseEntity ;
23- import org .springframework .security .core .Authentication ;
24- import org .springframework .security .oauth2 .core .oidc .user .OidcUser ;
2521import org .springframework .web .bind .annotation .*;
2622
2723import java .net .URI ;
@@ -104,14 +100,13 @@ public ResponseEntity<List<Map<String, Object>>> identityProviders(@PathVariable
104100 @ GetMapping ("/policies" )
105101 @ SuppressWarnings ("unchecked" )
106102 public ResponseEntity <List <Map <String , Object >>> policies (User user ,
107- Authentication authentication ,
108103 @ RequestParam ("entityId" ) String entityId ) {
109104 LOG .debug ("/policies for " + entityId + " for " + user .getEmail ());
110105
111106 confirmInstitutionAdmin (user );
112107 //we need to ensure the application is connected to the IdP of the user - realtime
113108 if (!user .isSuperUser ()) {
114- Map <String , Object > data = getIdentityProvider (authentication );
109+ Map <String , Object > data = getIdentityProvider (user );
115110 boolean noneMatch = ((List <Map <String , String >>) data .getOrDefault ("allowedEntities" , List .of ()))
116111 .stream ()
117112 .noneMatch (allowedEntity -> allowedEntity .get ("name" ).equals (entityId ));
@@ -131,7 +126,7 @@ public ResponseEntity<List<Map<String, Object>>> policies(User user,
131126 public ResponseEntity <Map <String , Object >> createPolicy (User user , @ RequestBody Map <String , Object > policy ) {
132127 LOG .debug ("/createPolicy for " + policy + " for " + user .getEmail ());
133128
134- policyAccessAllowed (user , policy );
129+ policyAccessAllowed (user , policy , true );
135130 return ResponseEntity .ok (manage .createPolicy (policy ));
136131 }
137132
@@ -140,7 +135,7 @@ public ResponseEntity<Map<String, Object>> createPolicy(User user, @RequestBody
140135 public ResponseEntity <Map <String , Object >> updatePolicy (User user , @ RequestBody Map <String , Object > policy ) {
141136 LOG .debug ("/updatePolicy for " + policy + " for " + user .getEmail ());
142137
143- policyAccessAllowed (user , policy );
138+ policyAccessAllowed (user , policy , true );
144139 return ResponseEntity .ok (manage .updatePolicy (policy ));
145140 }
146141
@@ -151,7 +146,7 @@ public ResponseEntity<Void> deletePolicy(User user, @PathVariable String policyI
151146
152147 LOG .debug ("/deletePolicy for " + policy + " for " + user .getEmail ());
153148
154- policyAccessAllowed (user , policy );
149+ policyAccessAllowed (user , policy , true );
155150 manage .deletePolicy (policy );
156151 return ResponseEntity .noContent ().build ();
157152 }
@@ -194,21 +189,17 @@ public ResponseEntity<Map<String, Object>> rejectChangeRequest(User user, @Reque
194189 return Results .okResult ();
195190 }
196191
197- private void policyAccessAllowed (User user , Map <String , Object > policy ) {
192+ private void policyAccessAllowed (User user , Map <String , Object > policy , boolean throwException ) {
198193 confirmInstitutionAdmin (user );
199194 //We don't want to use PolicyDefinition as @RequestBody, because the template from Manage is leading
200195 PolicyDefinition policyDefinition = this .objectMapper .convertValue (policy .get ("data" ), PolicyDefinition .class );
201196 confirmPolicyAccess (user , policyDefinition , manage );
202197 }
203198
204- private Map <String , Object > getIdentityProvider (Authentication authentication ) {
205- OidcUser oidcUser = (OidcUser ) authentication .getPrincipal ();
206- Map <String , Object > claims = oidcUser .getUserInfo ().getClaims ();
207- Institution institution = (Institution ) claims .get (InstitutionAdmin .INSTITUTION );
199+ private Map <String , Object > getIdentityProvider (User user ) {
208200 //We can't use any cache as this method is called right after automatic connection allowed
209- Map <String , Object > identityProvider = manage .providerById (EntityType .saml20_idp , institution .getManageIdentifier (), Environment .PROD );
210- Map <String , Object > data = getData (identityProvider );
211- return data ;
201+ Map <String , Object > identityProvider = manage .identityProviderByEntityID (user .getAuthenticatingAuthority ());
202+ return getData (identityProvider );
212203 }
213204
214205
0 commit comments