Top Description Methods
org.apache.catalina

public Interface Realm

extends Contained
Known Direct Implementers
org.apache.catalina.realm.RealmBase
Imports
java.beans.PropertyChangeListener, java.io.IOException, java.security.Principal, java.security.cert.X509Certificate, org.apache.catalina.connector.Request, .Response, org.apache.tomcat.util.descriptor.web.SecurityConstraint, org.ietf.jgss.GSSContext, .GSSCredential, .GSSName

A Realm is a read-only facade for an underlying security realm used to authenticate individual users, and identify the security roles associated with those users. Realms can be attached at any Container level, but will typically only be attached to a Context, or higher level, Container.
Author
Craig R. McClanahan

Method Summary

Modifier and TypeMethod and Description
public void
addPropertyChangeListener(PropertyChangeListener
The listener to add
listener
)

Add a property change listener to this component.

public Principal

Returns:

the associated principal, or null if none is associated.
authenticate
(String
Username of the Principal to look up
username
)

Try to authenticate with the specified username.

public Principal

Returns:

the associated principal, or null if there is none
authenticate
(String
Username of the Principal to look up
username
,
String
Password or other credentials to use in authenticating this username
credentials
)

Try to authenticate using the specified username and credentials.

public Principal

Returns:

the associated principal, or null if there is none.
authenticate
(String
Username of the Principal to look up
username
,
String
Digest which has been submitted by the client
digest
,
String
Unique (or supposedly unique) token which has been used for this request
nonce
,
String
the nonce counter
nc
,
String
the client chosen nonce
cnonce
,
String
the "quality of protection" (nc and cnonce will only be used, if qop is not null).
qop
,
String
Realm name
realm
,
String
Second digest calculated as digest(Method + ":" + uri)
digestA2
)
Deprecated Unused.

Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 2617 (which is a superset of RFC 2069).

public default Principal

Returns:

the associated principal, or null if there is none.
authenticate
(String
Username of the Principal to look up
username
,
String
Digest which has been submitted by the client
digest
,
String
Unique (or supposedly unique) token which has been used for this request
nonce
,
String
the nonce counter
nc
,
String
the client chosen nonce
cnonce
,
String
the "quality of protection" (nc and cnonce will only be used, if qop is not null).
qop
,
String
Realm name
realm
,
String
Second digest calculated as digest(Method + ":" + uri)
digestA2
,
String
The message digest algorithm to use
algorithm
)

Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 7616.

public Principal

Returns:

the associated principal, or null if there is none
authenticate
(GSSContext
The gssContext processed by the Authenticator.
gssContext
,
boolean
Should the realm attempt to store the delegated credentials in the returned Principal?
storeCreds
)

Try to authenticate using a GSSContext.

public Principal

Returns:

the associated principal, or null if there is none
authenticate
(GSSName
The GSSName of the principal to look up
gssName
,
GSSCredential
The GSSCredential of the principal, may be null
gssCredential
)

Try to authenticate using a GSSName.

public Principal

Returns:

the associated principal, or null if there is none
authenticate
(X509Certificate[]
Array of client certificates, with the first one in the array being the certificate of the client itself.
certs
)

Try to authenticate using a chain of X509Certificates.

public void
backgroundProcess()

Execute a periodic task, such as reloading, etc. This method will be invoked inside the classloading context of this container.

public SecurityConstraint[]

Returns:

the configured SecurityConstraint, or null if there is none
findSecurityConstraints
(Request
Request we are processing
request
,
Context
Context the Request is mapped to
context
)

Find the SecurityConstraints configured to guard the request URI for this request.

public CredentialHandler

Returns:

the CredentialHandler configured for this Realm.
getCredentialHandler
()

public boolean

Returns:

true if this constraint is satisfied and processing should continue, or false otherwise
hasResourcePermission
(Request
Request we are processing
request
,
Response
Response we are creating
response
,
SecurityConstraint[]
Security constraint we are enforcing
constraint
,
Context
The Context to which client of this class is attached.
context
)

Perform access control based on the specified authorization constraint.

public boolean

Returns:

true if the specified Principal has the specified security role, within the context of this Realm; otherwise return false.
hasRole
(Wrapper
wrapper context for evaluating role
wrapper
,
Principal
Principal for whom the role is to be checked
principal
,
String
Security role to be checked
role
)

Check if the specified Principal has the specified security role, within the context of this Realm.

public boolean

Returns:

true if this constraint was not violated and processing should continue, or false if we have created a response already.
hasUserDataPermission
(Request
Request we are processing
request
,
Response
Response we are creating
response
,
SecurityConstraint[]
Security constraint being checked
constraint
)

Enforce any user data constraint required by the security constraint guarding this request URI.

public default boolean

Returns:

true if the realm is able to perform authentication
isAvailable
()

Return the availability of the realm for authentication.

public void
removePropertyChangeListener(PropertyChangeListener
The listener to remove
listener
)

Remove a property change listener from this component.

public void
setCredentialHandler(CredentialHandler credentialHandler)

Set the CredentialHandler to be used by this Realm.

Inherited from org.apache.catalina.Contained:
getContainersetContainer

Method Detail

addPropertyChangeListenerback to summary
public void addPropertyChangeListener(PropertyChangeListener listener)

Add a property change listener to this component.

Parameters
listener:PropertyChangeListener

The listener to add

authenticateback to summary
public Principal authenticate(String username)

Try to authenticate with the specified username.

Parameters
username:String

Username of the Principal to look up

Returns:Principal

the associated principal, or null if none is associated.

