0

Glassfish v3と非常に単純なJAX-RSサービス(http://www.vogella.de/articles/REST/article.htmlで取得)と戦っています。

私が達成したいのは、すべてのリソースの基本http認証を設定することです。ユーザーがhttp:// localhost:8080 / de.vogella.jersey.first / rest / helloを要求したときに必要な場合は、ブラウザーにユーザー名とパスワードの入力を求めるアラートがポップアップ表示されます。

JDBCRealm認証を選択することにしました。PostgreSQL8.4と正しいJDBCドライバーを使用しています。

私の問題は、認証がアクティブになっていないように見えることです(HTTPヘッダーは非常に単純なものです:

Request URL:http://localhost:8080/de.vogella.jersey.first/rest/hello

Request Method:GET
Status Code:200 OK
Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:JSESSIONID=ec48541dc7654806fcf022d79e66; treeForm:tree-hi=treeForm:tree:configuration:loggerSetting
Host:localhost:8080
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.187 Safari/535.1

Response Headers
Content-Type:text/html
Date:Fri, 07 Oct 2011 14:26:26 GMT
Server:GlassFish Server Open Source Edition 3.0.1
Transfer-Encoding:chunked
X-Powered-By:Servlet/3.0

認証は設定されていますが、非アクティブのようです。その時点で、私が間違ったことを分析するためのあなたのスキルが必要です。

私がこれまでにしたこと:

1 / JAX-RSサービスをデプロイしました(これは問題なく動作します。前のURLを参照してください)2/データベースを作成し、2つのテーブルを作成しました:

CREATE TABLE groups
(
  username character varying(16) NOT NULL,
  id character varying(20) NOT NULL,
  CONSTRAINT groups_pkey PRIMARY KEY (username, id),
  CONSTRAINT fk_username FOREIGN KEY (username)
      REFERENCES users (username) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
);

CREATE TABLE users
(
  username character varying(16) NOT NULL,
  "password" character varying(32) NOT NULL,
  CONSTRAINT users_pkey PRIMARY KEY (username)
);

そして、次のようにそれらを入力しました:

テーブル"groups"->"webuser"; "employees"

テーブル"users"->"webuser"; "webuser"

3 / Glassfish管理GUIで、「postgres」と呼ばれる接続プールを次のように追加しました http://puu.sh/6DZV 。追加のプロパティを次に示します。 http://puu.sh/6E05

4 /次に、以下に示すように、「postgres」というJDVCリソースを作成しました。 http://puu.sh/6E0H

5 / Glassfish管理GUIで、以下に示すように、「postgres」と呼ばれるセキュリティレルムを追加しました。 http://puu.sh/6E1b

6/「ロガー設定」でjavax.enterprise.system.core.securityのログレベルも「FINEST」に設定しました。ブラウザからWebサービスを要求した後、server.logファイルに次の情報が表示されます。

[#|2011-10-07T16:26:26.410+0200|FINE|glassfish3.0.1|javax.enterprise.system.core.security|_ThreadID=67;_ThreadName=Thread-1;ClassName=com.sun.enterprise.security.web.integration.WebSecurityManager;MethodName=setPolicyContext;|[Web-Security] Policy Context ID was: de.vogella.jersey.first/de_vogella_jersey_first|#]

[#|2011-10-07T16:26:26.412+0200|FINE|glassfish3.0.1|javax.enterprise.system.core.security.com.sun.enterprise.security|_ThreadID=67;_ThreadName=Thread-1;ClassName=com.sun.enterprise.security.SecurityContext;MethodName=setCurrentSecurityContext;|SecurityContext: setCurrentSecurityContext method called|#]

7 /コードに関しては、アノテーションを追加しませんでしたが、web.xmlを次のように更新しました。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>de.vogella.jersey.first</display-name>
  <servlet>
    <description>JAX-RS Tools Generated - Do not modify</description>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>de.vogella.jersey.first</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>customer creation</web-resource-name>
      <url-pattern>/rest/*</url-pattern>
       <http-method>GET</http-method>
       <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>webusers</role-name>
    </auth-constraint>
  </security-constraint>

  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>postgres</realm-name>
  </login-config>

  <security-role>
    <role-name>webusers</role-name>
  </security-role>

</web-app>

そして、sun-web.xmlは次のようになります:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
  <context-root>/de.vogella.jersey.first</context-root>
  <security-role-mapping>
    <role-name>webusers</role-name>
    <group-name>webusers</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>
</sun-web-app>

これの何が問題になっていますか?何か忘れましたか?

お時間をいただきありがとうございます!

4

1 に答える 1

0

「デプロイメント間のセッションを維持する」を無効にする必要があることがわかりました。このオプションは、配置サーバーをダブルクリックしてチェックボックスをオフにすることで、サーバーに表示されます。

于 2011-10-08T14:05:38.203 に答える