봄에 SwitchUserFilter
을 사용하여 가장을 구현하려고하는데 오류가 발생합니다. 이 구현 없이는 프로젝트가 제대로 실행됩니다. 또한이 프로젝트는 xml 구성이 아닌 Java 구성을 사용하며 SecureAuth 인증을 사용합니다. 그리고의 SecurityConfig 클래스에 코드에 관련된 부분은 다음과 같습니다가장을 java.lang.IllegalStateException : UserDetailsService가 필요합니다.
@Configuration
@ComponentScan(basePackages = {"com.project.*"})
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
@PropertySource("classpath:app.properties")
@Import({TransactionManagersConfig.class, MailConfig.class})
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private SwitchUserFilter switchUserFilter;
@Autowired
protected AuthenticationSuccessHandler authenticationSuccessHandler;
@Bean
public UserDetailsService userDetailsServiceBean() {
try {
return super.userDetailsServiceBean();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Bean
public SwitchUserFilter switchUserFilter() {
SwitchUserFilter switchUserFilter = new SwitchUserFilter();
switchUserFilter.setUserDetailsService(userDetailsServiceBean());
switchUserFilter.setUsernameParameter("username");
switchUserFilter.setSwitchUserUrl("/switch");
switchUserFilter.setExitUserUrl("/exit");
switchUserFilter.setTargetUrl("/");
return switchUserFilter;
}
//more beans
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.headers().disable();
http //SAML CONFIG
.httpBasic()
.authenticationEntryPoint(samlEntryPoint()).and()
.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
.addFilterAfter(samlFilter(), BasicAuthenticationFilter.class);
http //DISABLE CROSS-SITE REQUEST FORGERY
.csrf()
.disable();
//Impersonate Interceptor
http
.addFilterAfter(switchUserFilter(), FilterSecurityInterceptor.class);
http
.authorizeRequests()
.antMatchers("/impersonate").permitAll()
.antMatchers("/api/**").permitAll()
.antMatchers("/#/**").permitAll()
.antMatchers("/switch").permitAll()
.antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/index")
.permitAll().successHandler(authenticationSuccessHandler);
http
.logout().logoutSuccessUrl(env.getProperty("realm.url.restart"));
http
.exceptionHandling().accessDeniedPage("/error?code=403&error=Access Denied&detail=You are not authorized to access.");
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.authenticationProvider(samlAuthenticationProvider());
}
@Override
public void configure(WebSecurity webSecutity) throws Exception {
webSecutity
.ignoring().antMatchers("/resources/**");
}
}
전체 클래스 SecurityConfig.java
오류 :
java.lang.IllegalStateException: UserDetailsService is required.
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$UserDetailsServiceDelegator.loadUserByUsername(WebSecurityConfigurerAdapter.java:393)
at org.springframework.security.web.authentication.switchuser.SwitchUserFilter.attemptSwitchUser(SwitchUserFilter.java:209)
at org.springframework.security.web.authentication.switchuser.SwitchUserFilter.doFilter(SwitchUserFilter.java:155)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at
내 URL가 중지 :
http://localhost:8080/switch?j_username=angel_cuenca
당신이 경우 코드의 더 많은 부분, 공유의 즐거움이 필요합니다.
@dur 내가 디버깅하고 평가할 때 예'super.userDetailsServiceBean()가'포함'분야에서 null'가' –
을 delegate' 당신은 구성하지 않은 'UserDetailsService'이므로'null'입니다. 하나 구성해야합니다. – dur
죄송합니다. 저는 Spring Security SAML에 대한 경험이 없으므로,'UserDetailsService'를 설정하는 방법을 모르겠습니다. 어쩌면이 [link] (https://www.dontpanicblog.co.uk/2014/05/07/saml-based-single-sign-on-sosoin-spring-security-applications/) 도움이 될 것입니다. – dur