ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Spring Security 除接触

2020-10-26 23:02:03  阅读:20  来源: 互联网

标签:web security Spring 接触 springframework import org Security annotation


WebSecurityConfig

package com.chenmuxin.springdemo.configuration;

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;

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                // 返回一个URL拦截注册器
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .formLogin()
                .loginPage("/myLogin.html")
                .loginProcessingUrl("/login")
                // 使登陆页面不设限访问
                .permitAll()
                .and()
                .csrf()
                .disable();
    }
}

SpringDemoApplication

package com.chenmuxin.springdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SpringDemoApplication {

    @GetMapping("/")
    public String hello(){
        return "Hello,spring securtiy";
    }
    public static void main(String[] args) {
        SpringApplication.run(SpringDemoApplication.class, args);
    }

}

application.properties

spring.security.user.name=root
spring.security.user.password=root

标签:web,security,Spring,接触,springframework,import,org,Security,annotation
来源: https://www.cnblogs.com/xl4ng/p/13881993.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有