2014-09-16 6 views
1

x-auth-security example 코드를 기반으로 AngularJS 및 Spring Boot를 사용하여 단일 페이지 웹 애플리케이션을 구축했습니다.스프링 부트/REST Ajax 앱 - 하루에도 여러 번 로그인하지 않아도됩니다.

이 모든 것이 아주 잘 작동하지만 사용자는 하루 동안 여러 번 다시 로그온해야한다고 불평하고 있습니다. Spring Security와 같은 것에 익숙하지는 않지만, 인증 토큰이 1 시간 만료로 생성된다는 이유가 있다고 생각합니다. https://github.com/joshlong/boot-examples/blob/master/x-auth-security/src/main/java/demo/xauth/TokenUtils.java 참조 :이 예를 들어 24 시간이 만료 연장하는 것이 좋습니다

public String createToken(UserDetails userDetails) { 
    long expires = System.currentTimeMillis() + 1000L * 60 * 60; 
    return userDetails.getUsername() + ":" + expires + ":" + computeSignature(userDetails, expires); 
} 

인가?

@EnableWebMvcSecurity 
@EnableWebSecurity 
@Configuration 
@Profile("security") 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter 
{ 

... 

@Override 
    protected void configure(HttpSecurity http) throws Exception 
    { 
     http.csrf().disable(); 
     http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); 

     http.authorizeRequests() 
       .antMatchers("/api/datasheets/*/documents/*/download").anonymous() // Workaround to allow download of the files again. This is insecure. Hopefully I get an answer soon: http://stackoverflow.com/questions/23413701/download-a-file-that-needs-authentication-token 
       .antMatchers("/api/**").hasRole("READONLY"); 

     SecurityConfigurer<DefaultSecurityFilterChain, HttpSecurity> securityConfigurer = new XAuthTokenConfigurer(userDetailsServiceBean()); 
     http.apply(securityConfigurer); 
    } 

    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception 
    { 
     auth.userDetailsService(new LocalUserDetailsService()) 
       .and().ldapAuthentication() 
       .contextSource(contextSource()) 
       .ldapAuthoritiesPopulator(authoritiesPopulator()) 
       .userSearchFilter(LDAP_USER_FILTER) 
       .userDnPatterns("OU=local,OU=Users") 
       .groupSearchBase("OU=Security Groups"); 
    } 

답변

1

을 나는 다른 사람들이 짧은 살았 토큰 및 새로 고침을 선호, 24 시간 어떤 사람들이 할 (안전 마지막 토큰을 생각 여부를 당신에게 달려 같아요 아니면 내가 봄 보안 구성에서 뭔가를 변경해야 메커니즘, OAuth2 에서처럼). 당신이 그 위험 수준에 만족한다면 변화시킬 것이 없습니다.

관련 문제