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

springboot如何通過(guò)session實(shí)現(xiàn)單點(diǎn)登入詳解

 更新時(shí)間:2021年12月03日 09:01:45   作者:是南巷的花貓啊  
單點(diǎn)登錄(SSO)的定義是在多個(gè)應(yīng)用系統(tǒng)中,用戶(hù)只需要登錄一次就可以訪問(wèn)所有相互信任的應(yīng)用系統(tǒng),下面這篇文章主要給大家介紹了關(guān)于springboot如何通過(guò)session實(shí)現(xiàn)單點(diǎn)登入的相關(guān)資料,需要的朋友可以參考下

我對(duì)于單點(diǎn)的理解

正常的登錄

進(jìn)入自己系統(tǒng)的登錄頁(yè)面,輸入用戶(hù)名密碼,登錄系統(tǒng)。

單點(diǎn)登錄

來(lái)到一個(gè)第三方的登錄頁(yè)面,輸入用戶(hù)名密碼,在這個(gè)頁(yè)面登錄成功之后,就算成功的登錄了應(yīng)用系統(tǒng)。好處在于這個(gè)登錄頁(yè)面不僅僅是登錄一個(gè)系統(tǒng),可以同時(shí)登錄多個(gè)系統(tǒng)。即所謂的一次登錄,全程暢通。

效果圖走起


另外開(kāi)一個(gè)瀏覽器

原來(lái)的頁(yè)面刷新一下

發(fā)現(xiàn)他已經(jīng)被擠下線

代碼部分

package com.nx.j2ee.service;

import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Service
public class OnlineService {
    private Map<String, HttpSession> UserMap = new HashMap<>();

    public HttpSession getUserMap(String name) {
        return UserMap.get(name);
    }

    public void setUserMap(String name, HttpSession httpSession) {
        UserMap.put(name, httpSession);
    }

    public void delectUserMap(String name){
        UserMap.remove(name);
    }

    public int shownum(){
        return UserMap.size();
    }

    public Map<String, HttpSession> showall(){
        return UserMap;
    }
}

登入controller

package com.nx.j2ee.controller;

import com.nx.j2ee.entity.UserEntity;
import com.nx.j2ee.service.OnlineService;
import com.nx.j2ee.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class User {

    @Autowired
    private UserService userService;

    @Autowired
    private OnlineService onlineService;

    /**
     * @Description : 登入顯示
     * @Author : 南巷的花貓
     * @Date : 2021/11/23 14:02
    */
    @GetMapping("/login")
    public String showlogin(){
        return "user/Login";
    }

    /**
     * @Description : 獲取登入信息
     * @Author : 南巷的花貓
     * @Date : 2021/11/23 14:03
    */
    @PostMapping("/login")
    public String setlogin(@RequestParam("name") String name,
                           @RequestParam("password") String password, Model model,
                           HttpSession httpSession){

        UserEntity userEntity = userService.login(name, password);

        if (userEntity != null){
            if(onlineService.getUserMap(name) != null){
                onlineService.getUserMap(name).invalidate();
            }
            httpSession.setAttribute("userinfo", userEntity);
            onlineService.setUserMap(name, httpSession);
            return "redirect:/";
        }else {
            model.addAttribute("eroor", "用戶(hù)名或者密碼出錯(cuò)");
            return "user/Login";
        }
    }

    @GetMapping("/downline")
    public String downline(HttpSession httpSession){

        UserEntity userEntity = (UserEntity) httpSession.getAttribute("userinfo");
        onlineService.delectUserMap(userEntity.getName());
        httpSession.invalidate();
        return "redirect:/";
    }
}

首頁(yè)controller

package com.nx.j2ee.controller;

import com.nx.j2ee.entity.UserEntity;
import com.nx.j2ee.service.OnlineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.Set;


@Controller
public class Index {

    @Autowired
    private OnlineService onlineService;

    private boolean select = false;

    @GetMapping("/")
    public String showindex(Model model, HttpSession httpSession){

        UserEntity userinfo = (UserEntity) httpSession.getAttribute("userinfo");
        if (userinfo != null){
            this.select = true;
        }else {
            this.select = false;
        }
        int onlinenum = onlineService.shownum();
        Set<String> userset = onlineService.showall().keySet();

        model.addAttribute("onlinenum", onlinenum);
        model.addAttribute("userinfo", userinfo);
        model.addAttribute("userset", userset);
        model.addAttribute("select", this.select);
        return "home/index";
    }
}

