@Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/user/**").authenticated() .anyRequest().permitAll() .and() .formLogin() .loginPage("/login") .defaultSuccessUrl("/user", true) .permitAll() .and() .logout() .permitAll() .and().portMapper().http(port).mapsTo(sslPort) .and().csrf().disable(); http.rememberMe().alwaysRemember(true); http.addFilterAt(qqAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); http.addFilterAt(githubAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); }
@Override protected void configure(HttpSecurity http) throws Exception { http .requiresChannel() .anyRequest().requiresSecure() .and() .portMapper() .http(543).mapsTo(123) .and() .portMapper(); } }
@Override protected void configure(HttpSecurity http) throws Exception { http.portMapper().http(80).mapsTo(443); http.exceptionHandling().authenticationEntryPoint(customAuthenticationEntryPoint); http.headers().frameOptions().disable(); http.logout().logoutSuccessHandler(logoutSuccessHandler()).permitAll() .and() .antMatcher("/**").authorizeRequests() .antMatchers("/webjars/**", "/", "/index.html", "/empty.html", "/login.html").permitAll() .antMatchers("/authserver/uaa/login", "/authserver/uaa/register", "/authserver/uaa/activate").permitAll() .antMatchers("/ui/VAADIN/**").permitAll() .anyRequest().authenticated() .and().csrf().disable().requiresChannel().anyRequest().requiresSecure(); }
@Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/list","/api/**").authenticated() .anyRequest().permitAll() .and() .formLogin() .loginPage("/login") .defaultSuccessUrl("/list").failureUrl("/?error") .permitAll() .and() .logout() .permitAll() .and().portMapper().http(80).mapsTo(443) .and().csrf().disable(); http.rememberMe().alwaysRemember(true); // //设置默认登录成功跳转页面 // .defaultSuccessUrl("/index").failureUrl("/login?error").permitAll() // .and() // //开启cookie保存用户数据 // .rememberMe() // //设置cookie有效期 // .tokenValiditySeconds(60 * 60 * 24 * 7) // //设置cookie的私钥 // .key("") } }
private void configureHSTS(HttpSecurity http) throws Exception { HeadersConfigurer<HttpSecurity>.HstsConfig hsts = http.headers().httpStrictTransportSecurity(); // If using SSL then enable the hsts and secure forwarding if (sslOn && sslHstsEnabled) { // only enable "requiresSecure" for browser requests (not for XHR/REST requests) // this options sets the REQUIRES_SECURE_CHANNEL attribute and causes ChannelProcessingFilter // to perform a 302 redirect to https:// http.portMapper().http(webPort).mapsTo(sslPort); http.requiresChannel().requestMatchers(browserHtmlRequestMatcher).requiresSecure(); hsts.maxAgeInSeconds(sslHstsMaxAge).includeSubDomains(sslHstsIncludeSubDomains); } else { hsts.disable(); } }