스프링 보안 OpenId를 사용하여 스프링 4.0 부팅 응용 프로그램을 실행하려고합니다.스프링 부트와 스프링 보안을 사용하여 스프링 4.0을 설정하는 방법 openId
@Configuration
@ComponentScan("x.y.z")
@EnableAutoConfiguration
@Import({SecurityConfig.class})
public class ServiceRegistryStart extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ServiceRegistryStart.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
application.sources(getClass());
return application;
}
}
SecurityConfig.class은 다음과 같습니다 (봄 보안에서 "오픈 ID-JC 샘플 프로젝트의 영향) :
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.anyRequest().authenticated()
.and()
.openidLogin()
.loginPage("/login.html")
.permitAll()
.authenticationUserDetailsService(new CustomUserDetailsService())
.attributeExchange("https://www.google.com/.*")
.attribute("email")
.type("http://axschema.org/contact/email")
.required(true)
.and()
.attribute("firstname")
.type("http://axschema.org/namePerson/first")
.required(true)
.and()
.attribute("lastname")
.type("http://axschema.org/namePerson/last")
.required(true)
.and()
.and()
.attributeExchange(".*yahoo.com.*")
.attribute("email")
.type("http://axschema.org/contact/email")
.required(true)
.and()
.attribute("fullname")
.type("http://axschema.org/namePerson")
.required(true)
.and()
.and()
.attributeExchange(".*myopenid.com.*")
.attribute("email")
.type("http://schema.openid.net/contact/email")
.required(true)
.and()
.attribute("fullname")
.type("http://schema.openid.net/namePerson")
.required(true);
}
@Bean(name = "myAuthenticationManager")
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
class CustomUserDetailsService implements AuthenticationUserDetailsService<OpenIDAuthenticationToken> {
@Override
public UserDetails loadUserDetails(OpenIDAuthenticationToken token) throws UsernameNotFoundException {
return new User(token.getName(), "", AuthorityUtils.createAuthorityList("ROLE_USER"));
}
}
}
나는 봄 부팅 응용 프로그램을 부트 스트랩하는 표준 방법을 사용하고 있습니다 로그인 페이지는 다음과 같습니다
<form id="googleLoginForm" action="/j_spring_openid_security_check" method="post">
<h1>Login</h1>
<input name="openid_identifier" type="hidden" value="https://www.google.com/accounts/o8/id"/>
<input name="openid.ns.pape" type="hidden" value="http://specs.openid.net/extensions/pape/1.0"/>
<input name="openid.pape.max_auth_age" type="hidden" value="0"/>
<p>
<input name="submit" value="Login using Google" type="submit"/>
</p>
</form>
문제는 "/ j_spring_openid_security_check"나는 문제가 생각하는 존재하지 않는 것 그건 내가 AbstractSecurityWebApplic에서 연장한다고 때문이다. Spring Security를 사용할 때 ationInitializer를 부팅 할 때 SpringBootServletInitializer를 사용해야합니다. 두 가지를 결합하는 가장 좋은 방법은 무엇입니까? SpringBootServletInitializer의 javadoc은 Spring Security가 감지 될 때 자동으로 필터를 등록하지만,이 경우에는 작동하지 않는 것으로 보입니다.
OpenID를 지원하기 위해 pom.xml 파일에서 무엇을하고 있습니까? 나는 당신과 비슷한 것을하고 있는데, "spring-boot-starter-security"의존성을 포함 시켰지만, OpenID 관련 클래스들을 끌어들이지는 않습니다. 나는 "spring-security-openid"의존성을 직접 추가 할 수 있다고 생각하지만, 어떤 버전을 지정해야하는지, 그리고 Spring Boot 버전 (지속적으로 변경됨)과 동기화하는 방법을 모르겠습니다. 나는 Spring Boot Security가 이것을 이미 가져 오지 않은 것에 놀랐다. –
스프링 부트 포인트가 버전을 지정하지 않아도됩니다. spring-security-openid에 종속성을 추가하기 만하면 버전은 이미 부모 pom에 지정되어 있습니다. –