Spring Cloud微服务安全实例分析

发布时间:2021-12-27 16:05:30 作者:iii
来源:亿速云 阅读:108

这篇文章主要介绍“Spring Cloud微服务安全实例分析”,在日常操作中,相信很多人在Spring Cloud微服务安全实例分析问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Spring Cloud微服务安全实例分析”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

  采用流行的微服务架构开发,应用程序访问安全将会面临更多更复杂的挑战,尤其是开发者最关心的三大问题:认证授权、可用性、可视化。本课程从简单的API安全入手,过渡到复杂的微服务场景,解决上述三大问题痛点,并结合实际给出相应解决方案。帮助大家形成对安全问题的系统性思考,实战开发一套可在中小公司落地的完整的安全方案。

  适合人群

  希望对微服务安全形成系统认识

  搭建一套完整落地方案的开发者

  技术储备要求

  Java Web开发基础

  Spring Boot2基础

  微服务基础知识

  package whu.extract.pubtime.core;

  import java.util.ArrayList;

  import java.util.Calendar;

  import java.util.Collections;

  import java.util.List;

  import java.util.regex.Matcher;

  import java.util.regex.Pattern;

  import whu.utils.TimeUtil;

  /**

  Created On 2014年3月13日 下午2:49:05

  @description 獲取網頁的發佈時間

  /

  public class FetchPubTime {

  / 表示url中連續的8位日期,

  private static String url_regwhole= "([-|/|]{1}20\d{6})";

  / 表示 用-或者/隔開的日期,有年月日的

  private static String url_reg_sepymd = "([-|/|]{1}20\d{2}[-|/|]{1}\d{1,2}[-|/|]{1}\d{1,2})";

  / 表示 用-或者/隔開的日期,只要年和月份的

  private static String url_reg_sepym = "([-|/|]{1}20\d{2}[-|/|_]{1}\d{1,2})";

  private static Calendar current = Calendar.getInstance();

  / 格式正確的時間正則表達式/

  private static String rightTimeReg = "^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$";

  /**

  @param url

  @param urlContent

  @return

  */

  public static String getPubTimeVarious(String url,String urlContent) {

  String pubTime = getPubTimeFromUrl(url);

  //链接里面沒有,匹配文本中的

  if(pubTime == null)

  {

  if(urlContent!=null&&!urlContent.trim().equals(""))

  return extractPageDate(urlContent);

  }

  return pubTime;

  }

  /**從url里面抽取動身佈時間,返回YYYY-MM-DD HH:mm:ss格式的字符串

  @param url

  @return

  */

  public static String getPubTimeFromUrl(String url)

  {

  Pattern p_whole = Pattern.compile(url_reg_whole);

  Matcher m_whole = p_whole.matcher(url);

  if(m_whole.find(0)&&m_whole.groupCount()>0)

  {

  String time = m_whole.group(0);

  time = time.substring(1,time.length());

  //每一步都不可以超出當前時間

  if(current.compareTo(TimeUtil.strToCalendar(time, "yyyyMMdd"))>=0)

  {

  return time.substring(0,4)+"-"+time.substring(4,6)+"-"+

  time.substring(6,8)+" "+"00:00:00";

  }

  }

  p_whole = null;

  m_whole = null;

  Pattern p_sep = Pattern.compile(url_reg_sep_ymd);

  Matcher m_sep = p_sep.matcher(url);

  if(m_sep.find(0)&&m_sep.groupCount()>0)

  {

  String time = msep.group(0);

  time = time.substring(1,time.length());

  String[] seg = time.split("[-|/|]{1}");

  Calendar theTime = Calendar.getInstance();

  theTime.set(Calendar.YEAR,Integer.parseInt(seg[0]));

  theTime.set(Calendar.MONTH, Integer.parseInt(seg[1]));

  theTime.set(Calendar.DAY_OF_MONTH, Integer.parseInt(seg[2]));

  if(current.compareTo(theTime)>=0)

  {

  return seg[0]+"-"+seg[1]+"-"+seg[2]+" "+"00:00:00";

  }

  }

  p_sep = null;

  m_sep = null;

  Pattern p_sep_ym = Pattern.compile(url_reg_sep_ym);

  Matcher m_sep_ym = p_sep_ym.matcher(url);

  if(m_sep_ym.find(0)&&m_sep_ym.groupCount()>0)

  {

  String time = m_sepym.group(0);

  time = time.substring(1,time.length());

  Calendar theTime = Calendar.getInstance();

  String[] seg = time.split("[-|/|]{1}");

  theTime.set(Calendar.YEAR,Integer.parseInt(seg[0]));

  theTime.set(Calendar.MONTH, Integer.parseInt(seg[1]));

  theTime.set(Calendar.DAY_OF_MONTH, 1);

  if(current.compareTo(theTime)>=0)

  {

  return seg[0]+"-"+seg[1]+"-"+"01"+" "+"00:00:00";

  }

  }

  return null;

  }

  /** 從網頁源码中取動身佈時間

  java中正則表達式提取字符串中日期完成代码

  2013年12月19日15:58:42

  讀取出2013-12-19 15:48:33或者2013-12-19或者2012/3/05方式的時間

  北海购房网 http://house.bh.goufang.com/lpfangjia/

  @param text 待提取的字符串

  @return 返回日期

  @author: oschina

  @Createtime: Jan 21, 2013

  */

  public static String extractPageDate(String text) {

  boolean containsHMS =false;

  String dateStr = text.replaceAll("r?n", " ");

  try {

  List matches = null;

  Pattern p_detail = Pattern.compile("(20\d{2}[-/]\d{1,2}[-/]\d{1,2} \d{1,2}:\d{1,2}:\d{1,2})|(20\d{2}年\d{1,2}月\d{1,2}日)", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE);

  //假如是僅僅抽取年月日,則依照上面的,假如是抽取年月日-時分秒,則依照下面的

  Pattern p = Pattern.compile("(20\d{2}[-/]\d{1,2}[-/]\d{1,2})|(20\d{2}年\d{1,2}月\d{1,2}日)", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE);

  //Matcher matcher = p.matcher(dateStr);

  Matcher matcher_detail = p_detail.matcher(dateStr);

  if(!(matcher_detail.find(0) && matcher_detail.groupCount() >= 1))

  {

  matcher_detail = p.matcher(dateStr);

  containsHMS = true;

  }else

  matcher_detail = p_detail.matcher(dateStr);

  if (matcher_detail.find() && matcher_detail.groupCount() >= 1) {

  matches = new ArrayList();

  for (int i = 1; i <= matcher_detail.groupCount(); i++) {

  String temp = matcher_detail.group(i);

  matches.add(temp);

  }

  } else {

  matches = Collections.EMPTY_LIST;

  }

  if (matches.size() > 0) {

  for(int i=0;i

  {

  String pubTime = matches.get(i).toString().trim();

  //取出第一個值

  pubTime = pubTime.replace("/", "-").replace("年", "-").replace("月", "-").replace("日", "-");

  if(current.compareTo(TimeUtil.strToCalendar(pubTime, "yyyy-MM-dd"))>=0)

  {

  if(containsHMS)

  pubTime+=" "+"00:00:00";

  if(pubTime.matches(rightTimeReg))

  {

  return pubTime;

  }

  }

  }

  } else {

  return null;

  }

  } catch (Exception e) {

  return null;

  }

  return null;

  }

  }

到此,关于“Spring Cloud微服务安全实例分析”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. Spring Cloud是什么
  2. 详解微服务:Spring Cloud原理及核心

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

spring cloud

上一篇:PHP-Casbin v3.20.0框架有什么变化

下一篇:Java的Future多线程模式怎么使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》