以下は私のセキュリティ設定です:
<security:http pattern="/login.*" security="none"/>
<security:http realm="myrealm">
<security:intercept-url pattern="/" access="ROLE_USER,ROLE_ADMIN,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR"/>
<security:intercept-url pattern="/*jsp" access="ROLE_USER,ROLE_ADMIN,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR"/>
<security:intercept-url pattern="/welcome.do" access="ROLE_ADMIN,ROLE_HD,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR,ROLE_USER,ROLE_SCANNER"/>
<security:intercept-url pattern="/*do" access="ROLE_ADMIN,ROLE_GROUPADMIN,ROLE_GROUP,ROLE_LOCMGR,ROLE_USER"/>
<security:form-login login-page="/login.do"
default-target-url="/welcome.do"
always-use-default-target="true"
authentication-failure-url="/login.do?login_error=1"/>
<security:logout logout-success-url="/login.do" />
<security:http-basic/>
<security:anonymous />
</security:http>
<bean id="authProvider" class="AuthenticationProvider">
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="authProvider"/>
</security:authentication-manager>
ログインページが表示されます。資格情報を入力して送信した後、リダイレクトされず、同じログインページが更新されます。DEBUGモードでは、次のことがわかります。Authenticated SCOTT on local database
間違ったログインパスワードでエラーメッセージが表示されます。パスワードをリセットするか、パスワードを忘れた場合のリンクも機能し、リダイレクトされます。しかし、welconmeページではありません
この時点では失敗しています。デバッグすると、プリンシパルにはrole_adminとして権限があり、パスワードには正しい値があります。しかし、この呼び出しnewAuth
の後にnull値があります!UsernamePasswordAuthenticationToken
Authentication newAuth = new UsernamePasswordAuthenticationToken(principal, password);
編集:私の設定では、私が使用していて、メソッドが3つのパラメーターを期待しているため、認証マネージャーを通過しようとして
authentication-manager
いUsernamePasswordAuthenticationToken
ました。
UsernamePasswordAuthenticationToken(object principal, object credentials, collection authorities);
これで問題は解決します!!