Настройка безопасности Spring Boot java не работает - PullRequest
0 голосов
/ 28 апреля 2020

Я сконвертировал свою конфигурацию XML для весенней защиты в конфигурацию Java для весенней загрузки. Вызовы серверных веб-служб и клиент переднего плана используют один и тот же сертификат. Конфигурация XML работала так, как я ожидаю, как для передней, так и для задней части. Но конфигурация Java не работает для клиентского интерфейса.

XML конфигурация

        <security:http use-expressions="true" auto-config="false">
            <security:x509 subject-principal-regex="CN=(.*?)," />

            <security:intercept-url method="GET" pattern="/admin/**" access="isAuthenticated() and hasAnyAuthority('ROLE_ADMINSUPPORT')"/>
            <security:intercept-url pattern="/services/**" access="isAuthenticated() and hasAnyAuthority('ROLE_ADMINSUPPORT','ROLE_SERVICESCLIENT')" />

<security:csrf disabled="true"/>

        </security:http>

        <security:authentication-manager alias="authenticationManager">
            <security:authentication-provider>
                <security:user-service>
                    <security:user name="something-test.someplace.net " authorities="ROLE_SERVICESCLIENT" />
                    <security:user name="something.someplace.net " authorities="ROLE_SERVICESCLIENT" />
                    <security:user name="App Production Support Cert" authorities="ROLE_ADMINSUPPORT,ROLE_LOGON,ROLE_SERVICESCLIENT" />                 
                </security:user-service>                
            </security:authentication-provider>
        </security:authentication-manager>              

Java конфигурация

@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.authorizeRequests().antMatchers("/css/**","/images/**","/javascript/**","/jsp/**");    


        httpSecurity.x509().subjectPrincipalRegex("CN=(.*?),");
        httpSecurity.authorizeRequests().antMatchers("/admin/**").hasAnyAuthority("ROLE_ADMINSUPPORT").anyRequest().authenticated();        
        httpSecurity.authorizeRequests().antMatchers("/services/**").hasAnyAuthority("ROLE_ADMINSUPPORT","ROLE_SERVICESCLIENT").anyRequest().authenticated();
httpSecurity.authorizeRequests().antMatchers("/**").hasAnyAuthority("ROLE_LOGON","ROLE_ADMINSUPPORT","ROLE_SERVICESCLIENT");

httpSecurity.csrf().disable();

…….
    }

    @Autowired
    protected void configureGlobal(AuthenticationManagerBuilder authenticationManager) throws Exception {

authenticationManager.inMemoryAuthentication().withUser("something-test.someplace.net ").password("").authorities("ROLE_SERVICESCLIENT");

authenticationManager.inMemoryAuthentication().withUser("something.someplace.net ").password("").authorities("ROLE_SERVICESCLIENT");

authenticationManager.inMemoryAuthentication().withUser("App Production Support Cert ").password("").authorities("ROLE_ADMINSUPPORT","ROLE_LOGON","ROLE_SERVICESCLIENT");
        }

    }
...