1818import org .springframework .transaction .annotation .Transactional ;
1919import org .springframework .util .StringUtils ;
2020import org .springframework .validation .annotation .Validated ;
21- import org .springframework .web .bind .annotation .*;
21+ import org .springframework .web .bind .annotation .DeleteMapping ;
22+ import org .springframework .web .bind .annotation .GetMapping ;
23+ import org .springframework .web .bind .annotation .PathVariable ;
24+ import org .springframework .web .bind .annotation .PostMapping ;
25+ import org .springframework .web .bind .annotation .RequestBody ;
26+ import org .springframework .web .bind .annotation .RequestMapping ;
27+ import org .springframework .web .bind .annotation .RestController ;
2228
2329import java .util .List ;
2430import java .util .Map ;
@@ -73,10 +79,10 @@ public ResponseEntity<APIToken> create(@Validated @RequestBody APIToken apiToken
7379 UserPermissions .assertAuthority (user , Authority .INVITER );
7480 String token = (String ) request .getSession ().getAttribute (TOKEN_KEY );
7581 if (!StringUtils .hasText (token )) {
76- throw new UserRestrictionException ();
82+ throw new UserRestrictionException ("Token is NULL" );
7783 }
7884 if (user .isSuperUser () && !StringUtils .hasText (apiTokenRequest .getOrganizationGUID ())) {
79- throw new UserRestrictionException ();
85+ throw new UserRestrictionException ("Super user must specify API token OrganizationGUID" );
8086 }
8187 APIToken apiToken ;
8288 if (user .isSuperUser () || user .isInstitutionAdmin ()) {
@@ -96,16 +102,17 @@ public ResponseEntity<APIToken> create(@Validated @RequestBody APIToken apiToken
96102 @ DeleteMapping ("/{id}" )
97103 public ResponseEntity <Void > deleteToken (@ PathVariable ("id" ) Long id , @ Parameter (hidden = true ) User user ) {
98104 LOG .debug (String .format ("DELETE /tokens/deleteToken with id %s for user %s" , id .toString (), user .getEduPersonPrincipalName ()));
105+
99106 UserPermissions .assertAuthority (user , Authority .INVITER );
100107 APIToken apiToken = apiTokenRepository .findById (id ).orElseThrow (() -> new NotFoundException ("API token not found" ));
101108 if (apiToken .isSuperUserToken () && !user .isSuperUser ()) {
102- throw new UserRestrictionException ();
109+ throw new UserRestrictionException ("Non super-user not allowed to delete super-user token: " + user . getEmail () );
103110 }
104111 if (user .isInstitutionAdmin () && !apiToken .getOrganizationGUID ().equals (user .getOrganizationGUID ())) {
105- throw new UserRestrictionException ();
112+ throw new UserRestrictionException ("User not allowed to delete token for different organization: " + user . getEmail () );
106113 }
107114 if (!user .isSuperUser () && !user .isInstitutionAdmin () && !Objects .equals (user .getId (), apiToken .getOwner ().getId ())) {
108- throw new UserRestrictionException ();
115+ throw new UserRestrictionException ("User not allowed to delete token for different owner: " + user . getEmail () );
109116 }
110117 apiTokenRepository .delete (apiToken );
111118 return Results .deleteResult ();
0 commit comments