Spring Boot에서 사전 인증 헤더 기반 인증을 설정하는 방법은 무엇입니까?
내 앱이 Oracle Access Manager SSO에서 사용자 이름이 포함된 AUTH_USER 요청 헤더를 가져옵니다. Spring Security "Additional Topics" 2.2.1에는 "PreAuth" 예제가 있는데, 이는 내가 필요한 것처럼 보이지만 전체 작동 예제는 아닙니다.
아래의 스니펫은 문서/예문에서 가져온 것이며, 주석 기반 구성으로 작동하지 않습니다.
사이트마인더 구성 예제 - 요청과 함께 XML 사용헤더 인증 필터 및 사전 인증됨사용자를 조회하기 위한 인증 공급자 및 사용자 세부 정보 서비스.
이 구성을 Java 기반 구성에 어떻게 매핑합니까?
<security:http>
<!-- Additional http configuration omitted -->
<security:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" />
</security:http>
<bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
<property name="principalRequestHeader" value="AUTH_USER"/>
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth. PreAuthenticatedAuthenticationProvider">
<property name="preAuthenticatedUserDetailsService">
<bean id="userDetailsServiceWrapper"
class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
<property name="userDetailsService" ref="userDetailsService"/>
</bean>
</property>
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="preauthAuthProvider" />
</security:authentication-manager>
Spring Security 사전 인증 예제의 설정은 완전히 다릅니다(XML 구성은 더욱 위협적입니다).사전 인증 필터나 헤더 이름 설정 방법에 대한 언급이 없습니다.
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login","/resources/**").permitAll()
.anyRequest().authenticated()
.and()
.jee()
.mappableRoles("USER","ADMIN");
}
}
spring-boot-sample-web-secure는 WebSecurityConfigurerAdapter 대신 WebMvcConfigurerAdapter를 확장하고 기본 양식 기반 로그인만 수행하며 사전 인증 AUTH_USER 헤더에서 userid를 가져오는 방법에 대한 정보는 없습니다.
public class SampleWebSecureApplication extends WebMvcConfigurerAdapter {
... omitted...
@Bean
public ApplicationSecurity applicationSecurity() {
return new ApplicationSecurity();
}
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
@Autowired
private SecurityProperties security;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated().and().formLogin()
.loginPage("/login").failureUrl("/login?error").permitAll();
}
}
}
많은 참고 자료/기사를 읽었지만 현재 코드와 스프링 부트와 관련이 없는 것 같아 앱 사전 인증 보안을 구성하는 방법을 이해하려고 노력하는 중입니다.
주입된 userService를 기반으로 사전 인증 보안을 구성하는 방법은 다음과 같습니다.
@Configuration
@EnableWebSecurity
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(jsr250Enabled = true, securedEnabled = true, prePostEnabled = true, proxyTargetClass = true)
public class ApplicationSecurity extends WebSecurityConfigurerAdapter {
private static final Logger LOG = Logger.getLogger(ApplicationSecurity.class.getName());
@Autowired
private UserService userService; // implements AuthenticationUserDetailsService...
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
LOG.info("configure autentication provider with custom userService");
PreAuthenticatedAuthenticationProvider paaProvider = new PreAuthenticatedAuthenticationProvider();
paaProvider.setPreAuthenticatedUserDetailsService(userService);
auth.authenticationProvider(paaProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
LOG.info("configure autentication filter");
// ...
}
}
언급URL : https://stackoverflow.com/questions/26070286/how-to-setup-pre-authentication-header-based-authentication-in-spring-boot
'prosource' 카테고리의 다른 글
여러 자식 컨텍스트가 있는 스프링 부트 응용 프로그램 만들기 (0) | 2023.07.22 |
---|---|
모듈의 정규식이 단어 경계(\b)를 지원합니까? (0) | 2023.07.22 |
_chkstk() 함수의 목적은 무엇입니까? (0) | 2023.07.22 |
명명된 매개 변수의 문자열 형식을 지정하시겠습니까? (0) | 2023.07.22 |
gcc, 엄격한 별칭 지정 및 조합을 통한 캐스팅 (0) | 2023.07.22 |