Skip to content

Commit 9e28663

Browse files
committed
Form-based security sample is now working
1 parent 307610c commit 9e28663

File tree

5 files changed

+22
-144
lines changed

5 files changed

+22
-144
lines changed

servlet/form-based-security/src/main/java/org/javaee7/servlet/form/based/security/SecureServlet.java

Lines changed: 0 additions & 122 deletions
This file was deleted.

servlet/form-based-security/src/main/webapp/WEB-INF/web.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,28 @@
4545
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4646
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
4747
version="3.1">
48-
<deny-uncovered-http-methods/>
48+
<!--<deny-uncovered-http-methods/>-->
49+
<servlet>
50+
<display-name>index</display-name>
51+
<servlet-name>index</servlet-name>
52+
<jsp-file>/index.jsp</jsp-file>
53+
</servlet>
4954
<security-constraint>
5055
<web-resource-collection>
5156
<web-resource-name>SecurityConstraint</web-resource-name>
5257
<url-pattern>/*</url-pattern>
53-
<!--<http-method>GET</http-method>-->
5458
</web-resource-collection>
5559
<auth-constraint>
5660
<role-name>g1</role-name>
5761
</auth-constraint>
5862
<user-data-constraint>
59-
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
63+
<transport-guarantee>NONE</transport-guarantee>
6064
</user-data-constraint>
6165
</security-constraint>
6266

6367
<login-config>
6468
<auth-method>FORM</auth-method>
69+
<realm-name>file</realm-name>
6570
<form-login-config>
6671
<form-login-page>/loginform.jsp</form-login-page>
6772
<form-error-page>/loginerror.jsp</form-error-page>

servlet/form-based-security/src/main/webapp/index.jsp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,11 @@
4747
<html>
4848
<head>
4949
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
50-
<title>Servlet Form-Based Security</title>
50+
<title>Servlet Form-Based Security - Success</title>
5151
</head>
5252
<body>
53-
<h1>Servlet Form-Based Security</h1>
54-
55-
<form method="POST" action="j_security_check">
56-
<input type="text" name="j_username">
57-
<input type="password" name="j_password" autocomplete="off">
58-
<input type="button" value="submit">
59-
</form>
60-
61-
<p>Make sure to invoke "./bin/asadmin create-file-user --groups g1 u1" and use the password "p1" when prompted.
62-
Then call the <a href="${pageContext.request.contextPath}/SecureServlet">GET</a> method.<br/>
53+
<h1>Servlet Form-Based Security- Success</h1>
54+
55+
If you reached this page that means form-based security credentials are correctly configured.
6356
</body>
6457
</html>

servlet/form-based-security/src/main/webapp/loginerror.jsp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@
5555
<h2>Invalid user name or password.</h2>
5656

5757
<p>Please enter a user name or password that is authorized to access this
58-
application. For this application, make sure to invoke: <p><p>
59-
"./bin/asadmin create-file-user --groups g1 u1" and use the password "p1" when prompted.<p><p>
60-
Click here to <a href="/index.jsp">Try Again</a></p>
58+
application. For this application, make sure to create a user: <p><p>
59+
60+
For WildFly: Invoke "./bin/add-user.sh -a -u u1 -p p1 -g g1"<br>
61+
For GlassFish: Invoke "./bin/asadmin create-file-user --groups g1 u1" and use the password "p1" when prompted.<br><br>
62+
63+
Click here to <a href="index.jsp">Try Again</a></p>
6164

6265
</body>
6366
</html>

servlet/form-based-security/src/main/webapp/loginform.jsp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@
5353
<h1>Form-Based Login Page</h1>
5454

5555
<form method="POST" action="j_security_check">
56-
<input type="text" name="j_username">
57-
<input type="password" name="j_password" autocomplete="off">
58-
<input type="button" value="submit">
56+
Username: <input type="text" name="j_username"> <p/>
57+
Password: <input type="password" name="j_password" autocomplete="off"> <p/>
58+
<input type="submit" value="Submit">
59+
<input type="reset" value="Reset">
5960
</form>
6061

61-
<p>Make sure to invoke "./bin/asadmin create-file-user --groups g1 u1" and use the password "p1" when prompted.
62-
Then call the <a href="${pageContext.request.contextPath}/SecureServlet">GET</a> method.<br/>
6362
</body>
6463
</html>

0 commit comments

Comments
 (0)