최근에 나는이 방법에 대한 액세스 권한을 제어하는 봄 보안을 사용하고 있습니다. 페이지에 액세스하면 @PreAuthorize에 지정된 인증 메소드를 트리거하여 사용자에게 전제가 있는지 여부를 판별 할 수 있습니다.예외 : 인증 개체가 SecurityContex에서 찾을 수 없습니다
는하지만 봄 예약 된 작업 (@Scheduled와 방법)을 사용하고, 그 방법은 세션 컨텍스트없이 자동으로 실행되는 것을 의미한다. 메서드가 @PreAuthorize를 사용하여 일부 함수를 호출하면 인증을 통과 할 수 없습니다. 액세스가 허용되는지 또는 거부되는지를 알려주는 "true"또는 "false"를 제공하지 않습니다. 다음과 같은 예외가 있습니다. 그것은 매우 짜증나!
============================================== ====================================
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:325)
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:196)
at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:64)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy40.refreshGlobalCacheStrategyMetrics(Unknown Source)
at org.sly.main.server.service.system.scheduling.MaintenanceServiceImpl.runRecreateStrategyMetricsCache(MaintenanceServiceImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:80)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.lang.Thread.run(Thread.java:662)
======= ========================================================================================================== =========================
나는 그것을 알아낼하려고 많은 페이지를 검색 한, 그러나 나는 마지막을 찾을 수 없습니다 그것을위한 해결책.
http://static.springsource.org/spring-security/site/faq.html#auth-exception-credentials-not-found
1.5 :
springsource.org에있는 페이지는 문제를 보여줍니다. "SecurityContext에서 인증 개체를 찾을 수 없습니다"라는 메시지가있는 예외가 발생합니다. 뭐가 문제 야?
이것은 익명 사용자가 보호 된 리소스에 액세스하려고 처음 발생하는 또 다른 디버그 수준의 메시지입니다,하지만 당신이 할 하지 않을 경우 필터 체인 구성에 AnonymousAuthenticationFilter 있습니다.
DEBUG [ExceptionTranslationFilter가] - 인증 예외가 발생; 조직에서 인증 객체가 org.springframework.security.intercept.AbstractSecurityInterceptor.credentialsNotFound (AbstractSecurityInterceptor.java:342)에서 SecurityContext에에서 찾을 수 없습니다 : 진입 점을
org.springframework.security.AuthenticationCredentialsNotFoundException을 인증 관련 리디렉션. 내가 다른 페이지를 찾을 수
그리고 springframework.security.intercept.AbstractSecurityInterceptor.beforeInvocation (AbstractSecurityInterceptor.java:254)를 구성하는 방법에 대해 설명합니다 AnonymousAuthenticationFilter http://static.springsource.org/spring-security/site/docs/3.0.x/reference/anonymous.html
,그것은 그의 구성이되어야한다 말합니다 :
<bean id="anonymousAuthFilter"
class="org.springframework.security.web.authentication.AnonymousAuthenticationFilter">
<property name="key" value="foobar"/>
<property name="userAttribute" value="anonymousUser,ROLE_ANONYMOUS"/>
</bean>
<bean id="anonymousAuthenticationProvider"
class="org.springframework.security.authentication.AnonymousAuthenticationProvider">
<property name="key" value="foobar"/>
</bean>
그래서 나는 내 응용 프로그램-security.xml에서 그것을 구성하지만 어떤 차이를하지 않습니다.
<beans:bean id="springSecurityFilterChain"
class="org.springframework.security.web.FilterChainProxy">
<security:filter-chain-map path-type="ant">
<security:filter-chain pattern="/**"
filters="anonymousAuthFilter" />
</security:filter-chain-map>
</beans:bean>
<!-- ///////////////////////////////////////// -->
<!-- ////for AnonymousAuthenticationFilter//// -->
<!-- ///////////////////////////////////////// -->
<beans:bean id="anonymousAuthFilter"
class="org.springframework.security.web.authentication.AnonymousAuthenticationFilter">
<beans:property name="key" value="foobar" />
<beans:property name="userAttribute" value="anonymousUser,ROLE_ANONYMOUS" />
</beans:bean>
<beans:bean id="anonymousAuthenticationProvider"
class="org.springframework.security.authentication.AnonymousAuthenticationProvider">
<beans:property name="key" value="foobar" />
</beans:bean>
봄 보안에 능숙한 사람이 있습니까? 내가 어떤 인증 프로세스가 없음을 볼 수있는 예외 구성에서