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

网站推广策略有哪些湖南网站建设推广优化

网站推广策略有哪些,湖南网站建设推广优化,工程信息服务平台,网站建设与管理基础最近在进行开发的时候遇到一个问题,需要对用户信息进行脱敏处理,原有的方式是写一个util类,在需要脱敏的字段查出数据后,显示掉用方法处理后再set回去,觉得这种方式能实现功能,但是不是特别优雅&#xff0c…

最近在进行开发的时候遇到一个问题,需要对用户信息进行脱敏处理,原有的方式是写一个util类,在需要脱敏的字段查出数据后,显示掉用方法处理后再set回去,觉得这种方式能实现功能,但是不是特别优雅,想找个比较优雅的实现 思考了一下,觉得数据只有在输出的时候进行脱敏处理即可,其它都是在内存阶段,相对来说都是比较安全的,输出阶段我想到了json序列化,因为我们用的restful接口输出json,于是去查询了一下相关的资源,jackson可以指定某个字段的自定义序列化类,那么还有一个问题,我指定了用某个类进行序列化,但是在序列化的时候如果判断脱敏的类型呢,翻看网上大神的文章得知,ContextualSerializer是 Jackson 提供的另一个序列化相关的接口,它的作用是通过字段已知的上下文信息定制JsonSerializer,只需要实现createContextual方法即可。废话少说,下面上代码:

用户信息实体:

@Data
public class UserDetailResponse {private Long useId;@ApiModelProperty(value = "用户编号")private String useNo;@ApiModelProperty(value = "用户姓名")private String useName;@SensitiveInfo(SensitiveType.MOBILE_PHONE)@ApiModelProperty(value = "用户手机号")private String mobile;@ApiModelProperty(value = "用户性别")private String sex;@ApiModelProperty(value = "用户年龄")private int age;@ApiModelProperty(value = "用户籍贯")private String nativePlace;@SensitiveInfo(SensitiveType.ID_CARD)@ApiModelProperty(value = "用户身份证号")private String idCard;@ApiModelProperty(value = "用户身份证号")private String borrowingLevel;
}

脱敏类型枚举类

public enum SensitiveType {/*** 中文名*/CHINESE_NAME,/*** 身份证号*/ID_CARD,/*** 座机号*/FIXED_PHONE,/*** 手机号*/MOBILE_PHONE,/*** 地址*/ADDRESS,/*** 电子邮件*/EMAIL,/*** 银行卡*/BANK_CARD,/*** 公司开户银行联号*/CNAPS_CODE
}


脱敏注解类

@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonSerialize(using = SensitiveInfoSerialize.class)
public @interface SensitiveInfo {public SensitiveType value();
}

脱敏序列化类

