当前位置: 首页 > 知识库问答 >
问题:

具有登录名和密码或证书的身份验证

祁鸿哲
2023-03-14

我有一个Spring启动的应用程序,用户可以通过登录和密码或数字证书进行身份验证。我试图用用户和密码验证,但当我试图用证书验证时,chrome不显示窗口来选择我想在验证中使用的证书(我有几个证书,服务器是安全的,等等...)

有什么想法吗?我附上我的WebSecurity配置适配器的代码,以防我出错

> @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
@EnableWebSecurity
@Configuration
@RequiredArgsConstructor
@Slf4j
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {





    @Configuration
    @Order(2)
    public static class AdminSecurityConfig extends WebSecurityConfigurerAdapter {
        @Autowired
        CustomAuthenticationProvider customAuthProvider;

        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                    .mvcMatchers(PublicUrls.URLS).permitAll()
                    .anyRequest().fullyAuthenticated()
                    .and()
                    .formLogin()
                    .loginPage("/login")
                    .defaultSuccessUrl("/")
                    .permitAll()
                    .and()
                    .cors()
                    .and()
                    .logout()
                    .invalidateHttpSession(true)
                    .clearAuthentication(true)
                    .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                    .logoutSuccessUrl("/login?logout")
                    .permitAll();

        }
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.authenticationProvider(customAuthProvider);
        }
    }
        @Configuration
        @Order(1)
        public static class UserSecurityConfig extends WebSecurityConfigurerAdapter {


            @Autowired
            CustomAuthenticationProvider2 customAuthProvider2;


            @Override
            protected void configure(HttpSecurity http) throws Exception {

                http.antMatcher("/loginCert*").authorizeRequests()
                        .mvcMatchers(PublicUrls.URLS).permitAll()
                        .anyRequest().fullyAuthenticated()
                        .and().x509()
                        .subjectPrincipalRegex("CN=(.*?)(?:,|$)")
                        .userDetailsService(userDetailsService());
            }

            protected void configure(AuthenticationManagerBuilder auth) throws Exception {
                auth.authenticationProvider(customAuthProvider2);
            }

        }




    @Bean("authenticationManager")
    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }

配置属性包括:

服务器ssl。密钥存储=存储/密钥存储。jks服务器。ssl。密钥存储密码=更改IT服务器。ssl。密钥别名=本地主机服务器。ssl。密钥密码=更改IT服务器。ssl。enabled=true服务器。ssl。客户端身份验证=需要服务器。端口=8443

共有1个答案

耿玄裳
2023-03-14

要使浏览器提示您输入客户端证书,您需要在应用程序中设置以下Spring属性。使用嵌入式tomcat时的属性

server.ssl.client-auth=need

对于专用tomcat,您需要在服务器中设置以下属性。xml

clientAuth="want"

请参阅以下教程,了解如何设置双向SSL认证

https://www.baeldung.com/x-509-authentication-in-spring-security

 类似资料:
  • 当使用Firebase身份验证匿名帐户时,它偶尔会在系统中创建一个新的用户ID,有时它会使用相同的用户ID。我真的希望每次都能创建相同的用户ID,这样匿名用户仍然可以在应用程序中维护相同的进度/数据。这实际上是我开始使用Firebase的原因。即使在重新启动应用程序等之后,我如何始终维护一个匿名帐户来保持相同的用户ID? 我希望用户每次以访客身份玩游戏时都能获得相同的ID。我看到有些应用程序在卸载

  • 使用,https://github.com/firebase/FirebaseUI-Android/tree/master/codelabs/chat作为登录的参考,我在键入时似乎遇到了问题 我只能键入Auth的提供者,而不能键入,为什么会这样,它提示我键入社会提供者。

  • 我有一个客户端服务器场景。 我有厚客户端和瘦客户端(浏览器),它们与我的服务器进行通信。 我的胖客户端使用X-509系统证书进行客户端证书身份验证,并与服务器通信 此外,此证书用于生成签名URL(带过期时间),以便我的瘦客户机与服务器通信,用于完整性和授权目的。在这种情况下,我也有一个基于令牌的方法用于身份验证。 现在,我想使用客户端凭据或基于身份验证代码将身份验证机制移动到基于OAuth的流。

  • 问题内容: 我是新手,由于良好的在线评论,决定尝试一下。我正在尝试使用scrapy登录到一个网站。我已经通过selenium的组合成功登录了,并通过收集所需的selenium饼干并将其添加到机械化中进行了机械化。现在,我正在尝试对selenium和selenium进行类似的处理,但似乎无法使任何事情起作用。我什至无法分辨是否有任何工作。谁能帮帮我吗。我是从下面开始的。我什至不需要用曲奇的方式来传送

  • 问题内容: 我正在开发Flask应用程序,并使用Flask-security进行用户身份验证(反过来又在下面使用Flask-login)。 我有一条需要身份验证的路由。我正在尝试编写一个单元测试,该测试对经过身份验证的用户返回适当的响应。 在单元测试中,我正在创建一个用户并以该用户身份登录,如下所示: 在测试内返回正确的用户。但是,请求的视图始终返回的。 所述路线定义为: 我可以肯定我只是不完全了

  • 我想在讲Grails的REST中设置基于证书的登录身份验证。 按照Burt Beckwith的文档,我使用Spring Security插件(spring-security-core:2.0-RC3)来设置X509身份验证: 生成证书文件和Tomcat配置似乎有点棘手,但已经在另一个答案中指出。我这样做了,并使用当前标准配置Tomcat 7,首先是keystoreFile、keystorePass