日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

springbboot加密打包_Spring Boot 配置 Security 密码加密

發布時間:2024/9/27 javascript 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springbboot加密打包_Spring Boot 配置 Security 密码加密 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

依賴

org.springframework.boot

spring-boot-starter-security

注入bean

@SpringBootApplication

public class UserApplication {

public static void main(String[] args) {

SpringApplication.run(UserApplication.class, args);

}

@Bean

public BCryptPasswordEncoder encoding(){

return new BCryptPasswordEncoder();

}

}

安全配置類

authenticated()要求認證后才能訪問。

如果用戶沒有認證的話,Spring Security的Filter將會捕獲該請求,并將用戶重定向到應用的登錄頁面。

/**

* 安全配置類

*/

@Configuration

@EnableWebSecurity

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override

protected void configure(HttpSecurity http) throws Exception {

//authorizeRequests:聲明配置是權限配置

//antMatchers:路徑

//permitAll:任何權限都可以訪問,不需要身份認證

//anyRequest:任何請求

//authenticated:認證后才能訪問

//and().csrf().disable():固定寫法,表示csrf攔截失效

http

.authorizeRequests()

.antMatchers("/**").permitAll()

.anyRequest().authenticated()

.and().csrf().disable();

}

}

access(String) 如果給定的SpEL表達式計算結果為true,就允許訪問

anonymous() 允許匿名用戶訪問

authenticated() 允許認證的用戶進行訪問

denyAll() 無條件拒絕所有訪問

fullyAuthenticated() 如果用戶是完整認證的話(不是通過Remember-me功能認證的),就允許訪問

hasAuthority(String) 如果用戶具備給定權限的話就允許訪問

hasAnyAuthority(String…) 如果用戶具備給定權限中的某一個的話,就允許訪問

hasRole(String) 如果用戶具備給定角色(用戶組)的話,就允許訪問

hasAnyRole(String…) 如果用戶具有給定角色(用戶組)中的一個的話,允許訪問

hasIpAddress(String) 如果請求來自給定ip地址的話,就允許訪問

not() 對其他訪問結果求反

permitAll() 所有權限無條件允許訪問

rememberMe() 如果用戶是通過Remember-me功能認證的,就允許訪問

密碼加密與解密

@Autowired

private BCryptPasswordEncoder encoding;

public void add(Admin admin) {

//加密

admin.setPassword(encoding.encode(admin.getPassword()));

adminDao.save(admin);

}

encoding.matches(admin.getPassword(),sqlAdmain.getPassword())

總結

以上是生活随笔為你收集整理的springbboot加密打包_Spring Boot 配置 Security 密码加密的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。