I'm trying to make authentication with Payara, using Postgres 9.4. I've been following some tutorials but they don't work. I create a database, populate it, remember to hash the passwords (using MD-5), then a JDBC connection pool (ping works), then jdbc resources, a realm, next I create an java web application, I remember about web.xml, glassfish-web.xml, about login and error page.... and after deploying the application and trying to log in, I get an error page (the one that I created in the application).
Here's exactly what I do:
I created a database called "security":
CREATE TABLE "Group" (
group_id serial NOT NULL,
group_name text NOT NULL,
user_id int NULL,
CONSTRAINT Group_pk PRIMARY KEY (group_id)
);
CREATE TABLE Users (
user_id serial NOT NULL,
username text NOT NULL,
password text NOT NULL,
CONSTRAINT Users_pk PRIMARY KEY (user_id)
);
ALTER TABLE "Group" ADD CONSTRAINT Group_Users
FOREIGN KEY (user_id)
REFERENCES Users (user_id)
NOT DEFERRABLE
INITIALLY IMMEDIATE
;
I used an encryption website to encrypt my password, "test", and got the following value: 098f6bcd4621d373cade4e832627b4f6. I used that value to populate my database:
I use Payara Server. I create new JDBC connection pool, like on the picture. I get info " Ping Succeeded", so I assume this is part is ok.
I create a JDBC Resource, with JNDI Name: jdbc/simplesec, and Pool Name: secuPool.
I create a new realm, called "secuRealm" - pictures below. I suppose something may be wrong there? realm part 1 realm part 2 Next, I write the application part. (I select web application, java). glassfish-web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<security-role-mapping>
<role-name>admin</role-name>
<group-name>admin</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>guest</role-name>
<group-name>guest</group-name>
</security-role-mapping>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
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:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>secuRealm</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>
login.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Login</h1>
<form action="j_security_check" method="POST">
Username:<input type="text" name="j_username"/><br/>
Password:<input type="password" name="j_password" /><br />
<input type="submit" value="Login" />
<br/>
</form>
</body>
</html>
error.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Incorrect Credentials</h1>
Try again. <br/>
<a href="login.jsp">Login</a>
</body>
</html>
index.jsp :
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1><br />
<a href="login.jsp">Login</a>
</body>
</html>
After deploying the application I try to log in. Username: 1, password: test. I get an error.jsp page in response. I don't understand why, using correct user data, I cannot log in. Where did I make mistake and how to make it work?
尝试在领域设置中指定Digest Algorythm:none
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.