これは、 Spring AOP を使用したMaksim Demidasのソリューションの開発です。
「アドバイスを投げる」タイプの Spring AOP アドバイスを定義します。@Secured
またはなどの他のアドバイスと正しく統合するために、インターフェース Ordered with HIGHEST_PRECEDENCE を実装します。@PreAuthorize
public class AccessDeniedExceptionInterceptor implements ThrowsAdvice, Ordered {
public void afterThrowing(AccessDeniedException e) throws GwtAccessDeniedException {
throw new GwtAccessDeniedException();
}
@Override
public int getOrder() {
return HIGHEST_PRECEDENCE;
}
}
Spring コンテキスト ファイルで、インターセプターを Bean として定義します。
<bean id="accessDeniedExceptionInterceptor" class="my.interceptor.package.AccessDeniedExceptionInterceptor"/>
Spring コンテキスト ファイルで、保護されたオブジェクトを構成します。この例では、特定の実装のすべてのパブリック メソッドが保護されています。
<!-- Configure global method security for the secured object -->
<security:global-method-security>
<security:protect-pointcut access="ROLE_USER"
expression="execution(public * my.service.package.ServiceImpl.*(..))"/>
</security:global-method-security>
サービス実装 Bean を定義します。
<bean id="rpcServiceTarget" class="my.service.package.ServiceImpl"/>
サービスのプロキシを定義し、インターセプターに接続します。
<bean id="rpcService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces" value="my.service.package.Service"/>
<property name="target" ref="rpcServiceTarget"/>
<property name="interceptorNames">
<list>
<value>accessDeniedExceptionInterceptor</value>
</list>
</property>
</bean>
以上です。プロキシを使用すると、Spring の AccessDeniedException からカスタム GwtAccessDeniedException に変換されます。