最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot?整合Security權限控制的初步配置

 更新時間:2022年11月10日 15:50:20   作者:EdurtIO  
這篇文章主要為大家介紹了SpringBoot?整合Security權限控制的初步配置實例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

正文

在源碼目錄下新建 config 目錄, 在該目錄下新建 WebSecurityConfig 類文件

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edurt.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
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.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
/**
 * WebSecurityConfig <br/>
 * 描述 : WebSecurityConfig <br/>
 * 作者 : qianmoQ <br/>
 * 版本 : 1.0 <br/>
 * 創(chuàng)建時間 : 2018-03-15 下午3:18 <br/>
 * 聯(lián)系作者 : <a href="mailTo:shichengoooo@163.com" rel="external nofollow" >qianmoQ</a>
 */
@Configuration
// 開啟security訪問授權
@EnableWebSecurity
// 開啟security注解模式
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Bean
    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // 允許直接訪問/路徑
        http.authorizeRequests().antMatchers("/").permitAll()
                // 其他路徑需要授權訪問
                .anyRequest().authenticated()
                // 指定登錄頁面
                .and().formLogin().loginPage("/user/login")
                // 登錄成功后的默認路徑
                .defaultSuccessUrl("/").permitAll()
                // 退出登錄后的默認路徑
                .and().logout().logoutSuccessUrl("/user/login").permitAll();
    }
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        // 配置用戶登錄檢索策略
        auth.userDetailsService(userDetailsService())
                // 配置密碼策略
                .passwordEncoder(passwordEncoder());
//        auth.inMemoryAuthentication().withUser("user").password("123456").roles("USER")
//                .and().withUser("admin").password("123456").roles("ADMIN");
    }
    @Bean
    public Md5PasswordEncoder passwordEncoder() {
        return new Md5PasswordEncoder();
    }
    @Bean
    public UserDetailsService userDetailsService() {
        InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
        // 創(chuàng)建模擬用戶
        manager.createUser(User.withUsername("user").password("123456").roles("USER").build());
        manager.createUser(User.withUsername("admin").password("123456").roles("ADMIN").build());
        return manager;
    }
}

瀏覽器打開 http://localhost:8080/home 會自動跳轉到用戶登錄頁面, 輸入賬號和密碼出現(xiàn)賬號密碼校驗頁面

以上就是SpringBoot 整合Security權限控制的初步配置的詳細內容,更多關于SpringBoot整合Security配置的資料請關注腳本之家其它相關文章!

相關文章

  • 創(chuàng)建好SpringBoot項目后但是找不到Maven的解決方法

    創(chuàng)建好SpringBoot項目后但是找不到Maven的解決方法

    在使用IDEA專業(yè)版創(chuàng)建好SpringBoot項目后,發(fā)現(xiàn)上方導航欄的運行按鈕是灰色的,而且左側導航欄的pom.xml的圖標顏色也不是正常的,點開右側導航欄的Maven后,發(fā)現(xiàn)Maven找不到,所以本文介紹了創(chuàng)建好SpringBoot項目后但是找不到Maven的解決方法,需要的朋友可以參考下
    2024-10-10
  • RabbitMQ消費者限流實現(xiàn)消息處理優(yōu)化

    RabbitMQ消費者限流實現(xiàn)消息處理優(yōu)化

    這篇文章主要介紹了RabbitMQ消費者限流實現(xiàn)消息處理優(yōu)化,消費者限流是用于消費者每次獲取消息時限制條數(shù),注意前提是手動確認模式,并且在手動確認后才能獲取到消息,感興趣想要詳細了解可以參考下文
    2023-05-05
  • JAVA通過Filter實現(xiàn)允許服務跨域請求的方法

    JAVA通過Filter實現(xiàn)允許服務跨域請求的方法

    這里的域指的是這樣的一個概念:我們認為若協(xié)議 + 域名 + 端口號均相同,那么就是同域即我們常說的瀏覽器請求的同源策略。這篇文章主要介紹了JAVA通過Filter實現(xiàn)允許服務跨域請求,需要的朋友可以參考下
    2018-11-11
  • java中判斷字段真實長度的實例(中文2個字符,英文1個字符)

    java中判斷字段真實長度的實例(中文2個字符,英文1個字符)

    下面小編就為大家?guī)硪黄猨ava中判斷字段真實長度的實例(中文2個字符,英文1個字符)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-01-01
  • Spring Boot集成Sorl搜索客戶端的實現(xiàn)代碼

    Spring Boot集成Sorl搜索客戶端的實現(xiàn)代碼

    本篇文章主要介紹了Spring Boot集成Sorl搜索客戶端的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • Java后臺開發(fā)之表單提交之前驗證

    Java后臺開發(fā)之表單提交之前驗證

    這篇文章主要介紹了Java后臺開發(fā)之表單提交之前驗證的實現(xiàn)代碼,非常不錯具有參考借鑒價值,需要的朋友參考下吧
    2017-02-02
  • IDEA連接遠程服務器簡化部署流程

    IDEA連接遠程服務器簡化部署流程

    筆者每次上線部署應用,都要使用第三方的客戶端連接工具,比如?Xshell,FinalShell,Terminus?等,基本的流程步驟及其繁瑣,基于這個原因,筆者今天探索通過?IDEA?連接遠程服務器并上傳文件,減少繁瑣的部署步驟,需要的朋友可以參考下
    2024-01-01
  • java的Jackson將json字符串轉換成泛型List

    java的Jackson將json字符串轉換成泛型List

    這篇文章主要介紹了java的Jackson將json字符串轉換成泛型List ,這里整理了詳細的代碼,有需要的小伙伴可以參考下。
    2017-02-02
  • Java解析使用JSON的多種方法

    Java解析使用JSON的多種方法

    使用JSON作為數(shù)據(jù)傳輸,在瀏覽器端非常方便。JSON去除了所有JavaScript執(zhí)行代碼,只保留對象格式,而且JSON天生適合JavaScript處理,所以,絕大多數(shù)REST?API都選擇JSON作為數(shù)據(jù)傳輸格式?,F(xiàn)在問題來了:使用Java如何對JSON進行讀寫?
    2022-12-12
  • 使用Java自制一個一個Nacos

    使用Java自制一個一個Nacos

    Nacos是?Dynamic?Naming?and?Configuration?Service的首字母簡稱,一個更易于構建云原生應用的動態(tài)服務發(fā)現(xiàn)、配置管理和服務管理平臺,本文將嘗試用Java實現(xiàn)一個Nacos,感興趣的可以了解下
    2024-01-01

最新評論

江口县| 齐齐哈尔市| 奇台县| 海伦市| 锡林浩特市| 泗水县| 大冶市| 台北县| 德阳市| 南京市| 安徽省| 富蕴县| 黄冈市| 桃源县| 枞阳县| 彭阳县| 东阿县| 淮北市| 剑阁县| 绥棱县| 呈贡县| 天津市| 罗田县| 黄陵县| 无极县| 句容市| 信阳市| 赤水市| 康乐县| 平泉县| 德化县| 民县| 富宁县| 财经| 花垣县| 灵石县| 翼城县| 涞水县| 综艺| 故城县| 黔西|