2016-12-13 13 views
1

내 서버에 CAS 서버를 설치했습니다. (아파치 바람둥이 전쟁 배포). CAS 서버에 사용자 이름 및 암호와 같은 사용자 정보가 있습니다. (앞으로는 LDAP 또는 사용자 자격 증명을위한 간단한 관계 데이터베이스에 연결됩니다. 문제는 여기에 있습니다.이 CAS 서버를 통해 스프링 응용 프로그램을 인증하려고하지만 스프링 보안에 대한 적절한 구성을 찾을 수 없습니다. 내 구성 파일은 다음과 같습니다CAS 서버를 통해 스프링 웹 응용 프로그램 인증

 @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .csrf().disable() 
      .authorizeRequests() 
       .antMatchers("/assets","/css", "/js","/font-awesome","/bootstrap","/images").permitAll() 
       .antMatchers("/", "/home").authenticated() 
//    .antMatchers("/hi").access("hasRole('ROLE_SUBSCRIPTION') or hasRole('ROLE_ADMIN')") 
       .antMatchers("/edit").authenticated() 
//    .antMatchers("/playlists/*").authenticated() 
//    .antMatchers("/createplaylist").authenticated() 
       .and() 
      .formLogin() 
       .loginPage("/login") 
       .permitAll() 
       .and() 
      .logout() 
       .permitAll(); 
    } 

    @Bean 
    public ServiceProperties serviceProperties() { 
     ServiceProperties sp = new ServiceProperties(); 
     sp.setService(env.getRequiredProperty(CAS_SERVICE_URL)); 
     sp.setSendRenew(false); 
     return sp; 
    } 
    @Bean 
    public Set<String> adminList() { 
     Set<String> admins = new HashSet<String>(); 
     String adminUserName = env.getProperty(APP_ADMIN_USER_NAME); 

     admins.add("admin"); 
     if (adminUserName != null && !adminUserName.isEmpty()) { 
      admins.add(adminUserName); 
     } 
     return admins; 
    } 

    @Bean 
    public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> customUserDetailsService() { 
     return new CustomUserDetailsService(adminList()); 
    } 
    @Bean 
    public CasAuthenticationProvider casAuthenticationProvider() { 
     CasAuthenticationProvider casAuthenticationProvider = new CasAuthenticationProvider(); 
//  casAuthenticationProvider.setAuthenticationUserDetailsService(customUserDetailsService()); 
//  casAuthenticationProvider.setServiceProperties(serviceProperties()); 
     casAuthenticationProvider.setTicketValidator(cas20ServiceTicketValidator()); 
//  casAuthenticationProvider.setKey("an_id_for_this_auth_provider_only"); 
     return casAuthenticationProvider; 
    } 
    @Bean 
    public Cas20ServiceTicketValidator cas20ServiceTicketValidator() { 
     return new Cas20ServiceTicketValidator(env.getRequiredProperty(CAS_URL_PREFIX)); 
    } 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
//  auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN"); 
     auth.authenticationProvider(casAuthenticationProvider()); 
    } 
당신은 쉽게 구성하도록 pac4j을 사용할 수 있습니다

답변