国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Spring Security學習筆記(一)

瀏覽:15日期:2022-08-25 15:45:13

介紹

這里學習SpringSecurity,對SpringSecurity進行學習。

基本用法

添加依賴

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

添加接口

package com.example.demo.web;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping('/test')public class Test { @RequestMapping('/test') public String test(){ return 'test'; }}

啟動項目

可以看到日志中,已經有了密碼

Spring Security學習筆記(一)

訪問接口,此時已經有了登錄頁面

Spring Security學習筆記(一)

輸入用戶名和密碼

用戶名: user密碼 984cccf2-ba82-468e-a404-7d32123d0f9c

Spring Security學習筆記(一)

此時已經登錄成功

配置用戶名和密碼

在配置文件中,進行配置

spring:security:user:name: mingpassword: 123456roles: admin

輸入用戶名和密碼,可以正常登錄

基于內存的認證

需要自定義類繼承 WebSecurityConfigurerAdapter實現自定義的配置這里基于內存的配置,如下

package com.example.demo.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;import org.springframework.security.crypto.password.NoOpPasswordEncoder;import org.springframework.security.crypto.password.PasswordEncoder;@Configurationpublic class MyWebSecurityConfig extends WebSecurityConfigurerAdapter { @Bean PasswordEncoder passwordEncoder(){ return NoOpPasswordEncoder.getInstance(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser('admin').password('123').roles('admin'); }}

這里基于內存的配置

HttpSecurity

這里對某些方法進行攔截

package com.ming.demo.interceptor;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.http.HttpMethod;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.crypto.bcrypt.BCryptPasswordEncoder;import org.springframework.security.crypto.password.PasswordEncoder;import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;@Configuration@EnableWebSecuritypublic class SecurityConfig extends WebSecurityConfigurerAdapter { //基于內存的用戶存儲 @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser('itguang').password('123456').roles('USER').and().withUser('admin').password('{noop}' + '123456').roles('ADMIN'); } //請求攔截 @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().permitAll().and().formLogin().permitAll().and().logout().permitAll(); }}

這里成功完成了post請求進行登錄驗證。

以上就是Spring Security學習筆記(一)的詳細內容,更多關于Spring Security的資料請關注好吧啦網其它相關文章!

標簽: Spring
相關文章:
主站蜘蛛池模板: 日本欧美视频在线 | 欧美日韩一级黄色片 | 欧美一区精品二区三区 | 成人免费一级在线播放 | 国产精品久久久99 | 成人午夜视频一区二区国语 | 91精品啪在线看国产网站 | 在线永久免费观看黄网站 | 毛片1毛片2毛片3毛片4 | 久久91精品国产99久久yfo | 真实国产乱子伦高清 | 亚洲成人综合视频 | 精品免费久久久久久成人影院 | 国产精品久久久久久久y | 高清一本之道加勒比在线 | 亚洲一区二区三区精品国产 | 国产美女做爰免费视频软件 | 毛片免费视频观看 | 精品久久久久久无码中文字幕 | 暖暖视频日韩欧美在线观看 | 性感美女一级片 | 亚洲国产一区二区在线 | 美女一级毛片免费观看 | 中文字幕综合 | 伊大人香蕉久久网欧美 | 国产精品视频免费 | 亚洲第一成年网站大全亚洲 | 欧美三级一级片 | 国产精品成人一区二区三区 | 日本一级在线播放线观看视频 | 国产欧美日韩一区二区三区在线 | 欧美性猛交xxxx免费看手交 | 天天看夜夜| 国产日韩欧美一区二区三区在线 | 亚洲国产精品一区二区首页 | 国产一区二区三区欧美精品 | 日韩成人三级 | 99久久精品国产9999高清 | 精品一区二区三区免费毛片爱 | 在线视免费频观看韩国aaa | 久久riav.com |