基本上涉及到用户参与的系统都要进行权限管理,权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户可以访问而且只能访问自己被授权的资源。
权限管理包括用户身份认证鉴权(授权)两部分,简称认证授权。对于需要访问控制的资源用户首先经过身份认证,认证通过后用户具有该资源的访问权限方可访问
身份认证,就是判断一个用户是否为合法用户的处理过程。最常用的简单身份认证方式是系统通过核对用户输入的用户名和口令,看其是否与系统中存储的该用户的用户名和口令一致,来判断用户身份是否正确。对于采用指纹等系统,则出示指纹;对于硬件Key等刷卡系统,则需要刷卡。
Subject :主体
访问系统的用户,主体可以是用户、程序等,进行认证的都称为主体;
Principal :身份信息
是主体(subject)进行身份认证的标识,标识必须具有唯一性,如用户名、手机号、邮箱地址等,一个主体可以有多个身份,但是必须有一个主身份(Primary Principal)。
是只有主体自己知道的安全信息,如密码、证书等。
授权,即访问控制,控制谁能访问哪些资源。主体进行身份认证后需要分配权限方可访问系统的资源,对于某些资源没有权限是无法访问的。
下图中橙色为授权流程。
授权可简单理解为who对what(which)进行How操作:
RBAC基于角色的访问控制(Role-Based Access Control)是以角色为中心进行访问控制,比如:主体的角色为总经理可以查询企业运营报表,查询员工工资信息等,访问控制流程如下:
if(主体.hasRole("总经理角色id")){
查询工资
}
缺点:以角色进行访问控制粒度较粗,如果上图中查询工资所需要的角色变化为总经理和部门经理,此时就需要修改判断逻辑为“判断主体的角色是否是总经理或部门经理”,系统可扩展性差。
修改代码如下:
if(主体.hasRole(“总经理角色id”) || 主体.hasRole(“部门经理角色id”)){
查询工资
}
RBAC基于资源的访问控制(Resource-Based Access Control)是以资源为中心进行访问控制,比如:主体必须具有查询工资权限才可以查询员工工资信息等,访问控制流程如下:
上图中的判断逻辑代码可以理解为:
if(主体.hasPermission(“查询工资权限标识”)){
查询工资
}
优点:系统设计时定义好查询工资的权限标识,即使查询工资所需要的角色变化为总经理和部门经理也只需要将“查询工资信息权限”添加到“部门经理角色”的权限列表中,判断逻辑不用修改,系统可扩展性强。
Spring Security 是一个能够为基于 Spring 的企业应用系统提供声明式的安全访问控制解决方案的安全框架。它提供了一组可以在 Spring 应用上下文中配置的 Bean,充分利用了 Spring IoC(Inversion of Control 控制反转),DI(Dependency Injection 依赖注入)和 AOP(面向切面编程)功能,为应用系统提供声明式的安全访问控制功能,减少了为企业系统安全控制编写大量重复代码的工作。
Spring Security 拥有以下特性:
<!--springboot整合security坐标-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
@RestController
public class HelloController {
@GetMapping("hello")
public String hello(){
return "Hello Spring security";
}
}
访问:http://localhost:8080/hello 结果打开的是一个登录页面,其实这时候我们的请求已经被保护起来了,要想访问,需要先登录。
Spring Security 默认提供了一个用户名为 user 的用户,其密码在控制台可以找到
当然还可以通过配置类的方式进行配置,创建一个配置类去继承,实现自定义用户名密码登录
/**
* Spring Security配置类
* 在springboot2.7 后WebSecurityConfigurerAdapter弃用了,用2.5.4
*/
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// 对密码进行加密。123 是密码明文,现在 Spring Security 强制性要求『不允许明文存储密码』。
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String password = passwordEncoder.encode("123");
auth.inMemoryAuthentication().withUser("tom").password(password).roles("admin");
}
}
从 5.x 开始,强制性要求必须使用密码加密器(PasswordEncoder)对原始密码(注册密码)进行加密。因此,如果忘记指定 PasswordEncoder 会导致执行时会出现 There is no PasswordEncoder mapped for the id "null" 异常。
这是因为我们在对密码加密的时候使用到了 BCryptPasswordEncoder 对象,而 Spring Security 在对密码比对的过程中不会『自己创建』加密器,因此,需要我们在 Spring IoC 容器中配置、创建好加密器的单例对象,以供它直接使用。
所以,我们还需要在容器中配置、创建加密器的单例对象(上面那个 new 理论上可以改造成注入),修改Spring securitry配置类
/**
* Spring Security配置类
* 在springboot2.7后WebSecurityConfigurerAdapter弃用了,用2.5.4
*/
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// 对密码进行加密。123 是密码明文,现在 Spring Security 强制性要求『不允许明文存储密码』。
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String password = passwordEncoder.encode("123");
auth.inMemoryAuthentication().withUser("tom").password(password).roles("admin");
}
/**
* 将PasswordEncoder注入到ioc容器
* @return
*/
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
我们获取用户名和密码都是从数据库中获取,所以用以上方式不合理,引出auth.userDetailsService() ,使用UserDetailsService来实现从数据库中查用户名和密码
Spring Security 内置的 Password Encoder 有:

