zoukankan      html  css  js  c++  java
  • 质量属性及战术——安全性

      网站的安全性战术分为:与抵抗攻击有关的战术、与检测攻击有关的战术以及从攻击中恢复有关的战术。

      抵抗攻击

      对用户身份验证。简单加入用户登陆即可。

      对原项目修改采用spring security来作为SpringBoot的身份验证和权限授予的插件。

      在pom.xml中加入

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

      等待idea自动加入插件。

      因为SpringBoot在完成配件安装之后就已经简单完成配置了,所以目前就已经完成了简单的身份验证配置了,只是目前全部都是默认配置。

      默认登录界面——

       用默认密码登陆后就能进入正常网站。

      对用户进行授权。

      配置如下就能完成对网站访问的权限分配

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
    import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
    import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
    import org.springframework.security.crypto.password.PasswordEncoder;
    
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      //配置URL权限过滤规则,登录页等等
       @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .authorizeRequests()
                    .antMatchers("/admin//**").hasRole("ADMIN")
                    .antMatchers("/index//**").hasAnyRole("ADMIN")
                    .antMatchers("/index").hasAnyRole("ADMIN")
                    .antMatchers("/static_rbg*//**").permitAll()
                    .antMatchers("/ricky*//**").permitAll()
                    .anyRequest().authenticated()
                    .and()
                    .formLogin()
                    .loginPage("/login")
                    .loginProcessingUrl("/ricky-login")
                    .defaultSuccessUrl("/index")
                    .successForwardUrl("/index")
                    .usernameParameter("username").passwordParameter("password")
                    .permitAll()
                    .and().csrf().disable();
        }
        @Autowired
        private CustomUserService myAppUserDetailsService;//mybatis验证类
        @Autowired
        public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
            //注入mybatis查询类和密码校验类
            auth.userDetailsService(myAppUserDetailsService)
            .passwordEncoder(passwordEncoder());
        }
        /**
        密码验证规则
        */
        @Bean(name = "passwordEncoder")
        public  PasswordEncoder passwordEncoder(){
            return new MyPasswordEncoder();
        }
    }

      限制访问。

      把项目部署到云端,利用云服务器的防火墙进行端口隔离。

      

        检测攻击。

      由云端提供。

  • 相关阅读:
    JAVA中handleEvent和action的区别
    Hessian的使用以及理解
    Java基础中的RMI介绍与使用
    Callable与Runable接口 submit与execute区别
    XXL-JOB原理--定时任务框架简介(一)
    11.并发包阻塞队列之LinkedBlockingQueue
    并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法
    正确实现用spring扫描自定义的annotation
    自贡进入“刷脸卡”时代 人脸识别支付“黑科技”现身自流井老街
    谷歌最新研究:量子计算机能在8小时内破解2048位RSA加密
  • 原文地址:https://www.cnblogs.com/limitCM/p/12368610.html
Copyright © 2011-2022 走看看