2017-11-06 1 views
1

JAX-RS 2를 사용하는 경우 아래와 같이 간단합니다.예 : @RolesAllowed를 사용하여 JAX-RS 1 (저지) 인증

하지만 문제는 이전 버전을 사용하고 있습니다. 나는 그것을하는 방법을 모른다.

@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라는 두 가지 역할을 추가하는 방법을 보여줍니다.

<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> 
관련 문제