2016-03-25 24 views

回答

0

您可以使用匿名過濾器。事情是這樣的:

<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> 

再檢查這樣的:

<sec:authorize access="hasAnyRole('ROLE_ANONYMOUS')"> 

在這裏你可以找到更多的信息: https://docs.spring.io/spring-security/site/docs/3.0.x/reference/anonymous.html

1

此代碼用戶是否登錄或沒有,作品當使用匿名驗證時:

<sec:authorize access="isAuthenticated()"> 
    <!-- if user is authenticated--> 
</sec:authorize> 
<sec:authorize access="!isAuthenticated()"> 
    <!-- if user is not authenticated--> 
</sec:authorize>