@@ -66,16 +66,16 @@ public AuthorizationResult authorize(AuthorizationRequest request) throws Author
6666 request .getResourceContext () != null && !request .getUserContext ().isEmpty () ? request .getUserContext () : Map .of ("" , "" ));
6767 } catch (Exception e ) {
6868 logger .error (
69- "An error occured while trying to build the OPA-request" , e );
70- return AuthorizationResult .denied ("An error occured while trying to build the OPA-request" );
69+ "An error occured while trying to build the OPA-request. " , e );
70+ return AuthorizationResult .denied ("An error occured while trying to build the OPA-request. " );
7171 }
7272
7373 OPAResponse opaResponse = null ;
7474 try {
7575 opaResponse = opaClient .evaluate (OPA_RULE_HEAD , requestForm , OPAResponse .class );
7676 } catch (OPAException e ) {
77- logger .error (MessageFormat . format ( "An error occured while trying to query against OPA: {0} " , e . toString ()) );
78- return AuthorizationResult .denied ("An error occured while trying to query against OPA" );
77+ logger .error ("An error occured while trying to query against OPA. " , e );
78+ return AuthorizationResult .denied ("An error occured while trying to query against OPA. " );
7979 }
8080 if (opaResponse == null ) {
8181 logger .error ("An error occured while unmarshalling an OPA response." );
@@ -89,23 +89,22 @@ public AuthorizationResult authorize(AuthorizationRequest request) throws Author
8989 cache .clear ();
9090 }
9191
92- switch (opaResponse .allowed ()) {
93- case "true" :
92+ if (opaResponse .resourceNotFound ()) {
93+ cache .putCachedResult (request , AuthorizationResult .resourceNotFound ());
94+ logger .debug ("Authorizer-Result: Resource not found" );
95+ return AuthorizationResult .resourceNotFound ();
96+ }
97+
98+ if (opaResponse .allowed ()) {
9499 cache .putCachedResult (request , AuthorizationResult .approved ());
95100 logger .debug ("Authorizer-Result: Access was approved" );
96101 return AuthorizationResult .approved ();
97- case "unknown" :
98- cache .putCachedResult (request , AuthorizationResult .resourceNotFound ());
99- logger .debug ("Authorizer-Result: No access resource found" );
100- return AuthorizationResult .resourceNotFound ();
101- default :
102+ } else {
102103 cache .putCachedResult (request , AuthorizationResult .denied ());
103104 logger .debug ("Authorizer-Result: Access was denied" );
104105 return AuthorizationResult
105106 .denied (opaResponse .message () != null ? opaResponse .message () : "Access denied." );
106107 }
107-
108- // enum - switch
109108 }
110109
111110 @ Override
0 commit comments