Package io.muserver.rest
Class BasicAuthSecurityFilter
- java.lang.Object
-
- io.muserver.rest.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 aSecurityContext
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 returnnull
andSecurityContext.isUserInRole(String)
will return false for any role.
-
-
Constructor Summary
Constructors Constructor Description BasicAuthSecurityFilter(java.lang.String authRealm, UserPassAuthenticator authenticator, Authorizer authorizer)
Creates a new Basic Auth Security Filter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
filter(javax.ws.rs.container.ContainerRequestContext filterContext)
-
-
-
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 nameauthenticator
- 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.
-
-