增加了登录权限的校验方法
This commit is contained in:
parent
c6e7657e62
commit
1c07580224
86
backend/src/main/java/com/stdproject/entity/LoginUser.java
Normal file
86
backend/src/main/java/com/stdproject/entity/LoginUser.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package com.stdproject.entity;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class LoginUser implements UserDetails {
|
||||||
|
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
private Collection<? extends GrantedAuthority> permissions;
|
||||||
|
|
||||||
|
public LoginUser(User user, Collection<? extends GrantedAuthority> permissions) {
|
||||||
|
this.user = user;
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JSONField(serialize = false)
|
||||||
|
private List<SimpleGrantedAuthority> authorities;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPassword() {
|
||||||
|
return user.getPassword();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsername() {
|
||||||
|
return user.getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取用户昵称
|
||||||
|
public String geNickname() {
|
||||||
|
return user.getNickname();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonExpired() {
|
||||||
|
// 检查密码是否过期
|
||||||
|
if (user.getPwdresettime() != null && user.getPwdvalidperiod() != null) {
|
||||||
|
java.time.LocalDateTime expireTime = user.getPwdresettime().plusDays(user.getPwdvalidperiod());
|
||||||
|
return expireTime.isAfter(java.time.LocalDateTime.now());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonLocked() {
|
||||||
|
// 检查登录失败锁定时间
|
||||||
|
if (user.getFailedlocktime() != null) {
|
||||||
|
// 如果锁定时间在当前时间之后,说明还在锁定期内,账户被锁定
|
||||||
|
return user.getFailedlocktime().isAfter(java.time.LocalDateTime.now());
|
||||||
|
}
|
||||||
|
// 没有锁定时间,账户未被锁定
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCredentialsNonExpired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
if(user.getStatus().equals("1")){ //用户有效
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
7105
frontend/yarn.lock
Normal file
7105
frontend/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user