Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, the <code>AccesssDecisionVoter</code> interface actually returns an <code>int</code> in this situation. Granted, the built-in voter implementations always only return one of the three constants you mentioned (and these are what the standard access decision managers check for), but then they don't really have anything extra to return - the <code>RoleVoter</code> for instance will deny access if and only if the principal doesn't have the required role.</p> <p>Since you're using your own implementations both of the voters and the access decision manager, you have several options available as I see it:</p> <ol> <li>Return other values of integers as some form of error code; treat <code>ACCESS_GRANTED</code>, <code>ACCESS_ABSTAIN</code> and <code>ACCESS_DENIED</code> as their typical values, but treat any other integer as "access denied" with an error code. Ideally have a lookup table of error codes available - essentially a poor man's enum.</li> <li>Within your voter, return <code>ACCESS_DENIED</code> as usual, and set some publically accessible property (either on the voter object itself or perhaps some statically-accessible field) with the error reason. In your manager, if you get access denied from your custom voter, check the property to get the details.</li> <li>As above, set an error property within the voter; but ensure that the instance of <code>Authentication</code> being passed in is one of your own custom subclasses that provides a good location to set/retrieve this information.</li> <li>Throw an <code>AccessDeniedException</code> (or suitable subclass) from within your voter itself. This is not ideal as it presupposes the logic in the access decision manager; but you could either let this bubble straight up, or if needed catch it within the manager (a custom subclass would definitely be good for this) and rethrow if access really is denied (something similar to what the <code>ProviderManager</code> class does with its <code>lastException</code> variable).</li> </ol> <p>None of these sticks out as the obviously correct and elegant answer, but you should be able to get something workable from whichever one is most appropriate. Since there is no <em>explicit</em> support within the voter framework for communicating reasons (it's a straight boolean response fundamentally) I don't think you can do much better.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload