주석 기반 메서드 수준 보안을 사용할 때 Spring 3.2.4를 사용 중이며 스프링 보안을 access-denied-handler
으로 리디렉션 할 수 없습니다. 이것에 대해 여러 가지 다른 게시물을 발견했지만, 현재까지 내가 찾은 해결책이없는 것 같습니다.스프링 보안 메서드 수준 보안을 사용하는 액세스 거부 처리기를 무시합니다.
내 security.xml 파일 :
<!-- need this here to be able to secure methods in components other than controllers (as scanned in applicationContext.xml) -->
<global-method-security secured-annotations="enabled" pre-post-annotations="enabled" jsr250-annotations="enabled" ></global-method-security>
<!-- Annotation/JavaConfig examples http://stackoverflow.com/questions/7361513/spring-security-login-page -->
<http use-expressions="true" entry-point-ref="authenticationEntryPoint">
<access-denied-handler ref="accessDeniedHandler"/>
<intercept-url pattern="/secure/login" access="permitAll" />
<intercept-url pattern="/secure/logout" access="permitAll" />
<intercept-url pattern="/secure/denied" access="permitAll" />
<session-management session-fixation-protection="migrateSession" session-authentication-error-url="/login.jsp?authFailed=true">
<concurrency-control max-sessions="10" error-if-maximum-exceeded="true" expired-url="/login.html" session-registry-alias="sessionRegistry"/>
</session-management>
<intercept-url pattern="/**" access="isAuthenticated()" />
<form-login default-target-url="/" authentication-failure-url="/secure/denied" />
<logout logout-url="/secure/logout" logout-success-url="/" />
<expression-handler ref="defaultWebSecurityExpressionHandler" />
</http>
<beans:bean id="authenticationEntryPoint" class="com.ia.security.LoginUrlAuthenticationEntryPoint">
<beans:constructor-arg name="loginFormUrl" value="/secure/login"/>
</beans:bean>
<beans:bean id="accessDeniedHandler" class="com.ia.security.AccessDeniedHandlerImpl">
<beans:property name="errorPage" value="/secure/denied"/>
</beans:bean>
내 AccessDeniedHandlerImpl.java :
public class AccessDeniedHandlerImpl extends org.springframework.security.web.access.AccessDeniedHandlerImpl {
// SLF4J logger
private static final Logger logger = LoggerFactory.getLogger(AccessDeniedHandlerImpl.class);
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
logger.log("AccessDeniedException triggered!");
super.handle(request, response, accessDeniedException);
}
}
내 주석 방법 : 나는하도록 할 필요가 특별한 아무것도
@PreAuthorize("hasAuthority('ROLE_ZZZZ')")
public ModelAndView getUserInfo(@PathVariable long userId){
ModelAndView mv = new ModelAndView();
User u = userService.findUser(userId);
mv.addObject("user", u);
return mv;
}
있는가 내 액세스 거부 처리기가 호출됩니까?
아직받지 못했습니다. 또한 정확하게 설명했지만 문제가 발생하지 않았습니다. ( – Cataclysm
javaconfig? – Vivek
@Eric이 솔루션에 대한 Java Config를 공유 할 수 있습니까? –