code: private static void checkPermission(final Subject user, 
                                        final Permission... permissions) 
    throws AuthorizationException {
      try{
        Subject.doAs(user, 
                     new PrivilegedExceptionAction<Void>() {
                       @Override
                       public Void run() throws Exception {
                         try {
                           for(Permission permission : permissions) {
                             AccessController.checkPermission(permission);
                           }
                         } catch (AccessControlException ace) {
                           LOG.info("Authorization failed for " + 
                                    UserGroupInformation.getCurrentUGI(), ace);
                           throw new AuthorizationException(ace);
                         }
                        return null;
                       }
                     }
                    );
      } catch (PrivilegedActionException e) {
        throw new AuthorizationException(e.getException());
      }
    }
docs: Check if the given {@link Subject} has all of necessary {@link Permission}
  set.
  
  @param user <code>Subject</code> to be authorized
  @param permissions <code>Permission</code> set
  @throws AuthorizationException if the authorization failed