Package org.codelibs.spnego
Class SpnegoHttpServletRequest
- java.lang.Object
-
- javax.servlet.ServletRequestWrapper
-
- javax.servlet.http.HttpServletRequestWrapper
-
- org.codelibs.spnego.SpnegoHttpServletRequest
-
- All Implemented Interfaces:
javax.servlet.http.HttpServletRequest,javax.servlet.ServletRequest,DelegateServletRequest,SpnegoAccessControl
public final class SpnegoHttpServletRequest extends javax.servlet.http.HttpServletRequestWrapper implements DelegateServletRequest, SpnegoAccessControl
Wrap ServletRequest so we can do our own handling of the principal and auth types.Also, see the documentation on the
DelegateServletRequestclass.Finally, a credential delegation example can be found on http://spnego.sourceforge.net
- Author:
- Darwin V. Felix
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleananyAccess(String... resources)Checks to see if the user has at least one of the passed-in user-defined resource labelsbooleananyRole(String... roles)Checks to see if the user has at least one of the passed-in attributes.StringgetAuthType()Returns "Negotiate" or "Basic" else default auth type.GSSCredentialgetDelegatedCredential()Returns the requester's delegated credential.StringgetRemoteUser()Returns authenticated username (sans domain/realm) else default username.UserInfogetUserInfo()Returns the user's info object.PrincipalgetUserPrincipal()Returns KerberosPrincipal of user.booleanhasAccess(String resource)Checks to see if the user has access to the user-defined resource label.booleanhasAccess(String resourceX, String... resourceYs)Checks to see if the user has the first user-defined resource label AND has at least one of the passed-in user-defined resource labels.booleanhasRole(String role)Checks to see if the user has the passed-in attribute.booleanhasRole(String featureX, String... featureYs)Checks to see if the user has the first attribute AND has at least one of the passed-in attributes.booleanisUserInRole(String role)-
Methods inherited from class javax.servlet.http.HttpServletRequestWrapper
authenticate, changeSessionId, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getMethod, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, login, logout, upgrade
-
Methods inherited from class javax.servlet.ServletRequestWrapper
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setCharacterEncoding, setRequest, startAsync, startAsync
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.servlet.ServletRequest
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
-
-
-
-
Method Detail
-
getAuthType
public String getAuthType()
Returns "Negotiate" or "Basic" else default auth type.- Specified by:
getAuthTypein interfacejavax.servlet.http.HttpServletRequest- Overrides:
getAuthTypein classjavax.servlet.http.HttpServletRequestWrapper- See Also:
HttpServletRequest.getAuthType()
-
getDelegatedCredential
public GSSCredential getDelegatedCredential()
Description copied from interface:DelegateServletRequestReturns the requester's delegated credential.Returns null if request has no delegated credential or if delegated credentials are not supported.
- Specified by:
getDelegatedCredentialin interfaceDelegateServletRequest- Returns:
- delegated credential or null
-
getRemoteUser
public String getRemoteUser()
Returns authenticated username (sans domain/realm) else default username.- Specified by:
getRemoteUserin interfacejavax.servlet.http.HttpServletRequest- Overrides:
getRemoteUserin classjavax.servlet.http.HttpServletRequestWrapper- See Also:
HttpServletRequest.getRemoteUser()
-
getUserPrincipal
public Principal getUserPrincipal()
Returns KerberosPrincipal of user.- Specified by:
getUserPrincipalin interfacejavax.servlet.http.HttpServletRequest- Overrides:
getUserPrincipalin classjavax.servlet.http.HttpServletRequestWrapper- See Also:
HttpServletRequest.getUserPrincipal()
-
anyRole
public boolean anyRole(String... roles)
Description copied from interface:SpnegoAccessControlChecks to see if the user has at least one of the passed-in attributes.String[] attributes = new String[] {"Developer", "Los Angeles", "Manager"}; if (accessControl.anyRole(attributes)) { // will be in here if the user has at least one matching attribute }- Specified by:
anyRolein interfaceSpnegoAccessControl- Parameters:
roles- e.g. Team Lead, IT, Developer- Returns:
- true if the user has at least one of the passed-in roles/features
-
hasRole
public boolean hasRole(String role)
Description copied from interface:SpnegoAccessControlChecks to see if the user has the passed-in attribute.String attribute = "Developer"; if (accessControl.hasRole(attribute)) { // will be in here if the user has the matching attribute }- Specified by:
hasRolein interfaceSpnegoAccessControl- Parameters:
role- e.g. Team Lead, IT, Developer- Returns:
- true if the user has at least one of the passed-in roles/features
-
hasRole
public boolean hasRole(String featureX, String... featureYs)
Description copied from interface:SpnegoAccessControlChecks to see if the user has the first attribute AND has at least one of the passed-in attributes.String attributeX = "Los Angeles"; String[] attributeYs = new String[] {"Developer", "Manager"}; if (accessControl.hasRole(attributeX, attributeYs)) { // will be in here if the user has attributeX // AND has at least one of the attributeYs. }- Specified by:
hasRolein interfaceSpnegoAccessControl- Parameters:
featureX- e.g. Information TechnologyfeatureYs- e.g. Team Lead, IT-Architecture-DL- Returns:
- true if the user has featureX AND at least one the featureYs
-
anyAccess
public boolean anyAccess(String... resources)
Description copied from interface:SpnegoAccessControlChecks to see if the user has at least one of the passed-in user-defined resource labelsString[] resources = new String[] {"admin-links", "ops-buttons"}; if (accessControl.anyAccess(resources)) { // will be in here if the user has at least one matching resource }- Specified by:
anyAccessin interfaceSpnegoAccessControl- Parameters:
resources- e.g. admin-links, ops-buttons- Returns:
- true if the user has at least one of the passed-in resources
-
hasAccess
public boolean hasAccess(String resource)
Description copied from interface:SpnegoAccessControlChecks to see if the user has access to the user-defined resource label.boolean hasPermission = false; if (request instanceof SpnegoAccessControl) { SpnegoAccessControl accessControl = (SpnegoAccessControl) request; hasPermission = accessControl.hasAccess("finance-links"); }- Specified by:
hasAccessin interfaceSpnegoAccessControl- Parameters:
resource- e.g. admin-buttons- Returns:
- true if the user has access to the user-defined resource
-
hasAccess
public boolean hasAccess(String resourceX, String... resourceYs)
Description copied from interface:SpnegoAccessControlChecks to see if the user has the first user-defined resource label AND has at least one of the passed-in user-defined resource labels.String resourceX = "finance-links"; String[] resourceYs = new String[] {"admin-links", "accounting-buttons"}; if (accessControl.hasAccess(resourceX, resourceYs)) { // will be in here if the user has resourceX // AND has at least one of the resourceYs. }- Specified by:
hasAccessin interfaceSpnegoAccessControl- Parameters:
resourceX- e.g. finance-linksresourceYs- e.g. admin-links, accounting-buttons- Returns:
- true if the user has resourceX AND at least one the resourceYs
-
getUserInfo
public UserInfo getUserInfo()
Description copied from interface:SpnegoAccessControlReturns the user's info object.- Specified by:
getUserInfoin interfaceSpnegoAccessControl- Returns:
- the user's info object
-
isUserInRole
public boolean isUserInRole(String role)
- Specified by:
isUserInRolein interfacejavax.servlet.http.HttpServletRequest- Overrides:
isUserInRolein classjavax.servlet.http.HttpServletRequestWrapper
-
-