Я хочу использовать custom authentication filter
что:Настройка Spring Security без XML весной 4
- захватывает зашифрованный заголовок маркера
- после проверки его, извлекает информацию пользователя и добавляет их в контексте безопасности текущего запроса в in an stateless
Я хочу, чтобы использовать этот держатель контекста безопасности, чтобы получить информацию о том, что текущий запрашивающий пользователь правильно обрабатывает свои запросы.
@RequestMapping(value = "/simple", method = RequestMethod.POST)
@ResponseBody
@Transactional
@Preauthorize(...)
public String simple(){
//collect the user's current details from the getPrinciple() and complete the transaction...
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return "Simple";
}
Я делал это раньше в XML следующим образом:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<security:global-method-security
secured-annotations="enabled" />
<security:http pattern="/**"
auto-config="true" disable-url-rewriting="true" use-expressions="true">
<security:custom-filter ref="authenticationTokenProcessingFilter"
position="FORM_LOGIN_FILTER" />
<security:intercept-url pattern="/authenticate"
access="permitAll" />
<security:intercept-url pattern="/secure/**"
access="isAuthenticated()" />
</security:http>
<bean id="CustomAuthenticationEntryPoint" class="org.foo.CustomAuthenticationEntryPoint" />
<bean class="org.foo.AuthenticationTokenProcessingFilter" id="authenticationTokenProcessingFilter">
<constructor-arg ref="authenticationManager" />
</bean>
</beans>
Однако, я хочу, чтобы это работать с новой Spring Boot
применения в не-XML WebSecurityConfigurerAdapter как пример в их Spring ботинке файлы:
@Bean
public ApplicationSecurity applicationSecurity() {
return new ApplicationSecurity();
}
@Order(Ordered.LOWEST_PRECEDENCE - 8)
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// this is obviously for a simple "login page" not a custom filter!
http.authorizeRequests().anyRequest().fullyAuthenticated().and().formLogin()
.loginPage("/login").failureUrl("/login?error").permitAll();
}
}
Любые советы или подобные им примеры?