在正式笔之 前先来思考如何将java 的包打包成jar 包同,运行时指定配置,这样运行,

以上问题有空在来研究,有空在来补这个文档

首先呢,先来说说Session 怎么使用,这个在sping boot 很简单 ,就是通过属性来操作获取和设置

session 使用

import javax.servlet.http.HttpSession;

// ...

@PostMapping("/login")
public String login(@RequestParam String username, @RequestParam String password, HttpSession session) {
// 假设验证了用户名和密码
if (isValidUser(username, password)) {
// 将用户信息存入Session
session.setAttribute("user", username);
return "redirect:/home";
} else {
return "login";
}
} @GetMapping("/home")
public String home(HttpSession session, Model model) {
// 从Session中获取用户信息
String username = (String) session.getAttribute("user");
if (username != null) {
model.addAttribute("username", username);
return "home";
} else {
return "redirect:/login";
}
} 

session 也可以结合本地缓存

spring:
session:
store-type: redis
redis:
host: localhost
port: 6379 然后用redis 来记录 session @GetMapping("/setSessionId")
public String setSessionId(HttpSession session, HttpServletResponse response) {
// 生成一个新的Session ID
session.invalidate();
session = request.getSession(true); // 将新的Session ID发送给客户端(这里通过响应头)
response.setHeader("X-Session-Id", session.getId()); return "setSessionId";
} @GetMapping("/getSessionId")
public String getSessionId(@RequestHeader(value = "X-Session-Id", required = false) String sessionId, Model model) {
if (sessionId != null) {
// 使用Session ID从服务器获取Session
HttpSession session = request.getSession(false);
if (session != null && session.getId().equals(sessionId)) {
model.addAttribute("sessionId", sessionId);
return "getSessionId";
}
}
return "error";
}

  

jwt  使用   首先这个也是一个依融包,先导入后增加一个配置,然后配置挡截器类

这个先略,稍后总结

Spring Boot 中集成 Spring Security 进行基本的身份认证

如果我们是用idea 新建的springboot 一开始就勾选了  Spring Security 。那么在构建时idea 会帮我做一些默认配置,

所以一登陆就开始认证了,新增一下用户名为user   密码在控制显示是一个uuid 当然呢我们更想自己配置细节

$ecurityProperties
初始化配置,配置了默认的用户名(user)和密码(uuid)。在application.properties中配置自定义用户名和密码。
例如:
spring.security.user.name=myusername
spring.security.user.password=mypassword

  

配置路径上下文
server.servlet.context-path=/myapp

 

通过内存来管理

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager; @Configuration
public class WebSecurityConfig { @Bean
public UserDetailsService userDetailsService() {
// 创建基于内存的用户信息管理器
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User.withDefaultPasswordEncoder().username("user").password("password").roles("USER").build());
return manager;
}
}

java spring boot 权限认证总结瞎记一通,各种 方案。附近如何运行jar包。和如何读配文件的更多相关文章

  1. Java Spring Boot VS .NetCore (九) Spring Security vs .NetCore Security

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  2. 从零一起学Spring Boot之LayIM项目长成记(五)websocket

    前言 距离上一篇已经比较久的时间了,项目也是开了个头.并且,由于网上的关于Spring Boot的websocket讲解也比较多.于是我采用了另外的一个通讯框架 t-io 来实现LayIM中的通讯功能 ...

  3. 从零一起学Spring Boot之LayIM项目长成记(四) Spring Boot JPA 深入了解

    前言 本篇内容主要是一些关于JPA的常用的一些用法等.内容也是很多是看其他博客学来的,顺道在本系列博客里抽出一篇作为总结.下面让我们来看看吧. 不过我更推荐大家读本篇:https://lufficc. ...

  4. Java Spring Boot VS .NetCore (十一)自定义标签 Java Tag Freemarker VS .NetCore Tag TagHelper

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  5. 从零一起学Spring Boot之LayIM项目长成记(二) LayIM初体验

    前言 接上篇,已经完成了一个SpringBoot项目的基本搭建.那么现在就要考虑要做什么,怎么做的问题.所以本篇内容不多,带大家一起来简单了解一下要做的东西,之前有很多人不知道从哪里下手,那么今天我带 ...

  6. 从零一起学Spring Boot之LayIM项目长成记(一) 初见 Spring Boot

    项目背景 之前写过LayIM的.NET版后端实现,后来又写过一版Java的.当时用的是servlet,websocket和jdbc.虽然时间过去很久了,但是仍有些同学在关注.偶然间我听说了Spring ...

  7. 从零一起学Spring Boot之LayIM项目长成记(三) 数据库的简单设计和JPA的简单使用。

    前言 今天是第三篇了,上一篇简单模拟了数据,实现了LayIM页面的数据加载.那么今天呢就要用数据库的数据了.闲言少叙,书归正传,让我们开始吧. 数据库 之前有好多小伙伴问我数据库是怎么设计的.我个人用 ...

  8. Java Spring Boot VS .NetCore (一)来一个简单的 Hello World

    系列文章 Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filte ...

  9. Java Spring Boot VS .NetCore (二)实现一个过滤器Filter

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  10. Java Spring Boot VS .NetCore (三)Ioc容器处理

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

随机推荐

  1. linux服务器下安装cbc和ipopt求解器【踩坑总结】

    安装CBC求解器 CBC求解器是一个C++库,我们可以通过以下命令在Linux系统中进行安装: sudo apt-get install coinor-cbc 对于Windows操作系统,可以从CBC ...

  2. Qt程序运行报错

    报错内容 PC环境为Ubuntu20.04,Qt版本是Qt5.12.9,AsensingViewer是编译好的程序 ./AsensingViewer: error while loading shar ...

  3. itest work 开源接口测试&敏捷测试管理平台 9.5.0 GA_u4发布,优化及修复BUG

    (一)itest work 简介 itest work (爱测试)  一站式工作站让测试变得简单.敏捷,"好用.好看,好敏捷" ,是itest wrok 追求的目标.itest w ...

  4. 从零开始写 Docker(十七)---容器网络实现(中):为容器插上”网线“

    本文为从零开始写 Docker 系列第十七篇,利用 linux 下的 Veth.Bridge.iptables 等等相关技术,构建容器网络模型,为容器插上"网线". 完整代码见:h ...

  5. Java 集合的概念

    目录 集合 单列集合(Collection) Collection中的一些方法 public static < T > boolean addAll(Collection<? sup ...

  6. The solution of P9194

    10黑寄. problem & blog 考虑到处理加边并不简单,所以我们可以考虑一个黑点 \(p\),连边\((u,p)(p,v)\). 考虑在现在这棵树上连个点在原图中有变相连相当于有一个 ...

  7. SQL SERVER 同一台服务器,A库正常连接,B库提示“等待的操作过时”

    SQL SERVER 同一台服务器,A库正常连接,B库提示"等待的操作过时" 解决方法: 在客户端(非SQL SERVER 服务器)用管理员身份运行CMD,输入netsh wins ...

  8. 获取前(后)x月的日期

    package com.jesims.busresume.web; import org.springframework.stereotype.Service; import java.text.Da ...

  9. python类和对象初识

    # python类和对象初识 a = 2 b = 3 print(id(a)) print(type(a)) print(a) print(id(b)) print(type(b)) print(b) ...

  10. 高通Android分区表详解

    高通Android分区表详解 Label Purpose of this partition Modem Partition for modem Fsc Cookie partition to sto ...