Class Auth


  • public class Auth
    extends java.lang.Object
    Authorization Policies. See Users for special user names.
    • Constructor Summary

      Constructors 
      Constructor Description
      Auth()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean allow​(java.lang.String user, AuthPolicy policy)
      Test whether a user (principal) is allowed by a authorization policy.
      static boolean allow​(java.lang.String user, AuthPolicy policy, java.lang.Runnable notAllowed)
      Test whether a user (principal) is allowed by a authorization policy and perform an action if the policy does not allow the user.
      static AuthPolicy policyAllowSpecific​(java.lang.String... allowedUsers)
      A policy that allows specific users (convenience wrapped for policyAllowSpecific(Collection)).
      static AuthPolicy policyAllowSpecific​(java.util.Collection<java.lang.String> allowedUsers)
      A policy that allows specific users.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ANY_USER

        public static AuthPolicy ANY_USER
        Any authenticated user.
      • ANY_ANON

        public static AuthPolicy ANY_ANON
        Any user, whether authenticated or not.
      • DENY

        public static AuthPolicy DENY
        Never allow.
    • Constructor Detail

      • Auth

        public Auth()
    • Method Detail

      • allow

        public static boolean allow​(java.lang.String user,
                                    AuthPolicy policy)
        Test whether a user (principal) is allowed by a authorization policy. The policy can be null, meaning no restrictions, and the function returns true. user maybe null, meaning unauthenticated and any policy must deal with this.
        Parameters:
        user -
        policy -
        Returns:
        boolean True if the policy is null or allows the user.
      • allow

        public static boolean allow​(java.lang.String user,
                                    AuthPolicy policy,
                                    java.lang.Runnable notAllowed)
        Test whether a user (principal) is allowed by a authorization policy and perform an action if the policy does not allow the user. The action can throw an exception. Additional, return true/false - see allow(String, AuthPolicy). The policy can be null, meaning no restrictions, and the function returns true. user maybe null, meaning unauthenticated and any policy must deal with this.
        Parameters:
        user -
        policy -
        notAllowed - Runnable to execute if the policy does not allow the user.