서비스 계층의 메서드 수준에서 Spring @PreAuthorize를 사용하여 사용자 지정 메서드를 호출하려고하지만 사용자 지정 메서드가 호출되지 않습니다. 내 코드 :사용자 지정 메서드로 @PreAuthorization 주석이 작동하지 않습니다.
스프링 애플리케이션의 context.xml :
<context:component-scan base-package="com.dice" />
<sec:global-method-security pre-post-annotations="enabled"/>
구성 요소 정의 : 구성 요소의
@InjectParam
CustomerUtil customerUtil;
@GET
@Path("/{customerId}/")
@Produces(MediaType.APPLICATION_JSON)
public Response getCustomerInfo(@PathParam("customerId") Integer customerId,
@DefaultValue("") @QueryParam("fields") String partialResponseFields) {
logger.debug("getCustomerInfo called: id: " + customerId + ", uriInfo = " + uriInfo.getPath());
try {
return buildOKResourceResponse(new CustomerActionResource(customerUtil.getCustomerInfo(uriInfo, customerId)),partialResponseFields);
사용 : 폴더의 유틸리티 클래스를 호출
@Component(value="authorizationService")
public class AuthorizationService implements AuthorizationServiceInt {
public boolean test(String key) {
logger.debug("AUTHORIZATION CALLED: " + key);
return false;
}
}
컨트롤러 :
@InjectParam
AuthorizationService svc;
@PreAuthorize("@authorizationService.test('special')")
public Customer getCustomerInfo(UriInfo uriInfo, Integer id) {
logger.debug("svc: " + svc.hasPermission("x"));
return populateCustomerInfo(uriInfo, PstUserModelServiceUtil.getPstUserModelByPstUserId(id));
}
AuthorizationService 클래스가 Spring에 의해 인식되는지 확인하기 위해 InjectParam을 포함 시켰습니다. 그리고 확실히, 주입 된 클래스를 통해 호출 할 때 'AUTHORIZATION CALLED'디버그 문이 표시되지만 @PreAuthorization 호출을 통해 호출 될 때는 표시되지 않습니다.
내 스프링 항아리 : 내가 잘못 뭐하는 거지
spring-aop-3.2.0.RELEASE.jar
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-context-support-3.2.2.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-data-commons-1.5.0.RELEASE.jar
spring-data-solr-1.0.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
spring-jdbc-3.2.0.RELEASE.jar
spring-orm-3.2.0.RELEASE.jar
spring-security-acl-3.1.4.RELEASE.jar
spring-security-config-3.1.4.RELEASE.jar
spring-security-core-3.1.4.RELEASE.jar
spring-security-oauth2-1.1.0.BUILD-SNAPSHOT.jar
spring-security-taglibs-3.1.4.RELEASE.jar
spring-security-web-3.1.4.RELEASE.jar
spring-tx-3.2.0.RELEASE.jar
spring-web-3.2.2.RELEASE.jar
spring-webmvc-3.2.2.RELEASE.jar
? 구성 요소 클래스와 클래스 모두에 대한 인터페이스를 가지고 있는데, 그 중 하나는 AOP로 읽었을 때, Spring은 기본 구현을보기 위해 스프링에 인터페이스가 필요한 impl 클래스를 데코레이션한다는 사실입니다.
getCustomerInfo() 메소드에 대한 스프링 컨트롤러 호출로 원래 게시물을 업데이트했습니다. 그리고 저는 관련이없는 영역으로 방향을 돌리고 있습니다 만, InowParam을 사용하여 Autowired를 사용할 때 예외가 발생하는 것을 수정해야했습니다. 저지 InjectParam을 사용하여 CustomerUtil 객체에 문제를 주입합니까? 그 객체는 Autowired 대신에 주석을 사용할 때 Spring에 의해 생성되지 않습니다. – Tracy
감사! 나는 '@InjectParam CustomerUtil'이 문제라고 믿습니다. 우리는 CustomerUtil 클래스를 서비스 계층으로 옮기고 spring-context.xml을 통해 빈을 삽입 한 다음 servlce 로케이터 클래스를 사용하여 빈을 찾을 계획이었다. 그래서 나는 앞서 나가서 한 번 해봤고 (그리고 Spring이 bean을 생성하도록 허용했습니다) PreAuthorize 주석은 매력처럼 시작되었습니다. – Tracy