Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It sounds like what you are trying to do is implement row-level security for specific accounts. There are other Stackoverflow questions (<a href="https://stackoverflow.com/questions/5716242/how-to-implement-row-level-security-in-java">How to implement row-level security in Java?</a> and <a href="https://stackoverflow.com/questions/3054608/database-independent-row-level-security-solution">Database independent row level security solution</a>) that discuss potential solutions to this very problem. Additionally, the link provided in the first answer discusses implementing <a href="http://mattfleming.com/node/243" rel="nofollow noreferrer">Row Level Security with Spring and Hibernate</a>. However, the higher ranked answer recommends implementing row-level security directly at the database level.</p> <p>Having worked with Shiro I can say that it can be done. However you must implement your own security structures (Realms, Permissions, Annotations) to accommodate the type of functionality you describe. One approach would be to add an annotation similar to what you have in your last example that indicates the method requires a permission check. This annotation would be tied to an Interceptor which would in turn generate the appropriate permission and then call to the security framework to verify the permission.</p> <p>It would look something like this.</p> <p>Method:</p> <pre><code>@RequiresAuthorization @Entitled public AccountDetails getAccountDetails(@Account String accountId) {...} </code></pre> <p>Interceptor:</p> <pre><code>@Interceptor @Entitled public class EntitledInterceptor { @AroundInvoke public void interceptOrder(InvocationContext ctx) { // return type is AccountDetails // parameter[0] is acccoundId Permission p = new CustomPermission(context.getMethod().getReturnType(), ctx.getParameters()[0]); if(SecurityUtils.getSubject().isPermitted(p)){ return ctx.proceed(); } else { throw new RowLevelSecurityException("No access!"); } } </code></pre> <p>Realm:</p> <pre><code>public boolean isPermitted(SubjectPrincipals principal, Permission p){ if( p instanceof CustomPermission){ CustomPermission cp = (CustomPermission) p; Class&lt;?&gt; type = cp.getType(); //AccountDetails Integer id = cp.getId(); //accountId Integer userId = principal.getPrimaryPrincipal(); //or username customPermissionCheckingLogic(userId, type, id); } } </code></pre> <p>Obviously this implementation relies on CDI and you having a way to determine what table(s) to check based on the object type provided (JPA annotations work in this regard). Additionally there may be ways to hook into Shiro's annotation scanning to provide more direct/native permission functionality than what I've done here.</p> <p><a href="http://docs.oracle.com/javaee/6/tutorial/doc/gkhjx.html" rel="nofollow noreferrer">Documentation on CDI interceptors.</a></p>
    singulars
    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.
    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