@@ -60,20 +60,37 @@ public class CheckLoginFilter implements ContainerRequestFilter, ContainerRespon
6060
6161 /*************** The following three methods control the default behavior for WDK endpoints ************/
6262
63- // override and add paths to this list if no authentication is required AND'
64- // no guest user should be created for this request
63+ /**
64+ * @param path request URL path
65+ * @return true if no authorization is required and no guest
66+ * user should be created for this request, else false
67+ */
6568 protected boolean isPathToSkip (String path ) {
6669 // skip user check for prometheus metrics requests
6770 return SystemService .PROMETHEUS_ENDPOINT_PATH .equals (path );
6871 }
6972
70- // override and add paths to this list if valid token is required (no guest will be created)
73+ /**
74+ * A return value of true indicates a valid bearer token is required; the token
75+ * may be a guest depending on the value of isGuestUserAllowed(). If false is
76+ * returned, no token is present, and isGuestUserAllowed() returns true, then a
77+ * new guest token will be generated for this request and returned to the user.
78+ *
79+ * @param path request URL path
80+ * @return true if a valid bearer token is required on the request, else false
81+ */
7182 protected boolean isValidTokenRequired (String path ) {
7283 return false ;
7384 }
7485
75- // authentication is required AND
76- // if token is absent or expired, create new guest to use for this request
86+ /**
87+ * A return value of true indicates a guest user is allowed to access this
88+ * endpoint. If a sent token is absent and isValidTokenRequired() returns false,
89+ * a new guest token will be generated for use on this request.
90+ *
91+ * @param path request URL path
92+ * @return true if guests are allowed to access this endpoint, else false
93+ */
7794 protected boolean isGuestUserAllowed (String path ) {
7895 return true ;
7996 }
@@ -121,8 +138,16 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
121138 }
122139 }
123140 catch (ExpiredTokenException e ) {
124- // token is expired; use guest token for now which should inspire them to log back in
125- useNewGuest (factory , request , requestContext , requestPath );
141+ if (isGuestUserAllowed (requestPath )) {
142+ // token is expired, but guest token is allowed to be generated,
143+ // which will hopefully inspire them to log back in
144+ useNewGuest (factory , request , requestContext , requestPath );
145+ }
146+ else {
147+ throw new NotAuthorizedException (Response .status (Status .UNAUTHORIZED )
148+ .entity ("Authorization token has expired." ).build ());
149+
150+ }
126151 }
127152 catch (InvalidTokenException e ) {
128153 // passed token is invalid; throw 401
0 commit comments