parent
4c72bc4ea2
commit
c2051b9595
@ -0,0 +1,20 @@
|
|||||||
|
//实现用户密码的加密存储。==>加上此文件,必须是密文存储
|
||||||
|
|
||||||
|
package com.kob.backend.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSecurity
|
||||||
|
|
||||||
|
public class SecurityConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();//返回加密方法
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.kob.backend.service.impl.utils;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import com.kob.backend.pojo.User;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class UserDetailsImpl implements UserDetails
|
||||||
|
{
|
||||||
|
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPassword() {
|
||||||
|
return user.getPassword();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsername() { return user.getUsername();}
|
||||||
|
//isAccountNonExpired 账户没有过期
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonExpired() {//账号没过期
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//isAccountNonLocked 账户没有被锁定
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonLocked() {//账号没被锁定
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//isCredentialsNonExpired 身份认证没过期
|
||||||
|
@Override
|
||||||
|
public boolean isCredentialsNonExpired() {//凭证没过期
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//isEnabled 账户启用
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {//用户已被禁用
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue