是否可以通过tomcat的默认身份验证方法制作一个使用JAAS身份验证的web应用程序?
举例说明:Tomcat使用tomcat_users.xml进行身份验证。web应用程序在jaas.cfg中定义了自己的方法。我们如何配置jaas.cfg,使其使用Tomcat的方法,以便当Tomcat中的配置改变时,应用程序的身份验证方法也随之改变。
当前配置如下:
BonitaAuth {
org.ow2.bonita.identity.auth.BonitaIdentityLoginModule required;
};
BonitaStore {
org.ow2.bonita.identity.auth.LocalStorageLoginModule required;
};
BonitaAuth-default {
org.ow2.bonita.identity.auth.BonitaIdentityLoginModule required domain="default";
org.ow2.bonita.identity.auth.LocalStorageLoginModule required domain="default";
};
BonitaStore-default {
org.ow2.bonita.identity.auth.LocalStorageLoginModule required domain="default";
};
/**
* Used by the REST server
*/
BonitaRESTServer {
org.ow2.bonita.identity.auth.BonitaRESTServerLoginModule required logins="restuser" passwords="restbpm" roles="restuser";
};
Tomcat用户存储库由Tomcat Realms定义。"tomcat_users.xml"文件供MemoryRealm
使用。要使用JAAS配置(JAAS .cfg),请配置JAASRealm
:http://tomcat.apache.org/tomcat - 7.0 - doc/realm howto.html # JAASRealm
可以使用Java EE身份验证并实现自己的领域。您有3个选项:
- 实现Tomcat
Realm
接口http://tomcat.apache.org/tomcat - 7.0 - doc/api/org/apache/catalina/realm.html - 扩展
RealmBase
http://tomcat.apache.org/tomcat - 7.0 doc/api/org/apache/catalina/realm/realmbase.html) - 扩展
JAASRealm
http://tomcat.apache.org/tomcat - 7.0 - doc/api/org/apache/catalina/realm/jaasrealm.html
在server.xml中配置您自己的域
<Realm className="org.myrealm"/>
Tomcat将调用您的身份验证方法http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/realm/RealmBase.html#authenticate%28java.lang.String,%20java.lang.String%29
在方法中可以调用JAAS身份验证。