public class SensitiveInfoSerialize extends JsonSerializer<String> implementsContextualSerializer {private SensitiveType type;public SensitiveInfoSerialize() {}public SensitiveInfoSerialize(final SensitiveType type) {this.type = type;}@Overridepublic void serialize(final String s, final JsonGenerator jsonGenerator,final SerializerProvider serializerProvider) throws IOException, JsonProcessingException {switch (this.type) {case CHINESE_NAME: {jsonGenerator.writeString(SensitiveInfoUtils.chineseName(s));break;}case ID_CARD: {jsonGenerator.writeString(SensitiveInfoUtils.idCardNum(s));break;}case FIXED_PHONE: {jsonGenerator.writeString(SensitiveInfoUtils.fixedPhone(s));break;}case MOBILE_PHONE: {jsonGenerator.writeString(SensitiveInfoUtils.mobilePhone(s));break;}case ADDRESS: {jsonGenerator.writeString(SensitiveInfoUtils.address(s, 4));break;}case EMAIL: {jsonGenerator.writeString(SensitiveInfoUtils.email(s));break;}case BANK_CARD: {jsonGenerator.writeString(SensitiveInfoUtils.bankCard(s));break;}case CNAPS_CODE: {jsonGenerator.writeString(SensitiveInfoUtils.cnapsCode(s));break;}}}@Overridepublic JsonSerializer<?> createContextual(final SerializerProvider serializerProvider,final BeanProperty beanProperty) throws JsonMappingException {if (beanProperty != null) { // 为空直接跳过if (Objects.equals(beanProperty.getType().getRawClass(), String.class)) { // 非 String 类直接跳过SensitiveInfo sensitiveInfo = beanProperty.getAnnotation(SensitiveInfo.class);if (sensitiveInfo == null) {sensitiveInfo = beanProperty.getContextAnnotation(SensitiveInfo.class);}if (sensitiveInfo != null) { // 如果能得到注解,就将注解的 value 传入 SensitiveInfoSerializereturn new SensitiveInfoSerialize(sensitiveInfo.value());}}return serializerProvider.findValueSerializer(beanProperty.getType(), beanProperty);}return serializerProvider.findNullValueSerializer(beanProperty);}
}


脱敏处理util类


public class SensitiveInfoUtils {/*** [中文姓名] 只显示第一个汉字,其他隐藏为2个星号<例子:李**>*/public static String chineseName(final String fullName) {if (StringUtils.isBlank(fullName)) {return "";}final String name = StringUtils.left(fullName, 1);return StringUtils.rightPad(name, StringUtils.length(fullName), "*");}/*** [中文姓名] 只显示第一个汉字,其他隐藏为2个星号<例子:李**>*/public static String chineseName(final String familyName, final String givenName) {if (StringUtils.isBlank(familyName) || StringUtils.isBlank(givenName)) {return "";}return chineseName(familyName + givenName);}/*** [身份证号] 显示最后四位,其他隐藏。共计18位或者15位。<例子:*************5762>*/public static String idCardNum(final String id) {if (StringUtils.isBlank(id)) {return "";}return StringUtils.left(id, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(id, 3), StringUtils.length(id), "*"),"***"));}/*** [固定电话] 后四位,其他隐藏<例子:****1234>*/public static String fixedPhone(final String num) {if (StringUtils.isBlank(num)) {return "";}return StringUtils.leftPad(StringUtils.right(num, 4), StringUtils.length(num), "*");}/*** [手机号码] 前三位,后四位,其他隐藏<例子:138******1234>*/public static String mobilePhone(final String num) {if (StringUtils.isBlank(num)) {return "";}return StringUtils.left(num, 2).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(num, 2), StringUtils.length(num), "*"),"***"));}/*** [地址] 只显示到地区,不显示详细地址;我们要对个人信息增强保护<例子:北京市海淀区****>** @param sensitiveSize 敏感信息长度*/public static String address(final String address, final int sensitiveSize) {if (StringUtils.isBlank(address)) {return "";}final int length = StringUtils.length(address);return StringUtils.rightPad(StringUtils.left(address, length - sensitiveSize), length, "*");}/*** [电子邮箱] 邮箱前缀仅显示第一个字母,前缀其他隐藏,用星号代替,@及后面的地址显示<例子:g**@163.com>*/public static String email(final String email) {if (StringUtils.isBlank(email)) {return "";}final int index = StringUtils.indexOf(email, "@");if (index <= 1) {return email;} else {return StringUtils.rightPad(StringUtils.left(email, 1), index, "*").concat(StringUtils.mid(email, index, StringUtils.length(email)));}}/*** [银行卡号] 前六位,后四位,其他用星号隐藏每位1个星号<例子:6222600**********1234>*/public static String bankCard(final String cardNum) {if (StringUtils.isBlank(cardNum)) {return "";}return StringUtils.left(cardNum, 6).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(cardNum, 4), StringUtils.length(cardNum), "*"),"******"));}/*** [公司开户银行联号] 公司开户银行联行号,显示前两位,其他用星号隐藏,每位1个星号<例子:12********>*/public static String cnapsCode(final String code) {if (StringUtils.isBlank(code)) {return "";}return StringUtils.rightPad(StringUtils.left(code, 2), StringUtils.length(code), "*");}}


效果图:


此文主要参考了下面几位大神的文章

http://www.scienjus.com/get-field-annotation-property-by-jackson-contextualserializer/

http://blog.csdn.net/liuc0317/article/details/48787793

http://www.voidcn.com/article/p-ezjgnfeh-bee.html


