Java 使用现有数据库在Glassfish上实现JDBC身份验证
为了熟悉JavaWeb服务,我一直在编写一个示例Jersey程序,现在我想在其中添加一个安全层(server-Glassfish,IDE-IntelliJ)。到目前为止,我已经实现了一个基于表单的登录系统,该系统应该引用现有的Sybase数据库。问题是,即使我输入了正确的凭据,它也不会进行身份验证,而且我对身份验证的了解还不足以解决问题。希望这里有人能找出我哪里出了错。以下是我采取的步骤:Java 使用现有数据库在Glassfish上实现JDBC身份验证,java,authentication,jdbc,glassfish,sybase,Java,Authentication,Jdbc,Glassfish,Sybase,为了熟悉JavaWeb服务,我一直在编写一个示例Jersey程序,现在我想在其中添加一个安全层(server-Glassfish,IDE-IntelliJ)。到目前为止,我已经实现了一个基于表单的登录系统,该系统应该引用现有的Sybase数据库。问题是,即使我输入了正确的凭据,它也不会进行身份验证,而且我对身份验证的了解还不足以解决问题。希望这里有人能找出我哪里出了错。以下是我采取的步骤: 在Glassfish管理控制台中创建社区池和资源 在Glassfish管理控制台中创建JDBC领域 修改w
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="3.1">
<security-constraint>
<display-name>Admin Pages</display-name>
<web-resource-collection>
<web-resource-name>Secured</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<!--<deny-uncovered-http-methods/>-->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>JdbcRealm</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/loginerror.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<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>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
管理页面
安全的
/*
得到
邮递
管理
形式
JdbcRealm
/login.xhtml
/loginerror.xhtml
管理
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
*.xhtml
login.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui">
<body>
<p:panel header="Login From">
<form method="POST" action="j_security_check">
Username: <input type="text" name="j_username"/>
Password: <input type="password" name="j_password"/>
<input type="submit" value="Login" />
<input type="reset" value="Reset" />
</form>
</p:panel>
</body>
用户名:
密码:
如果你能做到这一点,谢谢你的阅读。非常感谢您的帮助。
我想出来了。在Glassfish中使用jdbc领域时,必须有两个独立的数据库:一个有用户/密码列表,另一个有用户列表(与以前的数据库相同)&它们属于哪个组。如果您不使用组,Glassfish将不会对您进行身份验证,即使您希望每个人都具有相同的权限