zoukankan      html  css  js  c++  java
  • https Configure a Spring Boot app for HTTPS on Amazon AWS.

    参考: https://geocolumbus.github.io/HTTPS-ELB-AWS-Spring-Boot/

    1.  在服务器端配置  证书 域名 映射

    2. 导入依赖:

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    3.配置

    @Configuration
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Autowired
        private LdapConfig ldapConfig;
    
        @Autowired
        private CorsConfig corsConfig;
    
        @Bean
        @Override
        public AuthenticationManager authenticationManagerBean() throws Exception {
            return super.authenticationManagerBean();
        }
    
        @Value("${security.https.path}")
        private String httpsPath;   // 项目路径  ,正式环境  配置 "/" 即可
    
     
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .requiresChannel().antMatchers(httpsPath).requiresSecure()
                    .and()
                    .authorizeRequests()
                    //.antMatchers("/ui/**").fullyAuthenticated()
                    //.antMatchers("/file/**").fullyAuthenticated()
                    .antMatchers("/**").permitAll()
                    .and().cors()
                    .and().csrf().disable();
        }
    
        
    }

    (备份)

    @Configuration
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Autowired
        private LdapConfig ldapConfig;
    
        @Autowired
        private CorsConfig corsConfig;
    
        @Bean
        @Override
        public AuthenticationManager authenticationManagerBean() throws Exception {
            return super.authenticationManagerBean();
        }
    
        @Value("${security.https.path}")
        private String httpsPath;
    
        @Bean
        public UserDetailsContextMapper userDetailsContextMapper() {
            return new LdapUserDetailsMapper() {
                @Override
                public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
                                                      Collection<? extends GrantedAuthority> authorities) {
                    UserDetails details = super.mapUserFromContext(ctx, username, authorities);
                    return new UserDetail((LdapUserDetails) details);
                }
            };
        }
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .requiresChannel().antMatchers(httpsPath).requiresSecure()
                    .and()
                    .authorizeRequests()
                    .antMatchers("/ui/**").fullyAuthenticated()
                    .antMatchers("/file/**").fullyAuthenticated()
                    .antMatchers("/**").permitAll()
                    .and().cors()
                    .and().csrf().disable();
        }
    
        @Override
        public void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth
                    .ldapAuthentication()
                    .userDetailsContextMapper(userDetailsContextMapper())
                    .userDnPatterns("uid={0},ou=people")
                    .groupSearchBase("ou=groups")
                    .contextSource()
                    .url(ldapConfig.getUrl()+ldapConfig.getBase_dc())
                    .managerDn(ldapConfig.getUsername())
                    .managerPassword(ldapConfig.getPassword());
        }
    
        @Bean
        CorsConfigurationSource corsConfigurationSource() {
            CorsConfiguration configuration = new CorsConfiguration();
            configuration.setAllowedOrigins(corsConfig.getAllowedOrigins());
            configuration.setAllowedMethods(corsConfig.getAllowedMethods());
            configuration.setAllowedHeaders(corsConfig.getAllowedHeaders());
            configuration.setAllowCredentials(corsConfig.getAllowedCredentials());
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            source.registerCorsConfiguration("/**", configuration);
            return source;
        }
    }
    View Code

    4.在application. yml 或者 application.properties 中配置:

    server:
      port: 7000
      servlet:
        session:
          timeout: 1800
      tomcat:
        max-threads: 10
        remote-ip-header: x-forwarded-for
        protocol-header: x-forwarded-proto
  • 相关阅读:
    jzoj 3176. 【GDOI2013模拟5】蜘蛛侠
    各种各样的根号算法 总结&刷题
    jzoj 3187. 【GDOI2013模拟8】的士
    jzoj 3188. 【GDOI2013模拟8】找数
    jzoj 4673. 【NOIP2016提高A组模拟7.20】LCS again
    jzoj 4672. 【NOIP2016提高A组模拟7.20】Graph Coloring
    markdown 模板2
    树莓派kali开启arp【arpspoof,urlsnarf】
    Java 图片处理——如何生成高清晰度而占有磁盘小的缩略图
    手把手教你生成二维码-google.zxing
  • 原文地址:https://www.cnblogs.com/lshan/p/9817815.html
Copyright © 2011-2022 走看看