@@ -95,32 +95,36 @@ private void initPublicKey() {
95
95
}
96
96
97
97
private void checkAccess (final Context ctx , final Set <Role > permittedRoles ) {
98
+ try {
99
+ TokenVerifier <AccessToken > tokenVerifier = persistUserInfoInContext (ctx );
98
100
99
- TokenVerifier <AccessToken > tokenVerifier = persistUserInfoInContext (ctx );
100
-
101
- if (permittedRoles .isEmpty () || permittedRoles .contains (DefaultRole .OPEN ) && permittedRoles .size () == 1 )
102
- return ;
101
+ if (permittedRoles .isEmpty () || permittedRoles .contains (DefaultRole .OPEN ) && permittedRoles .size () == 1 )
102
+ return ;
103
103
104
- if (tokenVerifier == null )
105
- throw new UnauthorizedException ();
104
+ if (tokenVerifier == null )
105
+ throw new UnauthorizedException ();
106
106
107
- initPublicKey ();
108
- tokenVerifier .publicKey (publicKey );
109
- try {
110
- tokenVerifier .verifySignature ();
111
- } catch (VerificationException e ) {
112
- throw new UnauthorizedException ();
113
- }
107
+ initPublicKey ();
108
+ tokenVerifier .publicKey (publicKey );
109
+ try {
110
+ tokenVerifier .verifySignature ();
111
+ } catch (VerificationException e ) {
112
+ throw new UnauthorizedException ();
113
+ }
114
114
115
- try {
116
- tokenVerifier .verify ();
117
- if (permittedRoles .contains (DefaultRole .AUTHENTICATED ) && permittedRoles .size () == 1 )
118
- return ;
119
- if (hasPermittedRole (ctx , permittedRoles ))
120
- return ;
121
- throw new ForbiddenException ();
122
- } catch (VerificationException e ) {
123
- throw new ForbiddenException ();
115
+ try {
116
+ tokenVerifier .verify ();
117
+ if (permittedRoles .contains (DefaultRole .AUTHENTICATED ) && permittedRoles .size () == 1 )
118
+ return ;
119
+ if (hasPermittedRole (ctx , permittedRoles ))
120
+ return ;
121
+ throw new ForbiddenException ();
122
+ } catch (VerificationException e ) {
123
+ throw new ForbiddenException ();
124
+ }
125
+ } catch (Exception e ) {
126
+ log .error ("Error checking token." , e );
127
+ throw e ;
124
128
}
125
129
}
126
130
0 commit comments