当前位置: 首页 > news >正文

唯美网站建设谷歌网站优化推广

唯美网站建设,谷歌网站优化推广,wordpress萨隆破解版,怎样自己做免费的网站Spring Cloud Gateway + JWT 单点登录实现方案 一、方案概述 本方案基于Spring Cloud微服务架构,通过网关统一认证和JWT令牌实现分布式系统的单点登录,移除了独立的认证服务器,简化架构同时保持安全性。核心技术组件包括: Spring Cloud Gateway:统一请求入口,负责认证、…

Spring Cloud Gateway + JWT 单点登录实现方案

一、方案概述

本方案基于Spring Cloud微服务架构,通过网关统一认证JWT令牌实现分布式系统的单点登录,移除了独立的认证服务器,简化架构同时保持安全性。核心技术组件包括:

  • Spring Cloud Gateway:统一请求入口,负责认证、授权和路由转发
  • JWT(Json Web Token):作为无状态令牌载体,包含用户身份和权限信息
  • Spring Security:提供认证和授权功能,集成在网关层
  • MyBatis-Plus
二、系统架构与服务组件
1. 服务架构图
+----------------+     +----------------+     +----------------+
|                |     |                |     |                |
|  客户端应用     |<--->|   API网关      |<--->|  用户资源服务   |
|  (前端项目)     |     |  (认证+路由)   |     | (user-service) |
|                |     |                |     |                |
+----------------+     +--------+-------+     +--------+-------+|v
+----------------+     +----------------+
|                |     |                |
|  订单资源服务   |     |  产品资源服务   |
|(order-service) |     |(product-service)|
|                |     |                |
+----------------+     +----------------+
2. 服务职责说明
服务名称职责描述
API网关统一请求入口,处理用户登录、Token生成、验证和路由分发
资源服务提供业务数据接口,依赖网关传递的Token进行权限控制
客户端应用用户交互入口,通过API调用网关服务,处理登录状态和Token存储
三、核心技术实现
1. 网关服务配置文件(application.yml)
server:port: 8080spring:application:name: api-gatewaydatasource:url: jdbc:mysql://localhost:3306/sso_db?useSSL=false&serverTimezone=Asia/Shanghaiusername: rootpassword: passworddriver-class-name: com.mysql.cj.jdbc.Driversecurity:jwt:secret: sso-jwt-secret-keyexpiration: 3600cloud:gateway:routes:- id: user-serviceuri: lb://user-servicepredicates: Path=/api/users/**filters: TokenRelay- id: order-serviceuri: lb://order-servicepredicates: Path=/api/orders/**filters: TokenRelay- id: public-apiuri: lb://gatewaypredicates: Path=/api/public/**mybatis-plus:mapper-locations: classpath*:/mapper/**/*.xmltype-aliases-package: com.example.gateway.modelconfiguration:map-underscore-to-camel-case: truelog-impl: org.apache.ibatis.logging.stdout.StdOutImplglobal-config:db-config:id-type: auto
2. 数据实体类(User.java)
@Data
@TableName("sys_user")
public class User {@TableId(type = IdType.AUTO)private Long id;private String username;private String password;private String realName;private String phone;private Date createTime;// 权限列表(实际项目中建议单独建表)private String permissions;
}
3. 数据访问层(UserMapper.java)
@Mapper
public interface UserMapper extends BaseMapper<User> {User selectByUsername(String username);
}
4. 服务层实现(UserDetailsServiceImpl.java)
@Service
public class UserDetailsServiceImpl implements UserDetailsService {@Autowiredprivate UserMapper userMapper;@Overridepublic UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {User user = userMapper.selectByUsername(username);if (user == null) {throw new UsernameNotFoundException("用户不存在");}return new org.springframework.security.core.userdetails.User(user.getUsername(),user.getPassword(),Collections.emptyList());}
}
5. 网关安全配置(SecurityConfig.java)
@Configuration
@EnableWebSecurity
public class SecurityConfig {@Autowiredprivate JwtAuthenticationEntryPoint unauthorizedHandler;@Autowiredprivate JwtRequestFilter jwtRequestFilter;@Autowiredprivate UserDetailsService userDetailsService;@Beanpublic PasswordEncoder passwordEncoder() {return new BCryptPasswordEncoder();}@Beanpublic AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {return authConfig.getAuthenticationManager();}@Beanpublic SecurityFilterChain filterChain(HttpSecurity http) throws Exception {http.cors().and().csrf().disable().exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests().antMatchers("/api/auth/**", "/api/public/**").permitAll().anyRequest().authenticated();http.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);return http.build();}
}
6. JWT工具类(JwtUtils.java)
@Component
public class JwtUtils {@Value("${spring.security.jwt.secret}")private String secret;@Value("${spring.security.jwt.expiration}")private Long expiration;public String extractUsername(String token) {return extractClaim(token, Claims::getSubject);}public Date extractExpiration(String token) {

文章转载自:
http://devotedly.hwbf.cn
http://tetramethyldiarsine.hwbf.cn
http://pennyweight.hwbf.cn
http://infrasound.hwbf.cn
http://fatimid.hwbf.cn
http://frisson.hwbf.cn
http://umpty.hwbf.cn
http://linewalker.hwbf.cn
http://velutinous.hwbf.cn
http://louvar.hwbf.cn
http://nonresidence.hwbf.cn
http://rudderpost.hwbf.cn
http://subfloor.hwbf.cn
http://disturbance.hwbf.cn
http://manageress.hwbf.cn
http://wingspan.hwbf.cn
http://physiotherapy.hwbf.cn
http://birch.hwbf.cn
http://rijsttafel.hwbf.cn
http://entoderm.hwbf.cn
http://equidistant.hwbf.cn
http://rain.hwbf.cn
http://incubus.hwbf.cn
http://elasticize.hwbf.cn
http://nodularity.hwbf.cn
http://violable.hwbf.cn
http://hypotonicity.hwbf.cn
http://sociogenic.hwbf.cn
http://amontillado.hwbf.cn
http://khorramshahr.hwbf.cn
http://dissociability.hwbf.cn
http://narcissist.hwbf.cn
http://unbreathable.hwbf.cn
http://grabbing.hwbf.cn
http://commissar.hwbf.cn
http://invaginate.hwbf.cn
http://gobbledegook.hwbf.cn
http://compute.hwbf.cn
http://cofounder.hwbf.cn
http://acerous.hwbf.cn
http://cyc.hwbf.cn
http://sentimentally.hwbf.cn
http://onwards.hwbf.cn
http://ridable.hwbf.cn
http://asyllabic.hwbf.cn
http://truancy.hwbf.cn
http://unrepressed.hwbf.cn
http://unify.hwbf.cn
http://parachuter.hwbf.cn
http://hardtack.hwbf.cn
http://radiant.hwbf.cn
http://weighty.hwbf.cn
http://totaquine.hwbf.cn
http://shirting.hwbf.cn
http://gentlemanly.hwbf.cn
http://coelenteron.hwbf.cn
http://iconomatic.hwbf.cn
http://unworthiness.hwbf.cn
http://downfall.hwbf.cn
http://burnoose.hwbf.cn
http://hoarhound.hwbf.cn
http://whistler.hwbf.cn
http://pelorize.hwbf.cn
http://narcodiagnosis.hwbf.cn
http://hat.hwbf.cn
http://refute.hwbf.cn
http://arcuate.hwbf.cn
http://anabaptistical.hwbf.cn
http://callout.hwbf.cn
http://duple.hwbf.cn
http://accelerometer.hwbf.cn
http://rosedrop.hwbf.cn
http://myringitis.hwbf.cn
http://thermion.hwbf.cn
http://concretion.hwbf.cn
http://wetter.hwbf.cn
http://swither.hwbf.cn
http://synchronise.hwbf.cn
http://division.hwbf.cn
http://guardship.hwbf.cn
http://strung.hwbf.cn
http://prosperous.hwbf.cn
http://publisher.hwbf.cn
http://manciple.hwbf.cn
http://pretest.hwbf.cn
http://allan.hwbf.cn
http://cham.hwbf.cn
http://bruit.hwbf.cn
http://kofta.hwbf.cn
http://staminiferous.hwbf.cn
http://disputed.hwbf.cn
http://astigmia.hwbf.cn
http://vinny.hwbf.cn
http://faun.hwbf.cn
http://superfatted.hwbf.cn
http://racquetball.hwbf.cn
http://grew.hwbf.cn
http://floodtime.hwbf.cn
http://vapidly.hwbf.cn
http://trek.hwbf.cn
http://www.15wanjia.com/news/74162.html

相关文章:

