zoukankan      html  css  js  c++  java
  • spring security

    package com.xiaomi.mishell.statusbar.config;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    @Configuration
    public class MvcConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/login").setViewName("login");
            registry.addViewController("/push/sendMsg").setViewName("push/sendMsg");
            registry.addViewController("/push/data").setViewName("push/data");
        }
    
    }
    MvcConfig
    package com.xiaomi.mishell.statusbar.config;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Configuration;
    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.web.access.intercept.FilterSecurityInterceptor;
    
    @Configuration
    @EnableWebSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .authorizeRequests()
                    .antMatchers("/css/**", "/index").permitAll()
                    .antMatchers("/push/**").hasRole("USER")
                    .and()
                    .formLogin()
                    .loginPage("/login")
                    .permitAll()
                    .and()
                    .logout()
                    .permitAll();
            http.csrf().disable();
        }
    
        @Autowired
        public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
            auth
                    .inMemoryAuthentication()
                    .withUser("miuishell").password("miuishell").roles("USER");
        }
    }
    SecurityConfig
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
          xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    <head>
        <title>Spring Security Example </title>
        <link rel="stylesheet" href="/css/login.css" type="text/css"/>
    </head>
    <body>
    <div th:if="${param.error}">
        Invalid username and password.
    </div>
    <div th:if="${param.logout}">
        You have been logged out.
    </div>
    <form id="form_login" th:action="@{/login}" method="post">
        <div><label> User Name : <input type="text" name="username"/> </label></div>
        <br/>
        <div><label> Password&nbsp;&nbsp;&nbsp;: <input type="password" name="password"/> </label></div>
        <br/>
        <div><input type="submit" value="Sign In"/></div>
    </form>
    </body>
    </html>
    login.html

    login.html 解析报错  参考:http://www.cnblogs.com/tengpan-cn/p/7543080.html

  • 相关阅读:
    ABP框架系列之六:(Value-Objects-值对象)
    ElementUI如何展开指定Tree树节点
    JS如何将变量作为一个对象的Key
    分布式追踪系统架构与设计
    11.浅聊几种主流Docker网络的实现原理
    Python连接MongoDB数据库并执行操作
    1.ZooKeeper ACL权限控制
    Pika 连接 rabbitmq 集群
    js for等循环 跳出多层循环
    Django ForeignKey不需要参照完整性?
  • 原文地址:https://www.cnblogs.com/tengpan-cn/p/7885299.html
Copyright © 2011-2022 走看看