LDAP Server
openldap
OpenLDAP安装与配置,参考 : https://www.ilanni.com/?p=13775
tomcat
修改tomcat/conf/server.xml,添加以下内容
1 <Realm className="org.apache.catalina.realm.JNDIRealm" 2 connectionURL="ldap://127.0.0.1:389" roleBase="ou=Group,dc=ilanni,dc=com" 3 roleName="cn" roleSearch="(memberUid={0})" 4 userPattern="uid={0},ou=People,dc=ilanni,dc=com" 5 />
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>test01</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <security-constraint> <web-resource-collection> <web-resource-name>admin</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>ldapgroup1</role-name> <role-name>ldapgroup2</role-name> </auth-constraint> </security-constraint> <security-role> <role-name>administrator</role-name> </security-role> <security-role> <role-name>ldapgroup1</role-name> </security-role> <security-role> <role-name>ldapgroup2</role-name> </security-role> <login-config> <auth-method>FORM</auth-method> <form-login-config> <form-login-page>/admin/login.jsp</form-login-page> <form-error-page>/admin/login-error.jsp</form-error-page> </form-login-config> </login-config> </web-app>