public class OdbRealm
extends org.apache.catalina.realm.RealmBase
OdbRealm allows a web application to authenticate users against an embedded or standalone OrientDB database. It was
originally written to authenticate only against the built-in OUser
and ORole
classes but
the authentication is now configurable by a query.
It takes an OSQL query string as a attribute named query
which must return the password hash and the
roles for a user.
The query must:
String
for the user with a parameter name of, "password"List
of String
s with a parameter name of, "roles"
The password is checked using the method OSecurityManager.checkPassword(String, String)
. It checks for three
different types of password hashes by looking at the prefix of the string. They are:
{SHA-256}-
){PBKDF2WithHmacSHA1}-
){PBKDF2WithHmacSHA256}-
)
The simplest way to create a password hash in the correct format is to use the method
OUser.encryptPassword(String)
.
Important things to note for OdbRealm configuration are:
className
attribute must have a value of "com.ashtonit.odb.realm.OdbRealm
".dbUser
attribute must be the name of a database user with read access to the user
class for this realm. The "admin" user can be used for this for development and testing purposes.dbResource
attribute must match the value of the "name
" attribute in
your OdbResource configuration. If it is not present the realm creates its own instance of
OPartitionedDatabasePool
with the default capacity of 100.dbUrl
attribute must be a valid OrientDB URI.query
attribute must be an OSQL query string that takes one parameter (a user
identifier) and returns the password hash and roles.An example OdbRealm definition:
<Realm className="com.ashtonit.odb.realm.OdbRealm" dbPass="admin" dbResource="opdpfactory" dbUrl="plocal:/opt/odb/mydb" dbUser="admin" query="SELECT password, roles.name AS roles FROM OUser WHERE status = 'ACTIVE' AND name = ?" />
Modifier and Type | Field and Description |
---|---|
protected static String |
info |
protected static String |
name |
allRolesMode, container, containerLog, digest, digestEncoding, md, md5Helper, realmPath, sm, stripRealmForGss, support, validate, x509UsernameRetriever, x509UsernameRetrieverClassName
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
Constructor and Description |
---|
OdbRealm() |
Modifier and Type | Method and Description |
---|---|
Principal |
authenticate(GSSContext gssContext,
boolean storeCred)
This method of authentication is not supported by this implementation.
|
Principal |
authenticate(String username)
This method of authentication is not supported by this implementation.
|
Principal |
authenticate(String username,
String password)
Authenticates a database user.
|
Principal |
authenticate(String username,
String clientDigest,
String nonce,
String nc,
String cnonce,
String qop,
String realm,
String md5a2)
This method of authentication is not supported by this implementation.
|
Principal |
authenticate(X509Certificate[] certs)
This method of authentication is not supported by this implementation.
|
protected String |
getName()
Return a short name for this Realm implementation, for use in log messages.
|
protected String |
getPassword(String username)
This method is not supported by this implementation.
|
protected Principal |
getPrincipal(String username)
This method is not supported by this implementation.
|
void |
setDbPass(String dbPass)
The password for the generic user to connect to the database with so that we can look up the principal.
|
void |
setDbResource(String dbResource)
Sets the name of an arbitrary database resource instance.
|
void |
setDbUrl(String dbUrl)
Sets the URL for the OrientDB database.
|
void |
setDbUser(String dbUser)
Sets the generic username to connect to the database with so that we can look up the principal.
|
void |
setQuery(String query)
Sets the SQL query used to select the password and roles for the given user name.
|
addPropertyChangeListener, backgroundProcess, compareCredentials, digest, Digest, findSecurityConstraints, getAllRolesMode, getContainer, getCredentialHandler, getDigest, getDigest, getDigestCharset, getDigestEncoding, getDomainInternal, getObjectNameKeyProperties, getPrincipal, getPrincipal, getRealmPath, getRealmSuffix, getServer, getTransportGuaranteeRedirectStatus, getValidate, getX509UsernameRetrieverClassName, hasMessageDigest, hasResourcePermission, hasRole, hasUserDataPermission, initInternal, isStripRealmForGss, main, removePropertyChangeListener, setAllRolesMode, setContainer, setCredentialHandler, setDigest, setDigestEncoding, setRealmPath, setStripRealmForGss, setTransportGuaranteeRedirectStatus, setValidate, setX509UsernameRetrieverClassName, startInternal, stopInternal, toString
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister
protected static final String info
protected static final String name
public Principal authenticate(GSSContext gssContext, boolean storeCred) throws UnsupportedOperationException
authenticate
in interface org.apache.catalina.Realm
authenticate
in class org.apache.catalina.realm.RealmBase
UnsupportedOperationException
- when calledRealmBase.authenticate(GSSContext, boolean)
public Principal authenticate(String username) throws UnsupportedOperationException
authenticate
in interface org.apache.catalina.Realm
authenticate
in class org.apache.catalina.realm.RealmBase
UnsupportedOperationException
- when calledRealmBase.authenticate(String)
public Principal authenticate(String username, String password)
authenticate
in interface org.apache.catalina.Realm
authenticate
in class org.apache.catalina.realm.RealmBase
username
- the username to authenticatepassword
- the password associated with the usernameRealmBase.authenticate(String, String)
public Principal authenticate(String username, String clientDigest, String nonce, String nc, String cnonce, String qop, String realm, String md5a2) throws UnsupportedOperationException
authenticate
in interface org.apache.catalina.Realm
authenticate
in class org.apache.catalina.realm.RealmBase
UnsupportedOperationException
- when calledRealmBase.authenticate(String, String, String, String, String, String, String, String)
public Principal authenticate(X509Certificate[] certs) throws UnsupportedOperationException
authenticate
in interface org.apache.catalina.Realm
authenticate
in class org.apache.catalina.realm.RealmBase
UnsupportedOperationException
- when calledRealmBase.authenticate(X509Certificate[])
public void setDbPass(String dbPass)
dbPass
- the password for the generic userpublic void setDbResource(String dbResource)
If present the realm will use it to look up the OPartitionedDatabasePoolFactory
in the Tomcat JNDI
service and obtain a pool from it.
If it is not present the realm will create a new OPartitionedDatabasePool
with the default capacity of
100.
dbResource
- the JNDI name of the resourcepublic void setDbUrl(String dbUrl)
dbUrl
- the URL for the OrientDB databasepublic void setDbUser(String dbUser)
dbUser
- the generic username to connect to the databasepublic void setQuery(String query)
query
- the query used to select the password and roles for the given user nameprotected String getName()
getName
in class org.apache.catalina.realm.RealmBase
RealmBase.getName()
protected String getPassword(String username) throws UnsupportedOperationException
getPassword
in class org.apache.catalina.realm.RealmBase
UnsupportedOperationException
- when calledRealmBase.getPassword(String)
protected Principal getPrincipal(String username) throws UnsupportedOperationException
getPrincipal
in class org.apache.catalina.realm.RealmBase
UnsupportedOperationException
- when calledRealmBase.getPrincipal(String)
Copyright © 2016. All rights reserved.