ここ、グーグル、スプリングソースでこれを検索しましたが、うまくいく解決策が見つかりませんでした。以下のspring-security.xmlがあり、パターンを使用すると
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
これにより、ログイン ページにリダイレクトするときに 404 エラーが発生します。しかし、私が使用すると、これは起こりません
<intercept-url pattern="/index*" access="hasRole('ROLE_USER')" />
しかし、これではアプリの残りの部分が保護されないことは明らかです。
これは私が見落としている単純なものだと確信していますが、私が見つけることができる最も近いものは、このスタックオーバーフローの質問でした. 私はこれをせずに試してuse-expressions="true"
みました.intercept-url
/**
アドバイス/ヘルプは素晴らしいでしょう
spring-security.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login" filters="none" access="permitAll" />
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="username" password="password" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
アップデート
念のため、私はSpringとSpring security 3.0.4.RELEASEを使用しています
答え
クリスのアドバイスに従って、私は変更しました
<intercept-url pattern="/login" filters="none" access="permitAll" />
に:
<intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" />
これにより、例外が原因で 500 エラーが発生しました
SpelEvaluationException: EL1008E:(pos 0): Field or property
'IS_AUTHENTICATED_ANONYMOUSLY' cannot be found on object of
type'org.springframework.security.web.access.expression.WebSecurityExpressionRoot
に変更することでこれを解決しましIS_AUTHENTICATED_ANONYMOUSLY
たisAnonymous()
<intercept-url pattern="/login" access="isAnonymous()" />