Jsf 2 JSF2.2.10,Tomcat8,JAAS登录失败
我试图使用JDBC领域在Tomcat8上实现JSF2JAAS登录。我已使用以下资源为JDBC登录配置了数据库中的表: My web.xml:Jsf 2 JSF2.2.10,Tomcat8,JAAS登录失败,jsf-2,jaas,tomcat8,Jsf 2,Jaas,Tomcat8,我试图使用JDBC领域在Tomcat8上实现JSF2JAAS登录。我已使用以下资源为JDBC登录配置了数据库中的表: My web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaL
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/login.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<security-constraint>
<web-resource-collection>
<web-resource-name>Views only available when logged in as ADMIN</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Views only available when logged in as USER</web-resource-name>
<url-pattern>/user/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/loginFail.xhtml</form-error-page>
</form-login-config>
</login-config>
<error-page>
<error-code>403</error-code>
<location>/error-pages/forbidden.xhtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error-pages/notFound.xhtml</location>
</error-page>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
错误发生在以下位置:
request.login(username, password);
错误为“登录失败”
如何使登录成功?您的
在哪里?你定义了一个领域吗?我忘记的是实现实际的JAAS登录模块lol。谢谢你的帮助
public void login() throws IOException {
ExternalContext externalContext = externalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
try {
request.login(username, password);
} catch (ServletException e) {
String loginErrorMessage = e.getLocalizedMessage();
facesContext().addMessage(null, new FacesMessage(loginErrorMessage));
}
}
request.login(username, password);