public enum WebXml extends Enum<WebXml>
This configuration enum parses the /WEB-INF/web.xml
and all /META-INF/web-fragment
files
found in the classpath and offers methods to obtain information from them which is not available by the standard
Servlet API.
Some examples:
// Get the <welcome-file-list> (which are essentially path-relative filenames which needs to be served when a folder is requested). List<String> welcomeFiles = WebXml.INSTANCE.getWelcomeFiles();
// Get a mapping of all error page locations by exception type (a key of null represents the default error page location, if any). Map<Class<Throwable>, String> errorPageLocations = WebXml.INSTANCE.getErrorPageLocations();
// Get the <form-login-page> (which is a context-relative URL to the login page of FORM based authentication). String formLoginPage = WebXml.INSTANCE.getFormLoginPage();
// Get a mapping of all <security-constraint> URL patterns and associated roles. Map<String, Set<String>> securityConstraints = WebXml.INSTANCE.getSecurityConstraints();
// Check if access to certain (context-relative) URL is allowed for the given role based on <security-constraint>. boolean accessAllowed = WebXml.INSTANCE.isAccessAllowed("/admin.xhtml", "admin");
// Get web.xml configured session timeout (in seconds). int sessionTimeout = WebXml.INSTANCE.getSessionTimeout();
Enum Constant and Description |
---|
INSTANCE
Returns the lazily loaded enum singleton instance.
|
Modifier and Type | Method and Description |
---|---|
String |
findErrorPageLocation(Throwable exception)
Find for the given exception the right error page location.
|
Map<Class<Throwable>,String> |
getErrorPageLocations()
Returns a mapping of all error page locations by exception type.
|
String |
getFormErrorPage()
Returns the location of the FORM authentication error page, or
null if it is not defined. |
String |
getFormLoginPage()
Returns the location of the FORM authentication login page, or
null if it is not defined. |
Map<String,Set<String>> |
getSecurityConstraints()
Returns a mapping of all security constraint URL patterns and the associated roles in the declared order.
|
int |
getSessionTimeout()
Returns the configured session timeout in minutes, or
-1 if it is not defined. |
List<String> |
getWelcomeFiles()
Returns a list of all welcome files.
|
WebXml |
init(ServletContext servletContext)
Perform manual initialization with the given servlet context, if not null and not already initialized yet.
|
boolean |
isAccessAllowed(String url,
String role)
Returns
true if access to the given URL is allowed for the given role. |
static WebXml |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static WebXml[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final WebXml INSTANCE
Note: if this is needed in e.g. a Filter
which is called before the FacesServlet
is invoked,
then it won't work if the INSTANCE
hasn't been referenced before. Since JSF installs a special
"init" FacesContext
during startup, one option for doing this initial referencing is in a
ServletContextListener
. The data this enum encapsulates will then be available even where there is no
FacesContext
available. If there's no other option, then you need to manually invoke
init(ServletContext)
whereby you pass the desired ServletContext
.
public static WebXml[] values()
for (WebXml c : WebXml.values()) System.out.println(c);
public static WebXml valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic WebXml init(ServletContext servletContext)
servletContext
- The servlet context to obtain the web.xml from.WebXml
instance, initialized and all.public String findErrorPageLocation(Throwable exception)
exception
- The exception to find the error page location for.public boolean isAccessAllowed(String url, String role)
true
if access to the given URL is allowed for the given role. URL patterns are matched as
per Servlet 3.0 specification 12.1:
true
.
url
- URL to be checked for access by the given role. It must start with '/' and be context-relative.role
- Role to be checked for access to the given URL.true
if access to the given URL is allowed for the given role, otherwise false
.NullPointerException
- If given URL is null.IllegalArgumentException
- If given URL does not start with '/'.public List<String> getWelcomeFiles()
public Map<Class<Throwable>,String> getErrorPageLocations()
null
key.public String getFormLoginPage()
null
if it is not defined.null
if it is not defined.public String getFormErrorPage()
null
if it is not defined.null
if it is not defined.public Map<String,Set<String>> getSecurityConstraints()
null
, then it means that no auth constraint is been set (i.e. the resource is publicly
accessible). If the roles is empty, then it means that an empty auth constraint is been set (i.e. the resource
is in no way accessible).public int getSessionTimeout()
-1
if it is not defined.-1
if it is not defined.Copyright © 2012–2017 OmniFaces. All rights reserved.