@Service @PerLookup public class RealmAdapter extends RealmBase implements RealmInitializer, org.glassfish.hk2.api.PostConstruct
Modifier and Type | Class and Description |
---|---|
static interface |
RealmAdapter.IOSupplier<T> |
Modifier and Type | Field and Description |
---|---|
static String |
BASIC |
static String |
FORM |
protected boolean |
isCurrentURIincluded |
protected static String |
name
Descriptive information about this Realm implementation.
|
protected ReadWriteLock |
rwLock |
static String |
SECURITY_CONTEXT |
protected WebSecurityManager |
webSecurityManager
A
WebSecurityManager object associated with a CONTEXT_ID |
protected WebSecurityManagerFactory |
webSecurityManagerFactory
The factory used for creating
WebSecurityManager object. |
checkIfRequestIsSecure, container, controller, debug, digest, digestEncoding, info, lifecycle, log, md, md5Encoder, md5Helper, rb, started, support, validate
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
AUTHENTICATE_NEEDED, AUTHENTICATE_NOT_NEEDED, AUTHENTICATED_NOT_AUTHORIZED
Constructor and Description |
---|
RealmAdapter() |
RealmAdapter(String realmName,
String moduleID)
Create for WS EJB endpoint authentication.
|
Modifier and Type | Method and Description |
---|---|
Principal |
authenticate(javax.servlet.http.HttpServletRequest httpServletRequest)
This HttpServletRequest authenticate variant is primarily used by the DigestAuthenticator
|
Principal |
authenticate(String username,
char[] password)
Authenticates and sets the SecurityContext in the TLS.
|
boolean |
authenticate(WebPrincipal principal)
Used by SecurityServiceImpl
|
Principal |
authenticate(X509Certificate[] certs)
This HttpServletRequest authenticate variant is primarily used by the SSLAuthenticator
|
protected void |
configureSecurity(WebBundleDescriptor wbd,
boolean isSystem)
Generate the JSR 115 policy file for a web application, bundled within a ear or deployed as a standalone war file.
|
Principal |
createFailOveredPrincipal(String username)
This method is added to create a Principal based on the username only.
|
void |
destroy() |
SecurityConstraint[] |
findSecurityConstraints(HttpRequest request,
Context context)
Returns null 1.
|
SecurityConstraint[] |
findSecurityConstraints(String requestPathMB,
String httpMethod,
Context context)
Returns null 1.
|
protected String |
getName()
Return a short name for this Realm Adapter implementation.
|
protected char[] |
getPassword(String username)
Return the password associated with the given principal's user name.
|
protected Principal |
getPrincipal(String username)
Return the Principal associated with the given user name.
|
String |
getRealmName()
Return the name of the realm this RealmAdapter uses.
|
WebBundleDescriptor |
getWebDescriptor() |
WebSecurityManager |
getWebSecurityManager(boolean logNull)
Utility method to get the web security manager.
|
boolean |
hasResourcePermission(HttpRequest request,
HttpResponse response,
SecurityConstraint[] constraints,
Context context)
Perform access control based on the specified authorization constraint.
|
boolean |
hasRole(HttpRequest request,
HttpResponse response,
Principal principal,
String role)
Check if the given principal has the provided role.
|
boolean |
hasRole(String servletName,
Principal principal,
String role) |
boolean |
hasUserDataPermission(HttpRequest request,
HttpResponse response,
SecurityConstraint[] constraints)
Enforce any user data constraint required by the security constraint guarding this request URI.
|
boolean |
hasUserDataPermission(HttpRequest request,
HttpResponse response,
SecurityConstraint[] constraints,
String uri,
String method)
Checks if the given request URI and method are the target of any user-data-constraint with a transport-guarantee of
CONFIDENTIAL, and whether any such constraint is already satisfied.
|
void |
initConfigHelper(javax.servlet.ServletContext servletContext) |
void |
initializeRealm(Object descriptor,
boolean isSystemApp,
String realmName) |
boolean |
invokeAuthenticateDelegate(HttpRequest request,
HttpResponse response,
Context context,
Authenticator authenticator,
boolean calledFromAuthenticate)
Authenticates the user making this request, based on the specified login configuration.
|
boolean |
invokePostAuthenticateDelegate(HttpRequest request,
HttpResponse response,
Context context)
Post authentication for given request and response.
|
boolean |
isSecurityExtensionEnabled(javax.servlet.ServletContext context)
Return true if a Security Extension is available.
|
void |
logout()
Clean up security and policy context.
|
void |
logout(HttpRequest httpRequest)
Logs out.
|
void |
postConstruct() |
void |
postSetRunAsIdentity(ComponentInvocation invocation)
Attempts to restore old SecurityContext (but fails).
|
int |
preAuthenticateCheck(HttpRequest request,
HttpResponse response,
SecurityConstraint[] constraints,
boolean disableProxyCaching,
boolean securePagesWithPragma,
boolean ssoEnabled)
Checks whether or not authentication is needed.
|
void |
preSetRunAsIdentity(ComponentInvocation inv)
Set the run-as principal into the SecurityContext when needed.
|
void |
setCurrentSecurityContext(Principal principal) |
void |
setCurrentSecurityContextWithWebPrincipal(Principal principal) |
void |
setRealmName(String realmName) |
void |
setVirtualServer(Object container)
Sets the virtual server on which the web module (with which this RealmAdapter is associated with) has been deployed.
|
void |
updateWebSecurityManager() |
addLifecycleListener, addPropertyChangeListener, authenticate, backgroundProcess, digest, disableProxyCaching, findLifecycleListeners, getAlternateAuthType, getAlternatePrincipal, getContainer, getController, getDebug, getDigest, getDigest, getDigestEncoding, getInfo, getValidate, hasMessageDigest, hasRole, log, log, removeLifecycleListener, removePropertyChangeListener, setContainer, setController, setDebug, setDigest, setDigestEncoding, setRealmName, setValidate, start, stop
public static final String SECURITY_CONTEXT
public static final String BASIC
public static final String FORM
protected static final String name
protected volatile WebSecurityManager webSecurityManager
WebSecurityManager
object associated with a CONTEXT_IDprotected boolean isCurrentURIincluded
protected final ReadWriteLock rwLock
@Inject protected WebSecurityManagerFactory webSecurityManagerFactory
WebSecurityManager
object.public void initializeRealm(Object descriptor, boolean isSystemApp, String realmName)
initializeRealm
in interface RealmInitializer
protected String getName()
public String getRealmName()
getRealmName
in interface Realm
getRealmName
in class RealmBase
public void setRealmName(String realmName)
public void setVirtualServer(Object container)
setVirtualServer
in interface RealmInitializer
container
- The virtual serverpublic WebBundleDescriptor getWebDescriptor()
public WebSecurityManager getWebSecurityManager(boolean logNull)
This will log a warning if the manager is not found in the factory, and logNull is true.
public void updateWebSecurityManager()
updateWebSecurityManager
in interface RealmInitializer
public SecurityConstraint[] findSecurityConstraints(HttpRequest request, Context context)
See SJSAS 6232464 6202703 otherwise return an empty array of SecurityConstraint.
findSecurityConstraints
in interface Realm
findSecurityConstraints
in class RealmBase
request
- Request we are processingcontext
- Context the Request is mapped topublic SecurityConstraint[] findSecurityConstraints(String requestPathMB, String httpMethod, Context context)
See SJSAS 6232464 6202703 otherwise return an empty array of SecurityConstraint.
findSecurityConstraints
in interface Realm
findSecurityConstraints
in class RealmBase
requestPathMB
- the request URI (minus the context Path)httpMethod
- the request methodcontext
- the contextpublic boolean hasUserDataPermission(HttpRequest request, HttpResponse response, SecurityConstraint[] constraints) throws IOException
hasUserDataPermission
in interface Realm
hasUserDataPermission
in class RealmBase
request
- Request we are processingresponse
- Response we are creatingconstraints
- Security constraint being checkedtrue
if this constraint was not violated and processing should continue, or false
if we have created a response alreadyIOException
- if an input/output error occurspublic boolean hasUserDataPermission(HttpRequest request, HttpResponse response, SecurityConstraint[] constraints, String uri, String method) throws IOException
hasUserDataPermission
in interface Realm
hasUserDataPermission
in class RealmBase
request
- the request that may be redirectedresponse
- the response that may be redirectedconstraints
- the security constraints to check againsturi
- the request URI (minus the context path) to checkmethod
- the request method to checkIOException
public int preAuthenticateCheck(HttpRequest request, HttpResponse response, SecurityConstraint[] constraints, boolean disableProxyCaching, boolean securePagesWithPragma, boolean ssoEnabled) throws IOException
See SJSAS 6202703
preAuthenticateCheck
in interface Realm
preAuthenticateCheck
in class RealmBase
request
- Request we are processingresponse
- Response we are creatingconstraints
- Security constraint we are enforcingdisableProxyCaching
- whether or not to disable proxy caching for protected resources.securePagesWithPragma
- true if we add headers which are incompatible with downloading office documents in IE
under SSL but which fix a caching problem in Mozilla.ssoEnabled
- true if sso is enabledIOException
- if an input/output error occurspublic boolean invokeAuthenticateDelegate(HttpRequest request, HttpResponse response, Context context, Authenticator authenticator, boolean calledFromAuthenticate) throws IOException
true
if
any specified requirements have been satisfied, or false
if we have created a response challenge
already.invokeAuthenticateDelegate
in interface Realm
invokeAuthenticateDelegate
in class RealmBase
request
- Request we are processingresponse
- Response we are creatingcontext
- The Context to which client of this class is attached.authenticator
- the current authenticator.calledFromAuthenticate
- IOException
- if an input/output error occurspublic Principal authenticate(String username, char[] password)
This username/password authenticate variant is primarily used by the Basic- and FormAuthenticator.
authenticate
in interface Realm
authenticate
in class RealmBase
username
- the user name.password
- the password.public Principal authenticate(javax.servlet.http.HttpServletRequest httpServletRequest)
authenticate
in interface Realm
authenticate
in class RealmBase
httpServletRequest
- HTTP servlet request.public Principal authenticate(X509Certificate[] certs)
authenticate
in interface Realm
authenticate
in class RealmBase
certs
- Array of client certificates, with the first one in
the array being the certificate of the client itself.public boolean authenticate(WebPrincipal principal)
public Principal createFailOveredPrincipal(String username)
username
- public boolean hasResourcePermission(HttpRequest request, HttpResponse response, SecurityConstraint[] constraints, Context context) throws IOException
true
if this constraint
is satisfied and processing should continue, or false
otherwise.hasResourcePermission
in interface Realm
hasResourcePermission
in class RealmBase
request
- Request we are processingresponse
- Response we are creatingconstraint
- Security constraint we are enforcingThe
- Context to which client of this class is attached.IOException
- if an input/output error occurspublic boolean invokePostAuthenticateDelegate(HttpRequest request, HttpResponse response, Context context) throws IOException
invokePostAuthenticateDelegate
in interface Realm
invokePostAuthenticateDelegate
in class RealmBase
request
- Request we are processingresponse
- Response we are creatingcontext
- The Context to which client of this class is attached.IOException
- if an input/output error occurspublic boolean hasRole(HttpRequest request, HttpResponse response, Principal principal, String role)
public void preSetRunAsIdentity(ComponentInvocation inv)
This method will attempt to obtain the name of the servlet from the ComponentInvocation. Note that there may not be one since this gets called also during internal processing (not clear..) not just part of servlet requests. However, if it is not a servlet request there is no need (or possibility) to have a run-as setting so no further action is taken.
If the servlet name is present the runAsPrincipals cache is checked to find the run-as principal to use (if any). If one is set, the SecurityContext is switched to this principal.
See IASRI 4747594
inv
- The invocation object to process.public void postSetRunAsIdentity(ComponentInvocation invocation)
In theory this method seems to attempt to check if a run-as principal was set by preSetRunAsIdentity() (based on the indirect assumption that if the servlet in the given invocation has a run-as this must've been the case). If so, it retrieves the oldSecurityContext from the invocation object and set it in the SecurityContext.
The problem is that the invocation object is not the same object as was passed in to preSetRunAsIdentity() so it will never contain the right info - see bug 4757733.
In practice it means this method only ever sets the SecurityContext to null (if run-as matched) or does nothing. In particular note the implication that it will be set to null after a run-as invocation completes. This behavior will be retained for the time being for consistency with RI. It must be fixed later.
invocation
- The invocation object to process.public void logout(HttpRequest httpRequest)
Realm
public void logout()
RealmInitializer
logout
in interface RealmInitializer
protected char[] getPassword(String username)
RealmBase
getPassword
in class RealmBase
protected Principal getPrincipal(String username)
RealmBase
getPrincipal
in class RealmBase
public boolean isSecurityExtensionEnabled(javax.servlet.ServletContext context)
isSecurityExtensionEnabled
in interface Realm
isSecurityExtensionEnabled
in class RealmBase
context
- the ServletContextprotected void configureSecurity(WebBundleDescriptor wbd, boolean isSystem)
public void setCurrentSecurityContextWithWebPrincipal(Principal principal)
public void setCurrentSecurityContext(Principal principal)
public void initConfigHelper(javax.servlet.ServletContext servletContext)
public void postConstruct()
postConstruct
in interface org.glassfish.hk2.api.PostConstruct
Copyright © 2018. All rights reserved.