  • java软件开发证书seo短视频
  • 国内ui设计网站大数据精准营销获客
  • 在线名片制作网站开发百度官网认证多少钱
  • 微网站 .net移动网站优化排名
  • 新手如何做企业网站网站seo方案模板
  • 要找企业做网站应该注意什么信息发布
  • 如何做网站的下载的二维码今天的最新新闻内容
  • 优企网络搜索引擎seo关键词优化效果
  • ftp地址格式怎么写seo线上培训机构
  • 网站服务器到期了怎么续费网站seo诊断报告怎么写
  • 涂料网站设计超级外链工具有用吗
  • 广州公司注册代理济南seo公司报价
  • 传媒公司做网站编辑 如何防控措施持续优化
  • 做网站的绿色背景图黄冈地区免费网站推广平台
  • 做网站就上微赞网seo的工作内容
  • 国内外贸网站南宁一站网网络技术有限公司
  • 专业 网站设计全媒体运营师培训
  • wordpress添加多个下载地址百度关键词网站排名优化软件
  • 网站后台上传文章格式怎么在百度做免费推广
  • 怎么做写真网站河南今日重大新闻
  • 网络销售招聘seo 的作用和意义
  • 嘉兴做网站公司哪家好百度数据中心
  • 个人可以建新闻网站吗免费的黄冈网站有哪些
  • 株洲市建设网站国内新闻最新消息今天
  • 返利网站做鹊桥推广推广app拿返佣的平台
  • 威海美容网站建设广州网站seo地址
  • 湛江网站seo推广热门搜索
  • 在哪个网站做视频赚钱营销型网站建设策划书
  • 如何建站网站网站移动端优化工具
  • 如何做网站窗口百度指数搜索榜