V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  siweipancc  ›  全部回复第 26 页 / 共 27 页
回复总数  526
1 ... 18  19  20  21  22  23  24  25  26  27  
// ---------model
@Entity
@Data
@Accessors(chain = true)
public class AuthUrl implements Serializable {
@Id
@GeneratedValue
private Long id;

private String url;

@ElementCollection
private List<Long> uIds;
}

// ----- 控制层 @PreAuthorize("@userProfileManager.currentUserAuthForUlr(authentication,httpServletRequest.requestURL.toString())")
@PutMapping("password")
public ResponseEntity<String> changePassword(@RequestParam String newPassword, Authentication authentication) {
profileManager.changePassword(newPassword, authentication);
return ResponseEntity.ok("success");
}

// -------- service
public class UserProfileManager {
// 各种注入
public boolean currentUserAuthForUlr(Authentication authentication, String url) {
Optional<UserProfile> optional = userProfileMapper.findOne(Example.of(new UserProfile().setEmail(authentication.getPrincipal().toString())));
UserProfile profile = optional.orElseThrow(() -> new BadCredentialsException("请重新登录"));
AuthUrl authUrl = authUrlMapper.findOne(Example.of(new AuthUrl().setUrl(url))).orElse(null);
if (authUrl == null) {
return true;
}
List<Long> uIds = authUrl.getUIds();
return uIds == null || uIds.isEmpty() || uIds.contains(profile.getId());
}


public void changePassword(String newPassword, Authentication authentication) {
Optional<UserProfile> optional = userProfileMapper.findOne(Example.of(new UserProfile().setEmail(authentication.getPrincipal().toString())));
UserProfile profile = optional.orElseThrow(() -> new BadCredentialsException("请重新登录"));
String encode = passwordEncoder.encode(newPassword);
profile.setPassword(encode);
userProfileMapper.saveAndFlush(profile);
}
// **
}
你这个,可以用 PreAuth 注解,在 el 引用一个 验证 bean 对现有凭据进行拦截。我待会写一个 demo 看看。
最近全是唱见翻唱,黑名单暴增,恶心的要死
2020-06-14 21:14:06 +08:00
回复了 AmrtaShiva 创建的主题 iOS 13.5.1 都更新了吗?
kitsunebi 插件终于能用了:D
2020-06-09 19:29:48 +08:00
回复了 likefly 创建的主题 程序员 表设计遇到一个问题,感觉没有很好的方法
:D json 后期全是慢查询
2020-06-09 13:00:52 +08:00
回复了 RainyH2O 创建的主题 问与答 为什么有些网站很喜欢在 URL 塞一大堆参数?
@RainyH2O 嗯,好的,不送
2020-06-08 00:27:19 +08:00
回复了 SONIC1987 创建的主题 程序员 关于 996 和人生的思考
@cassyfar 我在做对接 zoom 这块的,大部分是 965,可能跟员工大部分是青年的有关系,老板也不敢随便喊人加班
2020-06-07 21:33:34 +08:00
回复了 RainyH2O 创建的主题 问与答 为什么有些网站很喜欢在 URL 塞一大堆参数?
我觉得你的问题在于 HTTP 基础不扎实……不然一个人思考就算是一天也足够了
2020-06-07 20:23:18 +08:00
回复了 ltoddy 创建的主题 JetBrains 大家最近有更新 Jetbrains 家的 IDE 吗
版本问题,所以我自己用的还停在 2019:D 公司的卡顿时间就当摸鱼了
在荔枝买过永久 86 的……你这也太坑了
@JsonField,我胡说的
2020-05-04 13:15:05 +08:00
回复了 lg106 创建的主题 Java Spring boot 里做表单验证,返回的错误是随机的,我想按顺序来
来个代码,看不懂是什么随机
2020-04-28 12:17:02 +08:00
回复了 RRRoger 创建的主题 程序员 有没有解析集合表达式的轮子 例如:`(-∞, -600]∪[600, +∞)`
参考一下 guava?
angular 一把梭,就像 springboot 一样畅快,开箱即用
2020-04-26 19:08:27 +08:00
回复了 z742364692 创建的主题 Java 咨询一下 maven 配置
私服不都丢内网吗,上云是什么操作……
2020-04-11 22:17:38 +08:00
回复了 congjf 创建的主题 职场话题 招人招到心态爆炸…………
初面不是技术的我直接闪。hr ?我谈不下去,说了也白搭,你往专业说了,他听不懂可能就把你 pass 了:)
text,有几个子集
2020-04-01 22:57:37 +08:00
回复了 findmyself 创建的主题 问与答 你会在新人入职的第一天给他安排开发需求吗
一个星期看项目代码,第二周开始让独立开发模块,很过分,不过谁让我在简历上吹呢 :)
2020-03-31 08:47:39 +08:00
回复了 xyp0302 创建的主题 问与答 入职 Java 开发,公司给配机械革命,可以接受吗?
不辞职等着电脑生小电脑?.jpg
1 ... 18  19  20  21  22  23  24  25  26  27  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1025 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 36ms · UTC 18:52 · PVG 02:52 · LAX 11:52 · JFK 14:52
Developed with CodeLauncher
♥ Do have faith in what you're doing.