Search in sources :

Example 1 with JdbcTokenRepositoryImpl

use of org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl in project judge by zjnu-acm.

the class TokenRepositoryConfiguration method persistentTokenRepository.

@Bean
public PersistentTokenRepository persistentTokenRepository(JdbcTemplate jdbcTemplate) {
    JdbcTokenRepositoryImpl jdbcTokenRepositoryImpl = new JdbcTokenRepositoryImpl();
    jdbcTokenRepositoryImpl.setJdbcTemplate(jdbcTemplate);
    jdbcTokenRepositoryImpl.setCreateTableOnStartup(false);
    return jdbcTokenRepositoryImpl;
}
Also used : JdbcTokenRepositoryImpl(org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl) Bean(org.springframework.context.annotation.Bean)

Example 2 with JdbcTokenRepositoryImpl

use of org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl in project yqq by yeycfri.

the class SecurityConfig method persistentTokenRepository.

@Bean
public PersistentTokenRepository persistentTokenRepository() {
    JdbcTokenRepositoryImpl db = new JdbcTokenRepositoryImpl();
    db.setDataSource(dataSource);
    return db;
}
Also used : JdbcTokenRepositoryImpl(org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl) Bean(org.springframework.context.annotation.Bean)

Example 3 with JdbcTokenRepositoryImpl

use of org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl in project paascloud-master by paascloud.

the class PcResourceServerConfig method persistentTokenRepository.

/**
 * 记住我功能的token存取器配置
 *
 * @return the persistent token repository
 */
@Bean
public PersistentTokenRepository persistentTokenRepository() {
    JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
    tokenRepository.setDataSource(dataSource);
    // tokenRepository.setCreateTableOnStartup(true); // 第一次启动创建
    return tokenRepository;
}
Also used : JdbcTokenRepositoryImpl(org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl) Bean(org.springframework.context.annotation.Bean)

Example 4 with JdbcTokenRepositoryImpl

use of org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl in project nzbhydra2 by theotherp.

the class SecurityConfig method configure.

@Override
protected void configure(HttpSecurity http) throws Exception {
    BaseConfig baseConfig = configProvider.getBaseConfig();
    if (configProvider.getBaseConfig().getMain().isUseCsrf()) {
        http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
    } else {
        http.csrf().disable();
    }
    http.headers().frameOptions().disable();
    if (baseConfig.getAuth().getAuthType() == AuthType.BASIC) {
        http = http.httpBasic().authenticationDetailsSource(new WebAuthenticationDetailsSource() {

            @Override
            public WebAuthenticationDetails buildDetails(HttpServletRequest context) {
                return new HydraWebAuthenticationDetails(context);
            }
        }).and().logout().logoutUrl("/logout").and();
    } else if (baseConfig.getAuth().getAuthType() == AuthType.FORM) {
        http = http.authorizeRequests().antMatchers("/internalapi/userinfos").permitAll().and().formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll().authenticationDetailsSource(new WebAuthenticationDetailsSource() {

            @Override
            public WebAuthenticationDetails buildDetails(HttpServletRequest context) {
                return new HydraWebAuthenticationDetails(context);
            }
        }).and().logout().permitAll().logoutUrl("/logout").deleteCookies("rememberMe").and();
    }
    if (baseConfig.getAuth().isAuthConfigured()) {
        enableAnonymousAccessIfConfigured(http);
        if (baseConfig.getAuth().isRememberUsers()) {
            JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
            tokenRepository.setDataSource(dataSource());
            http = http.rememberMe().alwaysRemember(true).tokenValiditySeconds(configProvider.getBaseConfig().getAuth().getRememberMeValidityDays() * SECONDS_PER_DAY).tokenRepository(tokenRepository).and();
        }
        http.logout().logoutUrl("/logout").logoutSuccessUrl("/").deleteCookies("rememberMe");
    }
    http.exceptionHandling().accessDeniedHandler(authAndAccessEventHandler);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebAuthenticationDetails(org.springframework.security.web.authentication.WebAuthenticationDetails) JdbcTokenRepositoryImpl(org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl) BaseConfig(org.nzbhydra.config.BaseConfig) WebAuthenticationDetailsSource(org.springframework.security.web.authentication.WebAuthenticationDetailsSource)

Aggregations

JdbcTokenRepositoryImpl (org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl)4 Bean (org.springframework.context.annotation.Bean)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 BaseConfig (org.nzbhydra.config.BaseConfig)1 WebAuthenticationDetails (org.springframework.security.web.authentication.WebAuthenticationDetails)1 WebAuthenticationDetailsSource (org.springframework.security.web.authentication.WebAuthenticationDetailsSource)1