Java OpenID Connect的Spring Security 5 XML配置

Java OpenID Connect的Spring Security 5 XML配置,java,xml,spring-security,spring-security-oauth2,openid-connect,Java,Xml,Spring Security,Spring Security Oauth2,Openid Connect,我们需要一个SpringSecurity5XML配置,以便在web应用程序中使用OpenIDConnect提供程序进行身份验证,但我只找到了SpringBoot的Java配置示例。 对于OpenID(不带connect!)、旧的oauth Spring安全扩展、oauth 2登录(不带OpenID)或第三方实现,web上有很多令人困惑的信息。 目前,我正在尝试将代码从OAuth2LoginConfiguler转换为XML,但这并不明显。例如,似乎没有AuthenticationEntryPoin

我们需要一个SpringSecurity5XML配置,以便在web应用程序中使用OpenIDConnect提供程序进行身份验证,但我只找到了SpringBoot的Java配置示例。 对于OpenID(不带connect!)、旧的oauth Spring安全扩展、oauth 2登录(不带OpenID)或第三方实现,web上有很多令人困惑的信息。
目前,我正在尝试将代码从OAuth2LoginConfiguler转换为XML,但这并不明显。例如,似乎没有AuthenticationEntryPoint。有人能为OpenID Connect提供一个有效的XML配置吗?

事实上,Spring Security 5不支持OAuth2Login配置的XML名称空间,并且可能不支持5.2版

与此相关的问题没有得到太多的支持,因此如果您希望看到它得到修复,我建议您表达您的支持

不幸的是,在即将发布的5.2版本中不会添加这种支持。5.2中还有其他更高优先级的项目。作为参考,我们根据用户需求对任务进行优先排序,鉴于在这个问题上只有2票赞成票,因此没有太多的需求。这并不意味着我们不会添加支持,只是意味着它在较低的优先级列表中

同时,我通过以下步骤为当前项目添加了OpenIDConnect 1.0支持。虽然项目是使用Spring 4实现的,我们已经能够将客户机与Spring Security 5和Spring Security OAuth 2.3.4结合使用。

在Spring Security中解决问题之前,我们混合使用Java配置和XML配置,以便能够在不编译的情况下更改参数,并为特定部署切换XML配置文件


授权代码

其他答案参考了Spring Security 5.3中解决的问题。 XML配置记录在文档中,例如:


测试用例中的一些示例:




该问题现已解决。SpringSecurity5.3中添加了XML配置支持
<http>
    <oauth2-login client-registration-repository-ref="clientRegistrationRepository"
              authorized-client-repository-ref="authorizedClientRepository"
              authorized-client-service-ref="authorizedClientService"
              authorization-request-repository-ref="authorizationRequestRepository"
              authorization-request-resolver-ref="authorizationRequestResolver"
              access-token-response-client-ref="accessTokenResponseClient"
              user-authorities-mapper-ref="userAuthoritiesMapper"
              user-service-ref="oauth2UserService"
              oidc-user-service-ref="oidcUserService"
              login-processing-url="/login/oauth2/code/*"
              login-page="/login"
              authentication-success-handler-ref="authenticationSuccessHandler"
              authentication-failure-handler-ref="authenticationFailureHandler"
              jwt-decoder-factory-ref="jwtDecoderFactory"/>
</http>
<http auto-config="true">
    <oauth2-client/>
</http>

<client-registrations>
    <client-registration registration-id="google"
                         client-id="google-client-id"
                         client-secret="google-client-secret"
                         redirect-uri="http://localhost/callback/google"
                         scope="scope1,scope2"
                         provider-id="google"/>
</client-registrations>
<http auto-config="true">
    <intercept-url pattern="/**" access="authenticated"/>
    <oauth2-login  login-page="/custom-login"/>
</http>
<client-registrations>
     <client-registration registration-id="google-login" client-id="google-client-id"
                     client-secret="google-client-secret" client-authentication-method="basic"
                     authorization-grant-type="authorization_code"
                     redirect-uri="{baseUrl}/login/oauth2/code/{registrationId}" scope="openid,profile,email"
                     client-name="Google" provider-id="google"/>
    <client-registration registration-id="github-login" client-id="github-client-id"
                     client-secret="github-client-secret" client-authentication-method="basic"
                     authorization-grant-type="authorization_code"
                     redirect-uri="{baseUrl}/login/oauth2/code/{registrationId}" scope="read:user"
                     client-name="Github" provider-id="github"/>
    <provider provider-id="google" authorization-uri="https://accounts.google.com/o/oauth2/v2/auth"
          token-uri="https://www.googleapis.com/oauth2/v4/token"
          user-info-uri="https://www.googleapis.com/oauth2/v3/userinfo" user-info-authentication-method="header"
          user-info-user-name-attribute="sub" jwk-set-uri="https://www.googleapis.com/oauth2/v3/certs"/>
    <provider provider-id="github" authorization-uri="https://github.com/login/oauth/authorize"
          token-uri="https://github.com/login/oauth/access_token" user-info-uri="https://api.github.com/user"
          user-info-authentication-method="header" user-info-user-name-attribute="id"/>
</client-registrations>