Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将X509证书身份验证与基于JWT令牌的身份验证一起使用_Java_Spring Boot_Spring Security_X509certificate_Jwt Auth - Fatal编程技术网

Java 将X509证书身份验证与基于JWT令牌的身份验证一起使用

Java 将X509证书身份验证与基于JWT令牌的身份验证一起使用,java,spring-boot,spring-security,x509certificate,jwt-auth,Java,Spring Boot,Spring Security,X509certificate,Jwt Auth,我有一个Spring引导应用程序当前使用X509证书身份验证。我可以同时使用JWT通过令牌和X509协议保护API和应用程序吗 用例: 应使用证书对公开/部署的应用程序URL进行身份验证,一旦验证,用户应提供有效的JWT令牌以访问应用程序内的任何API。我目前为我的X509证书配置了以下Web安全性 public class SecurityConfig extends WebSecurityConfigurerAdapter { @Value("${security.ena

我有一个Spring引导应用程序当前使用X509证书身份验证。我可以同时使用JWT通过令牌和X509协议保护API和应用程序吗

用例:

应使用证书对公开/部署的应用程序URL进行身份验证,一旦验证,用户应提供有效的JWT令牌以访问应用程序内的任何API。我目前为我的X509证书配置了以下Web安全性

public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${security.enable-csrf}")
    private boolean csrfEnabled;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().authenticated().and().x509().subjectPrincipalRegex("CN=(.*?)(?:,|$)")
                .userDetailsService(userDetailsService());
        
        if (!csrfEnabled) {
            http.csrf().disable();
        }
    }

    @Bean
    public UserDetailsService userDetailsService() {
        return (UserDetailsService) username -> {
            if (username.equals("XXXX")) {
                return new User(username, "", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
            } else {
                throw new UsernameNotFoundException(String.format("User %s not found", username));
            }
        };