HTML頁(yè)面

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <title>首頁(yè)</title>
</head>
<body>
<div class="layui-container">
    <div>
        <ul class="layui-nav layui-bg-green" lay-filter="">
            <li class="layui-nav-item">
                <a href="">在線人數(shù)<span class="layui-badge" th:text="${onlinenum}"></span></a>
            </li>
            <li class="layui-nav-item">
                <a th:href="@{/PTcourse}">普通課程</a>
            </li>
            <li class="layui-nav-item">
                <a th:href="@{/VIPcourse}">vip課程</a>
            </li>
            <li class="layui-nav-item">
                <a th:href="@{/GZcourse}">貴族課程</a>
            </li>
            <li class="layui-nav-item" style="float: right">
                <a href="" th:if="${not select}">游客</a>
                <a href="" th:if="${userinfo}" th:text="${userinfo.name}"></a>
                <dl class="layui-nav-child">
                    <dd th:if="${select}"><span style="color: #2d6086">等級(jí):&nbsp;</span><span style="color: #0C0C0C" th:text="${userinfo.getTest1()}"></span></dd>
                    <dd><a href="javascript:;">修改信息</a></dd>
                    <dd><a href="javascript:;">安全管理</a></dd>
                    <dd><a th:href="@{/downline}" th:if="${select}">下線</a></dd>
                    <dd><a th:href="@{/login}" th:if="${not select}">登入</a></dd>
                </dl>
            </li>
        </ul>
    </div>
    <div style="margin-top: 20px;padding: 0px 50px 0px 50px">
        <div>
            <h3 style="color: #ac0d22">在線用戶(hù)列表</h3>
        </div>
        <div th:each="username:${userset}">
            <p th:text="${username}"></p>
        </div>
    </div>
</div>
<script src="/layui/layui.js"></script>
<script>
  layui.use(['layer', 'form'], function(){
    var layer = layui.layer
            ,form = layui.form;

    layer.msg('追求極簡(jiǎn)');
  });
</script>
</body>
</html>

總結(jié)

到此這篇關(guān)于springboot如何通過(guò)session實(shí)現(xiàn)單點(diǎn)登入的文章就介紹到這了,更多相關(guān)springboot?session單點(diǎn)登入內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java導(dǎo)出CSV文件的方法

    Java導(dǎo)出CSV文件的方法

    這篇文章主要為大家詳細(xì)介紹了Java導(dǎo)出CSV文件的方法,分頁(yè)查詢(xún)大數(shù)據(jù)量,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-12-12
  • SpringBoot中的響應(yīng)式web應(yīng)用詳解

    SpringBoot中的響應(yīng)式web應(yīng)用詳解

    這篇文章主要介紹了SpringBoot中的響應(yīng)式web應(yīng)用詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • mybatis-plus如何禁用一級(jí)緩存的方法

    mybatis-plus如何禁用一級(jí)緩存的方法

    這篇文章主要介紹了mybatis-plus如何禁用一級(jí)緩存的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • 淺談對(duì)Java雙冒號(hào)::的理解

    淺談對(duì)Java雙冒號(hào)::的理解

    這篇文章主要介紹了淺談對(duì)Java雙冒號(hào)::的理解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • 基于Mybatis plus 自動(dòng)代碼生成器的實(shí)現(xiàn)代碼

    基于Mybatis plus 自動(dòng)代碼生成器的實(shí)現(xiàn)代碼

    本文通過(guò)實(shí)例代碼給大家介紹了基于Mybatis-plus 自動(dòng)代碼生成器的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-05-05
  • SpringDataJpa like查詢(xún)無(wú)效的解決

    SpringDataJpa like查詢(xún)無(wú)效的解決

    這篇文章主要介紹了SpringDataJpa like查詢(xún)無(wú)效的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • 基于AspectJ注解方式實(shí)現(xiàn)AOP

    基于AspectJ注解方式實(shí)現(xiàn)AOP

    這篇文章主要介紹了基于AspectJ注解方式實(shí)現(xiàn)AOP,使用AspectJ的注解可以更方便地編寫(xiě)和管理切面邏輯,而Spring AOP也是使用了AspectJ提供的注解來(lái)實(shí)現(xiàn)切面編程,需要的朋友可以參考下
    2023-09-09
  • Java實(shí)現(xiàn)五子棋(附詳細(xì)源碼)

    Java實(shí)現(xiàn)五子棋(附詳細(xì)源碼)

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • Java+element實(shí)現(xiàn)excel的導(dǎo)入和導(dǎo)出

    Java+element實(shí)現(xiàn)excel的導(dǎo)入和導(dǎo)出

    本文主要介紹了Java+element實(shí)現(xiàn)excel的導(dǎo)入和導(dǎo)出,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • 詳解如何使用SpringBoot封裝Excel生成器

    詳解如何使用SpringBoot封裝Excel生成器

    在軟件開(kāi)發(fā)過(guò)程中,經(jīng)常需要生成Excel文件來(lái)導(dǎo)出數(shù)據(jù)或者生成報(bào)表,為了簡(jiǎn)化開(kāi)發(fā)流程和提高代碼的可維護(hù)性,我們可以使用Spring Boot封裝Excel生成器,本文將介紹如何使用Spring Boot封裝Excel生成器,并提供一些示例代碼來(lái)說(shuō)明其用法和功能
    2023-06-06

最新評(píng)論

西丰县| 象山县| 依兰县| 潮州市| 南安市| 布尔津县| 滨州市| 保山市| 鹤山市| 崇州市| 霍州市| 启东市| 闻喜县| 隆化县| 武山县| 固安县| 阳城县| 灌云县| 平谷区| 洪洞县| 比如县| 亚东县| 成都市| 嵊州市| 类乌齐县| 南城县| 德令哈市| 湘潭市| 赫章县| 罗甸县| 海伦市| 来凤县| 和静县| 七台河市| 浦县| 民勤县| 德惠市| 余江县| 永安市| 社旗县| 启东市|