public final class WebSecurity extends java.lang.Object implements Service
Methods that start with "from" are to register WebSecurity with WebServer
- to create SecurityContext for requests:
Example:
// Web server routing builder - this is our integration pointRoutingrouting = Routing.builder() // register the WebSecurity to create context (shared by all routes) .register(WebSecurity.from(security))
Other methods are to create security enforcement points (gates) for routes (e.g. you are expected to use them for a get, post
etc. routes on specific path).
These methods are starting points that provide an instance of SecurityHandler that has finer grained methods to
control the gate behavior.
Note that if any gate is configured, auditing will be enabled by default except for GET and HEAD methods - if you want
to audit any method, invoke audit() to create a gate that will always audit the route.
If you want to create a gate and not audit it, use SecurityHandler.skipAudit() on the returned instance.
secure() - authentication and authorizationrolesAllowed(String...) - role based access control (implies authentication and authorization)authenticate() - authentication onlyauthorize() - authorization onlyallowAnonymous() - authentication optionalaudit() - audit all requests (including GET and HEAD)authenticator(String) - use explicit authenticator (named - as configured in config or through builder)authorizer(String) - use explicit authorizer (named - as configured in config or through builder)enforce() - use defaults (e.g. no authentication, authorization, audit calls except for GET and HEAD); this
also give access to more fine-grained methods of SecurityHandlerExample:
// continue from example above...
// create a gate for method GET: authenticate all paths under /user and require role "user" for authorization
.get("/user[/{*}]", WebSecurity.rolesAllowed("user"))
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CONTEXT_ADD_HEADERS
Security can accept additional headers to be added to security request.
|
| Modifier and Type | Method and Description |
|---|---|
static SecurityHandler |
allowAnonymous()
If called, authentication failure will not abort request and will continue as anonymous (defaults to false).
|
static SecurityHandler |
audit()
Whether to audit this request - defaults to false for GET and HEAD methods, true otherwise.
|
static SecurityHandler |
authenticate()
If called, request will go through authentication process - defaults to false (even if authorize is true).
|
static SecurityHandler |
authenticator(java.lang.String explicitAuthenticator)
Use a named authenticator (as supported by security - if not defined, default authenticator is used).
|
static SecurityHandler |
authorize()
Enable authorization for this route.
|
static SecurityHandler |
authorizer(java.lang.String explicitAuthorizer)
Use a named authorizer (as supported by security - if not defined, default authorizer is used, if none defined, all is
permitted).
|
static SecurityHandler |
enforce()
Return a default instance to create a default enforcement point (or modify the result further).
|
static WebSecurity |
from(Config config)
Create a consumer of routing config to be
registered with
web server routing to process security requests. |
static WebSecurity |
from(Security security)
Create a consumer of routing config to be
registered with
web server routing to process security requests. |
static WebSecurity |
from(Security security,
Config config)
Create a consumer of routing config to be
registered with
web server routing to process security requests. |
static SecurityHandler |
rolesAllowed(java.lang.String... roles)
An array of allowed roles for this path - must have a security provider supporting roles.
|
static SecurityHandler |
secure()
Secure access using authentication and authorization.
|
WebSecurity |
securityDefaults(SecurityHandler defaultHandler)
Create a new web security instance using the default handler as base defaults for all handlers used.
|
void |
update(Routing.Rules routing)
Updates
Routing.Rules with handlers representing this service. |
public static final java.lang.String CONTEXT_ADD_HEADERS
public static WebSecurity from(Security security)
registered with
web server routing to process security requests.
This method is to be used together with other routing methods to protect web resources programmatically.
Example:
.get("/user[/{*}]", WebSecurity.authenticate()
.rolesAllowed("user"))
security - initialized securitypublic static WebSecurity from(Config config)
registered with
web server routing to process security requests.
This method configures security and web server integration from a config instanceconfig - Config instance to load security and web server integration from configurationpublic static WebSecurity from(Security security, Config config)
registered with
web server routing to process security requests.
This method expects initialized security and creates web server integration from a config instancesecurity - Security instance to useconfig - Config instance to load security and web server integration from configurationpublic static SecurityHandler secure()
rolesAllowed(String...).
If you use a security provider, that requires additional data, use SecurityHandler.customObject(Object).
Behavior:
SecurityHandler instance configured with authentication and authorizationpublic static SecurityHandler authenticate()
Behavior:
SecurityHandler instancepublic static SecurityHandler audit()
Behavior:
SecurityHandler instancepublic static SecurityHandler authenticator(java.lang.String explicitAuthenticator)
Behavior:
explicitAuthenticator - name of authenticator as configured in SecuritySecurityHandler instancepublic static SecurityHandler authorizer(java.lang.String explicitAuthorizer)
Behavior:
explicitAuthorizer - name of authorizer as configured in SecuritySecurityHandler instancepublic static SecurityHandler rolesAllowed(java.lang.String... roles)
Behavior:
roles - if subject is any of these roles, allow accessSecurityHandler instancepublic static SecurityHandler allowAnonymous()
Behavior:
SecurityHandler instancepublic static SecurityHandler authorize()
Behavior:
SecurityHandler instancepublic static SecurityHandler enforce()
Behavior:
SecurityHandler instancepublic WebSecurity securityDefaults(SecurityHandler defaultHandler)
defaultHandler - if a security handler is configured for a route, it will take its defaults from this handlerpublic void update(Routing.Rules routing)
ServiceRouting.Rules with handlers representing this service.Copyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.