日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

單點登錄失敗解決措施 單點登錄框架有哪些( 二 )

定義用戶信息處理對象在spring security應用中底層會借助UserDetailService對象獲取數(shù)據(jù)庫信息,并進行封裝,最后返回給認證管理器,完成認證操作,例如:
package com.jt.auth.service;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.security.core.GrantedAuthority;import org.springframework.security.core.authority.AuthorityUtils;import org.springframework.security.core.userdetails.User;import org.springframework.security.core.userdetails.UserDetails;import org.springframework.security.core.userdetails.UserDetailsService;import org.springframework.security.core.userdetails.UsernameNotFoundException;import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;import org.springframework.stereotype.Service;import java.util.List;/** * 登錄時用戶信息的獲取和封裝會在此對象進行實現(xiàn), * 在頁面上點擊登錄按鈕時,會調用這個對象的loadUserByUsername方法, * 頁面上輸入的用戶名會傳給這個方法的參數(shù) */@Servicepublic class UserDetailsServiceImpl implements UserDetailsService {@Autowiredprivate BCryptPasswordEncoder passwordEncoder;//UserDetails用戶封裝用戶信息(認證和權限信息)@Overridepublic UserDetails loadUserByUsername(String username)throws UsernameNotFoundException {//1.基于用戶名查詢用戶信息(用戶名,用戶狀態(tài),密碼,....)//Userinfo userinfo=userMapper.selectUserByUsername(username);String encodedPassword=passwordEncoder.encode("123456");//2.查詢用戶權限信息(后面會訪問數(shù)據(jù)庫)//這里先給幾個假數(shù)據(jù)List<GrantedAuthority> authorities =AuthorityUtils.createAuthorityList(//這里的權限信息先這么寫,后面講"sys:res:create", "sys:res:retrieve");//3.對用戶信息進行封裝return new User(username,encodedPassword,authorities);}}網(wǎng)關中登陸路由配置在網(wǎng)關配置文件中添加登錄路由配置,例如
- id: router02uri: lb://sca-auth#lb表示負載均衡,底層默認使用ribbon實現(xiàn)predicates: #定義請求規(guī)則(請求需要按照此規(guī)則設計)- Path=/auth/login/** #請求路徑設計filters:- StripPrefix=1 #轉發(fā)之前去掉path中第一層路徑基于Postman進行訪問測試啟動sca-gateway,sca-auth服務,然后基于postman訪問網(wǎng)關,執(zhí)行登錄測試,例如:

單點登錄失敗解決措施 單點登錄框架有哪些


自定義登陸頁面在sca-resource-ui工程的static目錄中定義登陸頁面,例如:
<!doctype html><html lang="en"><head><!-- Required meta tags --><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><!-- Bootstrap CSS --><link rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"><title>login</title></head><body><div class="container"id="app"><h3>Please Login</h3><form><div class="mb-3"><label for="usernameId" class="form-label">Username</label><input type="text" v-model="username" class="form-control" id="usernameId" aria-describedby="emailHelp"></div><div class="mb-3"><label for="passwordId" class="form-label">Password</label><input type="password" v-model="password" class="form-control" id="passwordId"></div><button type="button" @click="doLogin()" class="btn btn-primary">Submit</button></form></div><script src="http://pic.yunnanlong.com/220910/060643N92-9.jpg" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script><script src="http://pic.yunnanlong.com/220910/060643D36-10.jpg"></script><script src="http://pic.yunnanlong.com/220910/06064325V-11.jpg"></script><script>var vm=new Vue({el:"#app",//定義監(jiān)控點,vue底層會基于此監(jiān)控點在內存中構建dom樹data:{ //此對象中定義頁面上要操作的數(shù)據(jù)username:"",password:""},methods: {//此位置定義所有業(yè)務事件處理函數(shù)doLogin() {//1.定義urllet url = "http://localhost:9000/auth/login"http://2.定義參數(shù)let params = new URLSearchParams()params.append('username',this.username);params.append('password',this.password);//3.發(fā)送異步請求axios.post(url, params).then((response) => {debuggerlet result=response.data;console.log(result);if (result.state == 200) {alert("login ok");} else {alert(result.message);}})}}});</script></body></html>

推薦閱讀