无法使用Spring OpenID成功登录

时间:2012-12-13 17:31:47

标签: spring spring-mvc spring-security openid

我在spring-security.xml

中有以下代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/security 
            http://www.springframework.org/schema/security/spring-security-3.1.xsd">


    <security:http security="none" pattern="/openid.jsp" />
    <security:http security="none" pattern="/logout.jsp" />
    <security:http security="none" pattern="/success.jsp" />

    <security:http auto-config="true"
        authentication-manager-ref="authManager">
        <security:intercept-url pattern="/**" access="ROLE_USER"/>
        <security:openid-login login-page="/openid.jsp" 
            authentication-failure-url="/logout.jsp"
            default-target-url="/success.jsp" >
        </security:openid-login>
    </security:http>


    <security:authentication-manager id="authManager">
        <security:authentication-provider>
            <security:user-service>
                <security:user name="spring" password="spring"
                    authorities="ROLE_USER" />
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager> 

</beans>

Tomcat访问日志确实显示Google已对openid进行了身份验证,但在允许从Google开放ID页面访问后,我仍然点击了logout.jsp。

127.0.0.1 - - [13/Dec/2012:22:55:44 +0530] "GET /SpringWebSecurityOpenID/getEmp.do/10 HTTP/1.1" 302 35
127.0.0.1 - - [13/Dec/2012:22:55:44 +0530] "GET /SpringWebSecurityOpenID/openid.jsp HTTP/1.1" 200 258
127.0.0.1 - - [13/Dec/2012:22:55:49 +0530] "POST /SpringWebSecurityOpenID/j_spring_openid_security_check HTTP/1.1" 302 35
127.0.0.1 - - [13/Dec/2012:22:55:50 +0530] "GET /SpringWebSecurityOpenID/j_spring_openid_security_check?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=id_res&openid.op_endpoint=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fud&openid.response_nonce=2012-12-13T17cwcwc4rf32dwfdwGJ5oVQ_g&openid.return_to=http%3A%2F%2Flocalhost%3A8080%2FSpringWebSecurityOpenID%2Fj_spring_openid_security_check&openid.assoc_handle=AMlYA9UzE_QF5BKDYtD-k3_TbEdofnp7-43i9om-guRWh1TG5LhzEN7lzPyJ0IXzTjtNDbZz&openid.signed=op_endpoint%2Cclaimed_id%2Cidentity%2Creturn_to%2Cresponse_nonce%2Cassoc_handle&openid.sig=4MN6wuiKCWkuNwfwfwfd32dddqwg%3D&openid.identity=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%cwcwc34r2dwefreWzH1fBOWj5v4U&openid.claimed_id=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid432432EdewedrUfrp0nP3AWzH1fBOWj5v4U HTTP/1.1" 302 35
127.0.0.1 - - [13/Dec/2012:22:55:50 +0530] "GET /SpringWebSecurityOpenID/logout.jsp HTTP/1.1" 200 102

请。帮助解决此问题。如果我删除openid登录页面属性并使用Spring生成的默认开放id表单,那么我可以轻松地进行身份验证并点击请求的URL。

上面有更新spring-security.xml代码。日志中看到的例外是:

2012-12-16 11:26:32,430&#123;HH&#58;mm&#58;ss&#125; DEBUG &#91;http-bio-8080-exec-4&#93; &#40;ConsumerManager.java&#58;1788&#41;
- Local signature verification succeeded.
2012-12-16 11:26:32,430&#123;HH&#58;mm&#58;ss&#125;  INFO &#91;http-bio-8080-exec-4&#93; &#40;ConsumerManager.java&#58;1848&#41;
- Verification succeeded for: https://www.google.com/accounts/o8/id?id=AItOawl2FdNxxWJLrUfrp0nP3AWzH1fBOWj5v4U
2012-12-16 11:26:32,433&#123;HH&#58;mm&#58;ss&#125; DEBUG &#91;http-bio-8080-exec-4&#93; &#40;ProviderManager.java&#58;152&#41; -
 Authentication attempt using org.springframework.security.openid.OpenIDAuthenticationProvider
2012-12-16 11:26:32,434&#123;HH&#58;mm&#58;ss&#125; DEBUG &#91;http-bio-8080-exec-4&#93; &#40;AbstractAuthenticationProcessingFil
ter.java&#58;340&#41; - Authentication request failed: org.springframework.security.core.userdetails.UsernameNotFoundException: h
ttps://www.google.com/accounts/o8/id?id=AItOawl2FdNxxWJLrUfrp0nP3AWzH1fBOWj5v4U
2012-12-16 11:26:32,434&#123;HH&#58;mm&#58;ss&#125; DEBUG &#91;http-bio-8080-exec-4&#93; &#40;AbstractAuthenticationProcessingFil
ter.java&#58;341&#41; - Updated SecurityContextHolder to contain null Authentication
2012-12-16 11:26:32,435&#123;HH&#58;mm&#58;ss&#125; DEBUG &#91;http-bio-8080-exec-4&#93; &#40;AbstractAuthenticationProcessingFil
ter.java&#58;342&#41; - Delegating to authentication failure handlerorg.springframework.security.web.authentication.SimpleUrlAuth
enticationFailureHandler@e9927a

我是否需要在spring-security.xml中添加要进行身份验证的用户。我试图允许任何有效的openid登录。我没有任何要验证的用户列表。

1 个答案:

答案 0 :(得分:1)

对于您的拦截器网址,请尝试使用此代替角色。

<security:intercept-url pattern="/**" access="isFullyAuthenticated()"/>