2017-11-06 3 views
1

JAX-RS 2を使用している場合は、以下のように簡単です。JAX-RS 1(ジャージー)での@RolesAllowedなどの許可

しかし、問題は前のバージョンを使用してこれを行うことです。私はそれをする方法を知らない。

@Provider 
public class SomeFilter implements ContainerRequestFilter { 

    @Context 
    private ResourceInfo resourceInfo; 

    @Override 
    public void filter(ContainerRequestContext requestContext) throws IOException { 
     Method method = resourceInfo.getResourceMethod(); 
    } 
} 

答えて

0

フィルタを使用する必要はありません。 web.xmlにセキュリティ制約auth-constraintを追加します。次のサンプルは、権限のある役割にstaffとcustomerという2つの役割を追加する方法を示しています。

<security-role> 
    <role-name>staff</role-name> 
</security-role> 
<security-role> 
    <role-name>customer</role-name> 
</security-role> 
<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Read-only REST requests</web-resource-name> 
     <url-pattern>/rest/weather/*</url-pattern> 
     <http-method>GET</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>customer</role-name> 
     <role-name>staff</role-name> 
    </auth-constraint> 
    <user-data-constraint> 
     <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 
<security-constraint> … </security-constraint> 
<login-config> 
    <auth-method>BASIC</auth-method> 
    <realm-name>file</realm-name> 
</login-config> 
関連する問題