2013-03-28 177 views
0

尊敬的全部, 新的是Spring Security。我已經配置了我的服務器來檢查Spring Security的登錄。現在我將它部署在某個服務器上並通過域名訪問它。我能夠訪問除SpringSecurity之外的所有網址。它檢查網址嗎?我怎樣才能改變它?彈簧安全問題

<intercept-url pattern="/login.do" access="fullyAuthenticated" /> 
    <form-login login-page="/index.do" always-use-default-target="false" default-target-url="/login.do" /> 
    <anonymous /> 
    <logout invalidate-session="true" logout-success-url="/index.do" logout-url="/j_spring_security_logout" /> 
    <custom-filter before="FORM_LOGIN_FILTER" ref="springSocialSecurityAuthenticationFilter" /> 
    <remember-me services-ref="springSocialSecurityRememberMeServices" key="springSocialSecurity" /> 
</http> 

感謝, OP

+0

分享你的春季安全配置 –

+0

我已經更新我的配置問題。請回復。 – Omprakash

+0

您使用的是什麼版本的Spring Security?您確實需要提供儘可能多的信息。 – ach

回答

0

首先,在intercept-url,你必須寫access="isFullyAuthenticated()"或使用Spring Security的常數:IS_AUTHENTICATED_FULLY

你的宣言是<intercept-url pattern="/login.do" access="fullyAuthenticated" /> 意義您必須登錄才能訪問login.do頁面。

我不認爲這是你想要的。

這裏的如何intercept-url作品一些例子:

<intercept-url pattern="/index.jsp" access="permitAll" /> 
    <intercept-url pattern="/secure/extreme/**" access="hasRole('supervisor')" /> 
    <intercept-url pattern="/secure/**" access="isAuthenticated()" /> 
    <intercept-url pattern="/listAccounts.html" access="isAuthenticated()" /> 
    <intercept-url pattern="/post.html" access="hasAnyRole('supervisor','regularuser')" /> 
    <intercept-url pattern="/**" access="denyAll" /> 

你必須定義一個基於應用程序的URL授權的水平。 要訪問登錄頁面,您需要讓登錄頁面爲permitAll訪問...所以用戶可以登錄。

如果用戶在未登錄的情況下嘗試訪問isAuthenticated()頁面,將會有重定向到登錄頁面。

您可以對模式進行多重訪問。例如,您可以決定一個頁面可以與認證或匿名角色訪問:

<intercept-url pattern='/page2.jsp' access='ROLE_ANONYMOUS,ROLE_USER'/> 
+0

感謝Rigg爲您提供的善意幫助和詳細信息。我的問題是,當我使用IP地址訪問我的應用程序時,它工作正常。就像這個222.222.222.222:8080/myApp,但是當我訪問同一個域名的應用程序。 www.domain.com/211,它不起作用。當我點擊url時,它重定向到apache服務器,然後是tomcat服務器。如果我在網址中保留web應用程序名稱,它就可以工作。但如果我在url中添加一些其他名稱,則不起作用。 – Omprakash

+0

好的,我不認爲這是一個彈簧安全問題。它可能來自服務器配置。你有在前面的Apache服務器重定向到你的Tomcat嗎?你使用HTTPS?你使用「網址重寫」? – Rigg802

+0

是的,這是真的。我有一個重定向到tomcat但HTTPS的Apache服務器。只有HTTP。我使用下面提到的腳本來重定向.. ProxyPass/abc http:// localhost:8080/xyz – Omprakash