Class BasicAuthSecurityFilter

  • All Implemented Interfaces:
    javax.ws.rs.container.ContainerRequestFilter

    public class BasicAuthSecurityFilter
    extends java.lang.Object
    implements javax.ws.rs.container.ContainerRequestFilter

    A filter that can handle Basic Authentication

    Construct this class and a username/password authenticator and a class that can check if your users are in a role or not, then add it to RestHandlerBuilder.addRequestFilter(ContainerRequestFilter) which will make a SecurityContext instance available (accessible with the @Context annotation in methods).

    Note: it assumes credentials are sent with every request, otherwise a 401 is returned.

    If authentication fails, then the method is still invoked, however SecurityContext.getUserPrincipal() will return null and SecurityContext.isUserInRole(String) will return false for any role.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void filter​(javax.ws.rs.container.ContainerRequestContext filterContext)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BasicAuthSecurityFilter

        public BasicAuthSecurityFilter​(java.lang.String authRealm,
                                       UserPassAuthenticator authenticator,
                                       Authorizer authorizer)
        Creates a new Basic Auth Security Filter
        Parameters:
        authRealm - The name of your application - the client may associate credentials with this name
        authenticator - An object that takes a username and password and returns a user (or null)
        authorizer - An object that can check if a given user is in a given role.
    • Method Detail

      • filter

        public void filter​(javax.ws.rs.container.ContainerRequestContext filterContext)
                    throws java.io.IOException
        Specified by:
        filter in interface javax.ws.rs.container.ContainerRequestFilter
        Throws:
        java.io.IOException