0

環境: GlassFish 3.1.2.2、JDK 6u31 を使用した Jersey 1.17。

web.xmlセキュリティ セグメント:

<security-constraint>
    <display-name>SSL transport</display-name>
    <web-resource-collection>
        <web-resource-name>Secure Area</web-resource-name>
        <description></description>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>USER</role-name>
        <role-name>ADMIN</role-name>
    </auth-constraint>
    <user-data-constraint>
        <description></description>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>myRealm</realm-name>
</login-config>

sun-web.xml :

<security-role-mapping>
    <role-name>USER</role-name>
    <group-name>USER</group-name>
</security-role-mapping>
<security-role-mapping>
    <role-name>ADMIN</role-name>
    <group-name>ADMIN</group-name>
</security-role-mapping>

インジェクションを使用してSecurityContextインスタンスを取得しています。

@Context
private SecurityContext sec;

これで、メソッドを使用して Web サービス メソッド内のロールを確認できるはずですがSecurityContext#isUserInRole(String role)、パラメーターとして何を指定しても、返される値は常にfalse.

メソッドを使用して、認証されたユーザーの名前を取得できますSecurityContext#getUserPrincipal()

ここで何が問題になる可能性がありますか?これを行う他の方法はありますか?

4

1 に答える 1