Skip to content

Commit

Permalink
Merge pull request #12 from aserto-dev/resource-mapper-errors
Browse files Browse the repository at this point in the history
Handle ResourceMapperError in AsertoAuthorizationManager.check
  • Loading branch information
ronenh authored Aug 7, 2024
2 parents 9b090c5 + a0d8870 commit 07677a1
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.aserto.authorizer.mapper.identity.InvalidIdentity;
import com.aserto.authorizer.mapper.policy.PolicyMapper;
import com.aserto.authorizer.mapper.resource.ResourceMapper;
import com.aserto.authorizer.mapper.resource.ResourceMapperError;
import com.aserto.authorizer.v2.Decision;
import com.aserto.model.IdentityCtx;
import com.aserto.model.PolicyCtx;
Expand Down Expand Up @@ -110,8 +111,16 @@ public AuthorizationDecision check(HttpServletRequest httpRequest, IdentityMappe
String policyPath = policyMapper.policyPath(httpRequest);
log.debug("Policy path is [{}], policy name is [{}], policy label is [{}] and decision is [{}]", policyPath, policyName, policyLabel , authorizerDecision);
PolicyCtx policyCtx = new PolicyCtx(policyName, policyLabel, policyPath, new String[]{ authorizerDecision });
Map<String, Value> resourceCtx = resourceMapper.getResource(httpRequest);
log.debug("Resource context: [{}]", toResourceContextString(resourceCtx));

Map<String, Value> resourceCtx;

try {
resourceCtx = resourceMapper.getResource(httpRequest);
log.debug("Resource context: [{}]", toResourceContextString(resourceCtx));
} catch (ResourceMapperError e) {
log.error("Resource mapper error [{}]. Authorization denied.", e.getMessage());
return new AuthorizationDecision(false);
}

boolean isAllowed = false;
try {
Expand Down

0 comments on commit 07677a1

Please sign in to comment.