]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-766: Reduce 'Anonymous access without a valid tenant ID' log message to WARN...
authorRay Lee <ray.lee@lyrasis.org>
Tue, 1 Oct 2019 21:36:42 +0000 (14:36 -0700)
committerRay Lee <ray.lee@lyrasis.org>
Tue, 1 Oct 2019 21:36:42 +0000 (14:36 -0700)
services/common/src/main/java/org/collectionspace/services/common/security/SecurityContextImpl.java

index 15cb981cdbead8d5d7e41650ac96a9dc21bfa0da..e3f2fd6a9764bcccd4203a40de08eea3e24b6d45 100644 (file)
@@ -44,40 +44,41 @@ public class SecurityContextImpl implements SecurityContext {
     private String userId;
     private String currentTenantName;
     private String currentTenantId;
-    
+
     private String getTenantId(UriInfo uriInfo) throws UnauthorizedException {
-       String result = AuthN.get().getCurrentTenantId();
-       
-       String userId = AuthN.get().getUserId();
+        String result = AuthN.get().getCurrentTenantId();
+        String userId = AuthN.get().getUserId();
+
         if (userId.equals(AuthN.ANONYMOUS_USER) == true) {
             //
             // If anonymous access is being attempted, then a tenant ID needs to be set as a query param
-            //         
-               if (uriInfo == null) {
-                       String errMsg = "Anonymous access attempted with missing or invalid tenant ID query or path paramter. A null 'UriInfo' instance was passed into the service context constructor.";
-                       logger.warn(errMsg);
-                       throw new UnauthorizedException(errMsg);
-               }
-               
-               String tenantIdQueryParam = uriInfo.getQueryParameters().getFirst(AuthN.TENANT_ID_QUERY_PARAM);
-               String tenantPathParam = uriInfo.getPathParameters().getFirst(AuthN.TENANT_ID_PATH_PARAM);
-               if (tenantIdQueryParam == null && tenantPathParam == null) {
-                       String errMsg = String.format("Anonymous access to '%s' attempted without a valid tenant ID query or path paramter.",
-                                       uriInfo.getPath());
-                       logger.error(errMsg);
-                       throw new UnauthorizedException(errMsg);
-               }
-               
+            //
+            if (uriInfo == null) {
+                String errMsg = "Anonymous access attempted with null UriInfo.";
+                logger.warn(errMsg);
+                throw new UnauthorizedException(errMsg);
+            }
+
+            String tenantIdQueryParam = uriInfo.getQueryParameters().getFirst(AuthN.TENANT_ID_QUERY_PARAM);
+            String tenantPathParam = uriInfo.getPathParameters().getFirst(AuthN.TENANT_ID_PATH_PARAM);
+
+            if (tenantIdQueryParam == null && tenantPathParam == null) {
+                String errMsg = String.format("Anonymous access to '%s' attempted without a valid tenant ID query or path parameter.",
+                        uriInfo.getPath());
+                logger.warn(errMsg);
+                throw new UnauthorizedException(errMsg);
+            }
+
                result = tenantIdQueryParam != null ? tenantIdQueryParam : tenantPathParam; // If both have value, user the query param (not path) value
         }
-        
+
         return result;
     }
 
     public SecurityContextImpl(UriInfo uriInfo) throws UnauthorizedException {
         userId = AuthN.get().getUserId();
-        currentTenantId = getTenantId(uriInfo);               
-        currentTenantName = AuthN.get().getCurrentTenantName();        
+        currentTenantId = getTenantId(uriInfo);
+        currentTenantName = AuthN.get().getCurrentTenantName();
     }
 
     @Override