解決策を見つけました。もし誰かが興味があれば、ここでそれを説明します。
私は、ユーザー(この場合は、匿名ユーザー)が要求されたページにアクセスすることを許可されているかどうかをチェックするために、私のセッション管理フィルタでdoFilterメソッドに次のJavaコードを追加しました:
...
private WebInvocationPrivilegeEvaluator webPrivilegeEvaluator;
...
// Before this I have checked that the session is invalid and that the invalidSessionUrl parameter isn't null
String uri = request.getRequestURI();
String cPath = request.getContextPath();
int longCPath = cPath.length();
String pagSolicitada = uri.substring(longCPath);
Authentication autenticacion = SecurityContextHolder.getContext().getAuthentication();
if (!webPrivilegeEvaluator.isAllowed(pagSolicitada, autenticacion)) {
// Redirect to the invalidSessionUrl
redirectStrategy.sendRedirect(request, response, invalidSessionUrl);
return;
}
// Do nothing, just skip this filter
chain.doFilter(request, response);
return;
...
webPrivilegeEvaluatorがあります私は、XML設定ファイル内に注入したセッション管理フィルタのプロパティ:
<beans:bean id="filtroGestionSesion" class="springSecurity.FiltroGestionSesion">
<beans:constructor-arg name="securityContextRepository" ref="securityContextRepository" />
<beans:property name="sessionAuthenticationStrategy" ref="sas" />
<beans:property name="invalidSessionUrl" value="/faces/paginas/autenticacion/login.xhtml?error=timeout" />
<beans:property name="webPrivilegeEvaluator" ref="webPrivilegeEvaluator" />
</beans:bean>
とBeanは、このプロパティの参照があること:
<beans:bean id="webPrivilegeEvaluator" class="org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator">
<beans:constructor-arg ref="filterSecurityInterceptor" />
</beans:bean>
最後に、filterSecurityInterceptorが彼らのために必要なパターンとアクセスインターセプト-URLの要素を持っている(名前空間のHTTP要素にこれらのインターセプト、URLを入れないで、ちょうどここに置く):
<beans:bean id="filterSecurityInterceptor" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
<beans:property name="securityMetadataSource">
<filter-security-metadata-source use-expressions="true">
<!-- IMPORTANTE: Poner las URLs más específicas primero -->
<intercept-url pattern="/" access="permitAll"/> <!-- Página inicio al arrancar la aplic (contextPath) -->
<intercept-url pattern="/faces/inicio.xhtml" access="permitAll"/>
<intercept-url pattern="/faces/paginas/autenticacion/login.xhtml*" access="permitAll"/>
<intercept-url pattern="/faces/paginas/autenticacion/**" access="isAuthenticated()"/>
<intercept-url pattern="/faces/paginas/administracion/**" access="isAuthenticated()"/>
<intercept-url pattern="/faces/paginas/barco/**" access="isAuthenticated()"/>
<intercept-url pattern="/faces/paginas/catalogo/**" access="permitAll"/>
<intercept-url pattern="/faces/paginas/error/**" access="permitAll"/>
<intercept-url pattern="/faces/paginas/plantillas/**" access="permitAll"/>
<intercept-url pattern="/**" access="denyAll" />
</filter-security-metadata-source>
</beans:property>
<beans:property name="authenticationManager" ref="authenticationManager" />
<beans:property name="accessDecisionManager" ref="httpRequestAccessDecisionManager" />
<beans:property name="observeOncePerRequest" value="false" />
</beans:bean>
このフィルタは、フィルタチェーンの最後の一人として宣言する必要があり、この方法:
<custom-filter position="LAST" ref="filterSecurityInterceptor" />
注:私は意図的にこの答えが大きすぎることはありませために他のBeanの宣言を省略しました。
私はchoquero70の質問があります。 WebInvocationPrivilegeEvaluatorがコントローラメソッドの@PreAutorizeアノテーションについて知っているかどうか知っていますか? –