public class BasicAuthSecurityFilter extends 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.
Constructor and Description |
---|
BasicAuthSecurityFilter(String authRealm,
UserPassAuthenticator authenticator,
Authorizer authorizer)
Creates a new Basic Auth Security Filter
|
Modifier and Type | Method and Description |
---|---|
void |
filter(javax.ws.rs.container.ContainerRequestContext filterContext) |
public BasicAuthSecurityFilter(String authRealm, UserPassAuthenticator authenticator, Authorizer authorizer)
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.public void filter(javax.ws.rs.container.ContainerRequestContext filterContext) throws IOException
filter
in interface javax.ws.rs.container.ContainerRequestFilter
IOException
Copyright © 2017–2019. All rights reserved.