上述 Password Encoder 中有一个『无意义』的加密器:NoOpPasswordEncoder 。它对原始密码没有做任何处理(现在也被标记为废弃)。
记得使用 @SuppressWarnings(“deprecation”) 去掉 IDE 的警告信息。
AuthenticationManager
它是 “表面上” 的做认证和鉴权比对工作的那个人,它是认证和鉴权比对工作的起点。
ProvierderManager 是 AuthenticationManager 接口的具体实现。
AuthenticationProvider
它是 “实际上” 的做认证和鉴权比对工作的那个人。从命名上很容易看出,Provider 受 ProviderManager 的管理,ProviderManager 调用 Provider 进行认证和鉴权的比对工作。
我们最常用到 DaoAuthenticationProvider 是 AuthenticationProvider 接口的具体实现。
UserDetailsService
虽然 AuthenticationProvider 负责进行用户名和密码的比对工作,但是它并不清楚用户名和密码的『标准答案』,而标准答案则是由 UserDetailsService 来提供。简单来说,UserDetailsService 负责提供标准答案 ,以供 AuthenticationProvider 使用。
UserDetails
UserDetails 它是存放用户认证信息和权限信息的标准答案的 “容器” ,它也是 UserDetailService “应该” 返回的内容。
PasswordEncoder
Spring Security 要求密码不能是明文,必须经过加密器加密。这样,AuthenticationProvider 在做比对时,就必须知道『当初』密码时使用哪种加密器加密的。所以,AuthenticationProvider 除了要向 UserDetailsService 『要』用户名密码的标准答案之外,它还需要知道配套的加密算法(加密器)是什么
Spring Security 要求 UserDetailsService 将用户信息的 “标准答案” 必须封装到一个 UserDetails 对象中,返回给 AuthenticationProvider 使用(做比对工作)。
我们可以直接使用 Spring Security 内置的 UserDetails 的实现类:User 。
/**
* spring security认证业务类
*/
@Service
public class MyUserDetailsService implements UserDetailsService {
//为passwordEncoder注入值
@Autowired
private UserDao userDao;
@Autowired
private PasswordEncoder passwordEncoder;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//调用dao到数据库中根据username查找用户信息
Users users = userDao.getByUserName(username);
try {
//将查找到的用户帐号与密码保存到Security的User对象中由Security进行比对
return new User(users.getUsername(), passwordEncoder.encode(users.getPassword()),
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_ADMIN")); //配置登录用户有哪些角色和权限,此处模拟直接写死
}catch (Exception e){
throw new UsernameNotFoundException("用户"+username+"不存在");
}
}
}
修改spring security配置类
/**
* Spring Security配置类
*
*
*/
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
/**
* 属性注入和构造注入区别
* 1、属性注入时,Spring IOC容器“创建对象”和为对象属性赋值两件事情是分开做的。
* 构造注入时,Spring IOC容器直接调用类的有参构造,这样“创建对象”和为对象
* 属性赋值两件事情是一起做的
* 2、属性注入没法表达对象创建的“先后/依赖关系”,但是构造注入可以
* 属性注入天然能解决循环依赖问题,但是构造注入要使用@Lazy注解
* 所以建议单例对象的必要属性用构造注入,可选属性使用属性注入
*/
@Resource
private MyUserDetailsService userDetailsService;
public SecurityConfig(@Lazy MyUserDetailsService myUserDetailsService) {
this.userDetailsService = myUserDetailsService;
}
/**
* 将PasswordEncoder注入到ioc容器
* @return
*/
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
}
ProviderManager/AuthenticationProvider 在做密码密码的比对工作时,会调用 UserDetailsService 的 .loadUserByUsername() 方法,并传入『用户名』,用以查询该用户的密码和权限信息。
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin();//1
http.authorizeRequests()
.anyRequest()
.authenticated(); // 2
http.csrf().disable(); // 3
}
代码配置的链式调用连写:
http.formLogin()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf().disable();
以上配置的意思是:
| # | 说明 |
|---|---|
| 1 | 要求用户登陆时,是使用表单页面进行登陆。但是,由于我们有意/无意中没有指明登陆页面,因此,Spring Security 会使用它自己自带的一个登陆页面。 |
| 2 | 同上,让 Spring Security 拦截所有请求。要求所有请求都必须通过认证才能放行,否则要求用户登陆。 |
| 3 | 同上,暂且认为是固定写法。后续专项讲解。 |
|
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<form action="dologin" method="post">
<!--注意:帐号和密码的名称必须是username和password否则spring security无法识别-->
<p>帐号:<input type="text" name="username"></p>
<p>密码:<input type="text" name="password"></p>
<p><button type="submit">登录</button></p>
</form>
</body>
</html>
SpringSecurityConfig 类中的配置代码
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin()
.loginPage("/login.html")//配置需要显示的登录页面
.loginProcessingUrl("/dologin") //配置登录请求路径,很from表单的 action 要对应上
.defaultSuccessUrl("/index") //默认登录成功后跳转地址
.permitAll()//这句配置很重要,新手容易忘记。放开 login.html和dologin 的访问权
.and().authorizeRequests()
.anyRequest().authenticated(); // 除了antMatchers() 配的页面,其他都需要认证
http.csrf().disable();
}
当前用户是否有权限访问某个 URI 的相关配置也是写在 configure(HttpSecurity http) 方法中。
.antMatchers() 方法是一个采用 ANT 风格的 URL 匹配器。
| 权限表达式 | 说明 |
|---|---|
| permitAll() | 永远返回 true |
| denyAll() | 永远返回 false |
| anonymous() | 当前用户是匿名用户(anonymous)时返回 true |
| rememberMe() | 当前用户是 rememberMe 用户时返回 true |
| authentication | 当前用户不是匿名用户时,返回 true |
| fullyAuthenticated | 当前用户既不是匿名用户,也不是 rememberMe 用户时,返回 true |
| hasRole(“role”) | 当用户拥有指定身份时,返回 true |
| hasAnyRole(“role1”, “role2”, …) | 当用户返回指定身份中的任意一个时,返回 true |
| hasAuthority(“authority1”) | 当用于拥有指定权限时,返回 true |
| hasAnyAuthority(“authority1”, “authority2”) | 当用户拥有指定权限中的任意一个时,返回 true |
| hasIpAddress(“xxx.xxx.x.xxx”) | 发送请求的 ip 符合指定时,返回 true |
| principal | 允许直接访问主体对象,表示当前用户 |
hasRole():数据库用户角色必须加 ROLE_ 前缀,而用hasRole() security会自动加上ROLE_ 前缀,自己不能加上ROLE_ 前缀,例如
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_admin")
对上
hasRole("admin")
hasAuthority() 数据库角色名称和方法内容一致 例如:
AuthorityUtils.commaSeparatedStringToAuthorityList("admin")
对上
hasRole("admin")
语法:
http.authorizeRequests()
.antMatchers("/user/insert").hasAuthority("user:insert")
.antMatchers("/user/modify").hasAuthority("user:modify")
.antMatchers("/user/delete").hasAuthority("user:delete")
.antMatchers("/user/query").hasAuthority("user:query")
.antMatchers("/user/**").hasAnyRole("USER", "ADMIN")
.antMatchers("/user-can-do").hasRole("USER") //
.antMatchers("/admin-can-do").hasRole("ADMIN") // 同上
.antMatchers("/all-can-do").permitAll()
.anyRequest().authenticated(); // 除了上面的权限以外的,都必须登录才能访问
提示:本质上 .hasRole("xxx") 和 .hasAuthority("xxx") 并没有太大区别,但是,.hashRole() 在做比对时,会在里面内容前面拼上 ROLE_ 。所以,确保你的 Role 的『标准答案』是以 Role_ 开头
在使用hasRole() 和 hasAnyRole() 时候,设置角色时候要加ROLE_ 前缀
return new User(users.getUsername(), passwordEncoder.encode(users.getPassword()),
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_admin"));
没有权限跳转到自定义页面
http.exceptionHandling().accessDeniedPage("/error"); //没有权限跳转到自定义页面
http.formLogin()
.loginPage("/hello")//配置需要显示的登录页面
.loginProcessingUrl("/dologin") //配置登录请求路径
.defaultSuccessUrl("/index")
.permitAll()//这句配置很重要,新手容易忘记。放开 login.html和dologin 的访问权
.and().authorizeRequests()
.antMatchers("/","/hello").permitAll()// 设置哪些路劲不需要登录,能直接当问
.antMatchers("/toupdate").hasAuthority("asd")
.anyRequest().authenticated(); // 除了antMatchers() 配的页面,其他都需要认证
http.csrf().disable();
在实际的使用过程中用户的鉴权并不是通过置来写的而是通过注解来进行,Spring Security 默认是禁用注解的。
要想开启注解功能需要在配置类上加入 @EnableGlobalMethodSecurity注解来判断用户对某个控制层的方法是否具有访问权限。
注解就是用来替换springSecurity配置类中的http.authorizeRequests()配置
Spring Security 支持三套注解:
| 注解类型 | 注解 |
|---|---|
| jsr250 注解 | @DenyAll、@PermitAll、@RolesAllowed |
| secured 注解 | @Secured |
| prePost 注解 | @PreAuthorize、@PostAuthorize |
使用什么注解在@EnableGlobalMethodSecurity开启,默认是关闭的,例如
@EnableWebSecurity
@EnableGlobalMethodSecurity(jsr250Enabled = true,securedEnabled=true) //开启jsr250和secured注解
public class SecurityConfig extends WebSecurityConfigurerAdapter {
}
secured 注解
@Secured 注解是 jsr250 标准出现之前,Spring Security 框架自己定义的注解。
@Secured 标注于方法上,表示只有具有它所指定的角色的用户才可以调用该方法。如果当前用户不具备所要求的角色,那么,将会抛出 AccessDenied 异常,注解和配置类都要加上ROLE_ 前缀
@RestController
public class UserController {
@Secured({"ROLE_USER","ROLE_ADMIN"}) // 这里加前缀 ROLE_,
@RequestMapping("/all-can-do")
public String show7(){
return "all-can-do";
}
@Secured("ROLE_USER")
@RequestMapping("/admin-can-do")
public String show6(){
return "admin-can-do";
}
}
配置类
return new User(users.getUsername(), passwordEncoder.encode(users.getPassword()),
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")); //配置登录用户有哪些角色和权限
JSR-250 注解
@DenyAll: 所有用户都不可以访问
@PermitAll:所有用户都可以访问
@RolesAllowed:用法同@Secured差不多,区别是注解上ROLE_ 可加可不加,但是配置类上必须加ROLE_ 前缀
prePost 注解
@PreAuthorize可以用来控制一个方法是否能够被调用。
@PreAuthorize(“hasRole(‘ROLE_ADMIN’)”)
publicvoid addUser(User user) {
System.out.println(“addUser…” + user);
}
@PreAuthorize(“hasRole(‘ROLE_USER’) or hasRole(‘ROLE_ADMIN’)”)
public User find(int id) {
System.out.println(“find user by id…” + id);
returnnull;
}
@DenyAll: 所有用户都不可以访问
@PermitAll:所有用户都可以访问
@RolesAllowed:用法同@Secured差不多,区别是注解上ROLE_ 可加可不加,但是配置类上必须加ROLE_ 前缀
prePost 注解
@PreAuthorize可以用来控制一个方法是否能够被调用。
@PreAuthorize(“hasRole(‘ROLE_ADMIN’)”)
publicvoid addUser(User user) {
System.out.println(“addUser…” + user);
}
@PreAuthorize(“hasRole(‘ROLE_USER’) or hasRole(‘ROLE_ADMIN’)”)
public User find(int id) {
System.out.println(“find user by id…” + id);
returnnull;
}
@PostAuthorize在方法调用完之后进行权限检查。
@PostAuthorize(“returnObject.id%2==0”)
public User find(int id) {
User user = new User();
user.setId(id);
return user;
}
如果返回值的id是偶数则表示校验通过,否则表示校验失败,将抛出AccessDeniedException
实际开发中最常用的写法 使用 @PreAuthorize(“hasRole(‘admin’)”)
@RequestMapping("insert")
@PreAuthorize("hasAnyAuthority('admin')")
public String insert(){
return "insert";
}
在某些前后端完全分离,仅靠 JSON 完成所有交互的系统中,一般会在登陆成功时返回一段 JSON 数据,告知前端,登陆成功与否。在这里,可以通过 .successHandler 方法和 .failureHandler 方法指定『认证通过』之后和『认证未通过』之后的处理逻辑。
/**
* 认证成功的处理器类
*/
@Component
public class SimpleAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
Authentication authentication) throws IOException, ServletException {
// authentication 对象携带了当前登陆用户名等相关信息
//User user = (User) authentication.getPrincipal();
httpServletResponse.setContentType("application/json;charset=UTF-8");
ResponseResult<Void> ok = new ResponseResult<>(200, "登录成功");
//使用jacksong将对象序列化为josn字符串
ObjectMapper mapper=new ObjectMapper();
String json=mapper.writeValueAsString(ok);
//输出json字符串到客户端
PrintWriter printWriter = httpServletResponse.getWriter();
printWriter.print(json);
printWriter.flush();
printWriter.close();
}
}
/**
* 登录失败处理器
*/
public class SimpleAuthenticationFailureHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest request,
HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
//响应请求转码
response.setContentType("application/json;charset=UTF-8");
System.out.println(exception);
//exception就是登录失败时的异常对象
ResponseResult<Void> responseResult=null;
if(exception instanceof InternalAuthenticationServiceException){
responseResult=new ResponseResult<>(2001, "用户名错误!");
}
if(exception instanceof BadCredentialsException){
responseResult=new ResponseResult<>(2002, "密码错误!");
}
//使用jacksong将对象序列化为josn字符串
ObjectMapper mapper=new ObjectMapper();
String json=mapper.writeValueAsString(responseResult);
//输出json字符串到客户端
PrintWriter printWriter =response.getWriter();
printWriter.print(json);
printWriter.flush();
printWriter.close();
}
}
修改spring security配置类
@Resource
private SimpleAuthenticationSuccessHandler simpleAuthenticationSuccessHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
/**
* 资源权限相关配置
* 配置哪些路径需要什么权限才能访问
*/
http.authorizeRequests()
.antMatchers("/user/insert").hasAuthority("user:insert")
.antMatchers("/user/modify").hasAuthority("user:modify")
.antMatchers("/user/delete").hasAuthority("user:delete")
.antMatchers("/user/query").hasAuthority("user:query")
.antMatchers("/user/**").hasAnyRole("USER", "ADMIN")
.antMatchers("/user-can-do").hasRole("USER") // 这里本质上应该是 ROLE_USER,但是 ROLE_ 要移除。不过你所提供的标准答案中,又必须要有 ROLE_ !
.antMatchers("/admin-can-do").hasRole("ADMIN") // 同上
.antMatchers("/all-can-do").permitAll()
.anyRequest().authenticated(); // 除了上面的权限以外的,都必须登录才能访问
//登录相关配置
http.formLogin()
.loginPage("/login.html")//配置需要显示的登录页面
.loginProcessingUrl("/dologin") //告诉spring security登录页面发送这个请求时spring secruity就做登录认证
.successHandler(new simpleAuthenticationSuccessHandle())//配置登录成功后的处理器
.failureHandler(new SimpleAuthenticationFailureHandler())//配置登录失败后的处理器
.permitAll();//这句配置很重要,新手容易忘记。放开 login.html和dologin 的访问权
http.csrf().disable();
}
我正在使用Ruby2.1.1和Rails4.1.0.rc1。当执行railsc时,它被锁定了。使用Ctrl-C停止,我得到以下错误日志:~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`gets':Interruptfrom~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`verify_server_version'from~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.
转自:spring.profiles.active和spring.profiles.include的使用及区别说明下文笔者讲述spring.profiles.active和spring.profiles.include的区别简介说明,如下所示我们都知道,在日常开发中,开发|测试|生产环境都拥有不同的配置信息如:jdbc地址、ip、端口等此时为了避免每次都修改全部信息,我们则可以采用以上的属性处理此类异常spring.profiles.active属性例:配置文件,可使用以下方式定义application-${profile}.properties开发环境配置文件:application-dev
我无法运行Spring。这是错误日志。myid-no-MacBook-Pro:myid$spring/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/lib/spring/sid.rb:17:in`fiddle_func':uninitializedconstantSpring::SID::DL(NameError)from/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/li
目录SpringBootStarter是什么?以前传统的做法使用SpringBootStarter之后starter的理念:starter的实现: 创建SpringBootStarter步骤在idea新建一个starter项目、直接执行下一步即可生成项目。 在xml中加入如下配置文件:创建proterties类来保存配置信息创建业务类:创建AutoConfiguration测试如下:SpringBootStarter是什么? SpringBootStarter是在SpringBoot组件中被提出来的一种概念、简化了很多烦琐的配置、通过引入各种SpringBootStarter包可以快速搭建出一
文章目录前言一、Elasticsearch版本介绍二、客户端种类三、客户端与版本兼容性四、引入Elasticsearch依赖包五、客户端配置六、Elasticsearch使用前言ElasticSearch是Elastic公司出品的一款功能强大的搜索引擎,被广泛的应用于各大IT公司,它的代码位于https://github.com/elastic/elasticsearch,目前是一个开源项目。ElasticSearch公司的另外两个开源产品Logstash、Kibana与ElasticSearch构成了著名的ELK技术栈。。他们三个共同形成了一个强大的生态圈。简单地说,Logstash负责数据
有道无术,术尚可求,有术无道,止于术。本系列SpringBoot版本3.0.4本系列SpringSecurity版本6.0.2本系列SpringAuthorizationServer版本1.0.2源码地址:https://gitee.com/pearl-organization/study-spring-security-demo文章目录前言1.OAuth2AuthorizationServerMetadataEndpointFilter2.OAuth2AuthorizationEndpointFilter3.OidcProviderConfigurationEndpointFilter4.N
如何用IDEA2022创建并初始化一个SpringBoot项目?目录如何用IDEA2022创建并初始化一个SpringBoot项目?0. 环境说明1. 创建SpringBoot项目 2.编写初始化代码0. 环境说明IDEA2022.3.1JDK1.8SpringBoot1. 创建SpringBoot项目 打开IDEA,选择NewProject创建项目。 填写项目名称、项目构建方式、jdk版本,按需要修改项目文件路径等信息。 选择springboot版本以及需要的包,此处只选择了springweb。 此处需特别注意,若你使用的是jdk1
我正在尝试为我的gem编写规范,它生成otp并将其保存在数据库中。现在我正在为它编写规范。所以基本上我有三种方法generate_otp!、regenerate_otp!、verify_otp(otp)。generate_otp!的作用是调用包含三个变量的方法generate_otpotp_code-基本上是使用secure_random生成的随机值otp_verified-一个bool值,用于设置otp是否已验证的状态otp_expiry_time-设置otp的到期时间,可以由Rails应用在配置中设置。这三个也是我的数据库的列。在generate_otp之后,我正在调用active
我今天遇到了同样的问题,有一个建议:在您的命令前添加bundleexec可能会解决此问题。前置bundleexec没有帮助(我已经这样做了)。springstop和springrestart没有帮助。我需要做的:bundleupdatespring这对我有用。在之前的gemlock文件中使用spring版本是否有更好的解决方案? 最佳答案 我删除gemfile.lock并运行bundle通常会清除一切。否则只需从Gemfile中删除gem"spring"并运行bundle 关于ruby-
前言微信支付是企业级项目中经常使用到的功能,作为后端开发人员,完整地掌握该技术是十分有必要的。一、申请流程和步骤图1-1注册微信支付账号获取微信小程序APPID获取微信商家的商户ID获取微信商家的API私钥配置微信支付回调地址绑定微信小程序和微信支付的关系搭建SpringBoot工程编写后台支付接口发布部署接口服务项目使用微信小程序或者UniAPP调用微信支付功能支付接口的封装配置jwt或者openid的token派发原生微信小程序完成支付对接二、注册商家2.1商户平台商家或者企业想要通过微信支付来进行商品的销售,必须先通过微信平台(pay.weixin.qq.com)去将商家进行注册。注册成