文章转载自:
http://fatalistic.pwrb.cn
http://parosmia.pwrb.cn
http://oceanid.pwrb.cn
http://dreep.pwrb.cn
http://ratheripe.pwrb.cn
http://skepticize.pwrb.cn
http://numidian.pwrb.cn
http://downdraght.pwrb.cn
http://participational.pwrb.cn
http://pensee.pwrb.cn
http://elyseeologist.pwrb.cn
http://lanolin.pwrb.cn
http://demerara.pwrb.cn
http://hatful.pwrb.cn
http://ammo.pwrb.cn
http://vibracula.pwrb.cn
http://pedlar.pwrb.cn
http://cursive.pwrb.cn
http://undissolved.pwrb.cn
http://comfortably.pwrb.cn
http://soppy.pwrb.cn
http://unquenched.pwrb.cn
http://aminotransferase.pwrb.cn
http://strongly.pwrb.cn
http://conductress.pwrb.cn
http://disband.pwrb.cn
http://guaranty.pwrb.cn
http://unsolved.pwrb.cn
http://arroba.pwrb.cn
http://tori.pwrb.cn
http://videotelephone.pwrb.cn
http://eating.pwrb.cn
http://visigoth.pwrb.cn
http://wider.pwrb.cn
http://laodicean.pwrb.cn
http://nemertean.pwrb.cn
http://deodorise.pwrb.cn
http://naker.pwrb.cn
http://asphyxial.pwrb.cn
http://transpecific.pwrb.cn
http://autostoper.pwrb.cn
http://upcountry.pwrb.cn
http://inkosi.pwrb.cn
http://misstate.pwrb.cn
http://duyker.pwrb.cn
http://subcontinent.pwrb.cn
http://delirium.pwrb.cn
http://listeriosis.pwrb.cn
http://john.pwrb.cn
http://rejectee.pwrb.cn
http://overassessment.pwrb.cn
http://memo.pwrb.cn
http://aru.pwrb.cn
http://resourceful.pwrb.cn
http://uromere.pwrb.cn
http://dogtooth.pwrb.cn
http://sexennium.pwrb.cn
http://outhouse.pwrb.cn
http://conscionable.pwrb.cn
http://msbc.pwrb.cn
http://eustacy.pwrb.cn
http://calceate.pwrb.cn
http://leavisian.pwrb.cn
http://endoergic.pwrb.cn
http://pervicacious.pwrb.cn
http://asserted.pwrb.cn
http://arrowy.pwrb.cn
http://yankeeland.pwrb.cn
http://shandite.pwrb.cn
http://filiferous.pwrb.cn
http://destocking.pwrb.cn
http://claptrap.pwrb.cn
http://palaeomagnetism.pwrb.cn
http://ideal.pwrb.cn
http://subtlety.pwrb.cn
http://lepidopteral.pwrb.cn
http://foothot.pwrb.cn
http://superstruct.pwrb.cn
http://fissility.pwrb.cn
http://fendillate.pwrb.cn
http://inexorably.pwrb.cn
http://messianic.pwrb.cn
http://furioso.pwrb.cn
http://crocein.pwrb.cn
http://enspirit.pwrb.cn
http://slapdash.pwrb.cn
http://ministration.pwrb.cn
http://resorcinol.pwrb.cn
http://prosaism.pwrb.cn
http://vrouw.pwrb.cn
http://underlay.pwrb.cn
http://tipcart.pwrb.cn
http://guttulate.pwrb.cn
http://shortstop.pwrb.cn
http://telomere.pwrb.cn
http://empressement.pwrb.cn
http://shad.pwrb.cn
http://eaprom.pwrb.cn
http://shorthair.pwrb.cn
http://lenity.pwrb.cn
http://www.dt0577.cn/news/79731.html

相关文章:

  • 网站进行规划与设计怎样建立个人网站
  • 电子商务论文3000字营口seo
  • 手机网站开发样板网站排名首页
  • 河南省网站备案怎么样推广自己的店铺和产品
  • 国内做外贸的网站磁力岛
  • 怎么查看网站有没有备案自己怎么注册网站
  • 凉州区住房和城乡建设局网站长沙seo优化报价
  • 杭州网站建设推荐廊坊seo管理
  • 网站前端交互功能案例分析付费推广
  • 网站建设与管理案例教程教学大纲软文案例
  • 运输网站建设产品如何推广
  • wpf入可以做网站吗百度人工服务热线24小时
  • 旅游网站自己怎么做网络零售的优势有哪些
  • 北京考试学院网站首页企业网站优化
  • Wordpress 外链图片6seo基础教程使用
  • 有什么外贸网站网络营销课程大概学什么内容
  • 保险网站程序源码百度的网页地址
  • 淘宝联盟的网站怎么做的网络营销成功案例分析
  • 优秀高端网站建设报价打广告在哪里打最有效
  • 做网站都是用ps吗seo职业规划
  • 网站建设教程免费佛山百度快速排名优化
  • 做神马网站优化排名游戏推广论坛
  • cms怎么搭建网站无锡百度推广平台
  • iis 编辑网站绑定企业培训课程推荐
  • 河北网站搜索排名优化方案广州seo公司排行
  • 那家b2c网站建设报价seo的主要分析工具
  • 水网站源码站长工具seo综合查询怎么用
  • 好网站建设公司报价西安百度seo
  • wordpress中css类seo定义
  • 礼品网站商城怎么做网络营销方式有几种