public class TemporaryUser extends Object implements org.springframework.security.core.userdetails.UserDetails, org.springframework.security.core.CredentialsContainer
https://gitee.com/pcore/just-auth-spring-security-starter/issues/I22KP3| 限定符和类型 | 类和说明 |
|---|---|
static class |
TemporaryUser.UserBuilder
Builds the user to be added.
|
| 构造器和说明 |
|---|
TemporaryUser(String username,
String password,
boolean enabled,
boolean accountNonExpired,
boolean credentialsNonExpired,
boolean accountNonLocked,
Collection<? extends org.springframework.security.core.GrantedAuthority> authorities,
me.zhyd.oauth.model.AuthUser authUser,
String encodeState)
Construct the
User with the details required by
org.springframework.security.authentication.dao.DaoAuthenticationProvider. |
TemporaryUser(String username,
String password,
Collection<? extends org.springframework.security.core.GrantedAuthority> authorities,
me.zhyd.oauth.model.AuthUser authUser,
String encodeState)
Calls the more complex constructor with all boolean arguments set to
true. |
| 限定符和类型 | 方法和说明 |
|---|---|
static TemporaryUser.UserBuilder |
builder()
Creates a UserBuilder
|
boolean |
equals(Object rhs)
Returns
true if the supplied object is a User instance with the
same username value. |
void |
eraseCredentials() |
Collection<org.springframework.security.core.GrantedAuthority> |
getAuthorities() |
me.zhyd.oauth.model.AuthUser |
getAuthUser() |
String |
getEncodeState() |
String |
getPassword() |
String |
getUsername() |
int |
hashCode()
Returns the hashcode of the
username. |
boolean |
isAccountNonExpired() |
boolean |
isAccountNonLocked() |
boolean |
isCredentialsNonExpired() |
boolean |
isEnabled() |
String |
toString() |
static TemporaryUser.UserBuilder |
withDefaultPasswordEncoder()
已过时。
Using this method is not considered safe for production, but is
acceptable for demos and getting started. For production purposes, ensure the
password is encoded externally. See the method Javadoc for additional details.
There are no plans to remove this support. It is deprecated to indicate
that this is considered insecure for production purposes.
|
static TemporaryUser.UserBuilder |
withUsername(String username)
Creates a UserBuilder with a specified user name
|
public TemporaryUser(String username, String password, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities, me.zhyd.oauth.model.AuthUser authUser, String encodeState)
true.username - 用户名默认为: username + "_" + providerId + "_" + providerUserIdpassword - 密码authorities - 权限默认为 Auth2Properties.defaultAuthoritiesauthUser - 第三方授权登录的用户信息encodeState - 第三方授权登录的流程中加密后的 state 参数public TemporaryUser(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities, me.zhyd.oauth.model.AuthUser authUser, String encodeState)
User with the details required by
org.springframework.security.authentication.dao.DaoAuthenticationProvider.username - the username presented to the
DaoAuthenticationProviderpassword - the password that should be presented to the
DaoAuthenticationProviderenabled - set to true if the user is enabledaccountNonExpired - set to true if the account has not expiredcredentialsNonExpired - set to true if the credentials have not
expiredaccountNonLocked - set to true if the account is not lockedauthorities - the authorities that should be granted to the caller if they
presented the correct username and password and the user is enabled. Not null.authUser - 第三方授权登录的用户信息encodeState - 第三方授权登录的流程中加密后的 state 参数IllegalArgumentException - if a null value was passed either as
a parameter or as an element in the GrantedAuthority collectionpublic Collection<org.springframework.security.core.GrantedAuthority> getAuthorities()
getAuthorities 在接口中 org.springframework.security.core.userdetails.UserDetailspublic String getPassword()
getPassword 在接口中 org.springframework.security.core.userdetails.UserDetailspublic String getUsername()
getUsername 在接口中 org.springframework.security.core.userdetails.UserDetailspublic me.zhyd.oauth.model.AuthUser getAuthUser()
public String getEncodeState()
public boolean isEnabled()
isEnabled 在接口中 org.springframework.security.core.userdetails.UserDetailspublic boolean isAccountNonExpired()
isAccountNonExpired 在接口中 org.springframework.security.core.userdetails.UserDetailspublic boolean isAccountNonLocked()
isAccountNonLocked 在接口中 org.springframework.security.core.userdetails.UserDetailspublic boolean isCredentialsNonExpired()
isCredentialsNonExpired 在接口中 org.springframework.security.core.userdetails.UserDetailspublic void eraseCredentials()
eraseCredentials 在接口中 org.springframework.security.core.CredentialsContainerpublic boolean equals(Object rhs)
true if the supplied object is a User instance with the
same username value.
In other words, the objects are equal if they have the same username, representing the same principal.
public static TemporaryUser.UserBuilder withUsername(String username)
username - the username to usepublic static TemporaryUser.UserBuilder builder()
@Deprecated public static TemporaryUser.UserBuilder withDefaultPasswordEncoder()
WARNING: This method is considered unsafe for production and is only intended for sample applications.
Creates a user and automatically encodes the provided password using
PasswordEncoderFactories.createDelegatingPasswordEncoder(). For example:
UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
// outputs {bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
System.out.println(user.getPassword());
This is not safe for production (it is intended for getting started experience)
because the password "password" is compiled into the source code and then is
included in memory at the time of creation. This means there are still ways to
recover the plain text password making it unsafe. It does provide a slight
improvement to using plain text passwords since the UserDetails password is
securely hashed. This means if the UserDetails password is accidentally exposed,
the password is securely stored.
In a production setting, it is recommended to hash the password ahead of time.
For example:
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
// outputs {bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
// remember the password that is printed out and use in the next step
System.out.println(encoder.encode("password"));
UserDetails user = User.withUsername("user")
.password("{bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG")
.roles("USER")
.build();
Copyright © 2021. All rights reserved.