authenticateback to summary
public Principal authenticate(String username, String credentials)

Try to authenticate using the specified username and credentials.

Parameters
username:String

Username of the Principal to look up

credentials:String

Password or other credentials to use in authenticating this username

Returns:Principal

the associated principal, or null if there is none

authenticateback to summary
public Principal authenticate(String username, String digest, String nonce, String nc, String cnonce, String qop, String realm, String digestA2)

Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 2617 (which is a superset of RFC 2069).

Parameters
username:String

Username of the Principal to look up

digest:String

Digest which has been submitted by the client

nonce:String

Unique (or supposedly unique) token which has been used for this request

nc:String

the nonce counter

cnonce:String

the client chosen nonce

qop:String

the "quality of protection" (nc and cnonce will only be used, if qop is not null).

realm:String

Realm name

digestA2:String

Second digest calculated as digest(Method + ":" + uri)

Returns:Principal

the associated principal, or null if there is none.

Annotations
@Deprecated
authenticateback to summary
public default Principal authenticate(String username, String digest, String nonce, String nc, String cnonce, String qop, String realm, String digestA2, String algorithm)

Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 7616.

The default implementation calls authenticate(String, String, String, String, String, String, String, String) for backwards compatibility which effectively forces the use of MD5 regardless of the algorithm specified in the call to this method.

Implementations are expected to override the default implementation and take account of the algorithm parameter.

Parameters
username:String

Username of the Principal to look up

digest:String

Digest which has been submitted by the client

nonce:String

Unique (or supposedly unique) token which has been used for this request

nc:String

the nonce counter

cnonce:String

the client chosen nonce

qop:String

the "quality of protection" (nc and cnonce will only be used, if qop is not null).

realm:String

Realm name

digestA2:String

Second digest calculated as digest(Method + ":" + uri)

algorithm:String

The message digest algorithm to use

Returns:Principal

the associated principal, or null if there is none.

authenticateback to summary
public Principal authenticate(GSSContext gssContext, boolean storeCreds)

Try to authenticate using a GSSContext.

Parameters
gssContext:GSSContext

The gssContext processed by the Authenticator.

storeCreds:boolean

Should the realm attempt to store the delegated credentials in the returned Principal?

Returns:Principal

the associated principal, or null if there is none

authenticateback to summary
public Principal authenticate(GSSName gssName, GSSCredential gssCredential)

Try to authenticate using a GSSName.

Parameters
gssName:GSSName

The GSSName of the principal to look up

gssCredential:GSSCredential

The GSSCredential of the principal, may be null

Returns:Principal

the associated principal, or null if there is none

authenticateback to summary
public Principal authenticate(X509Certificate[] certs)

Try to authenticate using a chain of X509Certificates.

Parameters
certs:X509Certificate[]

Array of client certificates, with the first one in the array being the certificate of the client itself.

Returns:Principal

the associated principal, or null if there is none

backgroundProcessback to summary
public void backgroundProcess()

Execute a periodic task, such as reloading, etc. This method will be invoked inside the classloading context of this container. Unexpected throwables will be caught and logged.

findSecurityConstraintsback to summary
public SecurityConstraint[] findSecurityConstraints(Request request, Context context)

Find the SecurityConstraints configured to guard the request URI for this request.

Parameters
request:Request

Request we are processing

context:Context

Context the Request is mapped to

Returns:SecurityConstraint[]

the configured SecurityConstraint, or null if there is none

getCredentialHandlerback to summary
public CredentialHandler getCredentialHandler()
Returns:CredentialHandler

the CredentialHandler configured for this Realm.

hasResourcePermissionback to summary
public boolean hasResourcePermission(Request request, Response response, SecurityConstraint[] constraint, Context context) throws IOException

Perform access control based on the specified authorization constraint.

Parameters
request:Request

Request we are processing

response:Response

Response we are creating

constraint:SecurityConstraint[]

Security constraint we are enforcing

context:Context

The Context to which client of this class is attached.

Returns:boolean

true if this constraint is satisfied and processing should continue, or false otherwise

Exceptions
IOException:
if an input/output error occurs
hasRoleback to summary
public boolean hasRole(Wrapper wrapper, Principal principal, String role)

Check if the specified Principal has the specified security role, within the context of this Realm.

Parameters
wrapper:Wrapper

wrapper context for evaluating role

principal:Principal

Principal for whom the role is to be checked

role:String

Security role to be checked

Returns:boolean

true if the specified Principal has the specified security role, within the context of this Realm; otherwise return false.

hasUserDataPermissionback to summary
public boolean hasUserDataPermission(Request request, Response response, SecurityConstraint[] constraint) throws IOException

Enforce any user data constraint required by the security constraint guarding this request URI.

Parameters
request:Request

Request we are processing

response:Response

Response we are creating

constraint:SecurityConstraint[]

Security constraint being checked

Returns:boolean

true if this constraint was not violated and processing should continue, or false if we have created a response already.

Exceptions
IOException:
if an input/output error occurs
isAvailableback to summary
public default boolean isAvailable()

Return the availability of the realm for authentication.

Returns:boolean

true if the realm is able to perform authentication

removePropertyChangeListenerback to summary
public void removePropertyChangeListener(PropertyChangeListener listener)

Remove a property change listener from this component.

Parameters
listener:PropertyChangeListener

The listener to remove

setCredentialHandlerback to summary
public void setCredentialHandler(CredentialHandler credentialHandler)

Set the CredentialHandler to be used by this Realm.

Parameters
credentialHandler:CredentialHandler

the CredentialHandler to use