私は Java の濁った海に足を踏み入れ、PackPub JavaEE 6 With Netbeans7 bookに取り組んでいます。初期の例の 1 つはフォーム認証です。これには、セキュリティ ロール「admin」と制約を使用して展開記述子 (web.xml) を設定することが含まれます。次に、これらのロールを新しいグループに割り当てて Glassfish 記述子を取得し、Glassfish コンソールを使用してこれらのグループに新しいユーザーを作成する方法について説明します。
この保護されたページ内のページにアクセスしようとすると、期待どおりにログイン ページが表示されますが、ログインが機能しません。Glassfish コンソールで作成した有効な認証情報を入力していることはわかっていますが、ログイン エラー ページが表示されます (j_security_check URL でレンダリングされます)。
ログインページは基本的なものです。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Log in to view secure content</title>
</head>
<body>
<h1>Log in</h1>
<form action="j_security_check" method="POST">
<table border="0">
<tbody>
<tr>
<td slign="right">Username: </td>
<td><input type="text" name="j_username" value="" /></td>
</tr>
<tr>
<td slign="right">Password: </td>
<td><input type="password" name="j_password" value="" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login" /></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
私は何かを構成しておらず、おそらく非常に基本的なものですが、この本はこのような問題には役立たないので、この問題のデバッグまたは診断をどこから開始するかについての指針を得ることができるかどうか疑問に思いました.
私のweb.xmlは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<security-constraint>
<display-name>Admin Pages</display-name>
<web-resource-collection>
<web-resource-name>Administrative pages</web-resource-name>
<description/>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginerror.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Administrators</description>
<role-name>Admin</role-name>
</security-role>
<security-role>
<description>public user</description>
<role-name>User</role-name>
</security-role>
</web-app>
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>
<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>
Glassfishコンソールで再確認しましたが、編集中です
Configuartions|Security|Realms|file
私の新しいユーザーには「管理者」のグループリストがあります
ありがとう