质量属性及战术——安全性

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

  抵抗攻击

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

  对原项目修改采用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();
    }
}

  限制访问。

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

  

 

    检测攻击。

  由云端提供。

 

posted @ 2020-02-26 19:32  limitCM  阅读(276)  评论(0编辑  收藏  举报