📄 user.java
字号:
/**
*
*/
package cn.edu.zust.gk.user.entity;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.GrantedAuthorityImpl;
import org.springframework.security.userdetails.UserDetails;
/**
*/
public class User implements UserDetails {
private static final long serialVersionUID = 8026813053768023527L;
private Integer id;
private String name;
private String password;
private boolean enabled;
private Set<Role> roles;
/**
* The default constructor
*/
public User() {
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.userdetails.UserDetails#getAuthorities()
*/
public GrantedAuthority[] getAuthorities() {
List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(this.getRoles().size());
for (Role role : this.getRoles()) {
grantedAuthorities.add(new GrantedAuthorityImpl(role.getName()));
}
return grantedAuthorities.toArray(new GrantedAuthority[roles.size()]);
}
/**
* Returns the authorites string
*
* eg. pa --- ROLE_ADMIN,ROLE_USER pb --- ROLE_ADMIN
*
* @return
*/
public String getAuthoritiesString() {
StringBuffer sb = new StringBuffer();
GrantedAuthority[] grantedAuthorities = this.getAuthorities();
if (grantedAuthorities.length == 0) {
return "";
}
sb.append(grantedAuthorities[0].getAuthority());
for (int i = 1; i < grantedAuthorities.length; i++) {
sb.append(",");
sb.append(grantedAuthorities[i].getAuthority());
}
return sb.toString();
}
/*
* (non-Javadoc)
*
* @see org.springframework.security.userdetails.UserDetails#getPassword()
*/
public String getPassword() {
return password;
}
/*
* (non-Javadoc)
*
* @see org.springframework.security.userdetails.UserDetails#getUsername()
*/
public String getUsername() {
return name;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.userdetails.UserDetails#isAccountNonExpired
* ()
*/
public boolean isAccountNonExpired() {
return true;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.userdetails.UserDetails#isAccountNonLocked()
*/
public boolean isAccountNonLocked() {
return true;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.security.userdetails.UserDetails#isCredentialsNonExpired
* ()
*/
public boolean isCredentialsNonExpired() {
return true;
}
/*
* (non-Javadoc)
*
* @see org.springframework.security.userdetails.UserDetails#isEnabled()
*/
public boolean isEnabled() {
return enabled;
}
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the disabled
*/
public boolean isDisabled() {
return !enabled;
}
/**
* @return the roles
*/
public Set<Role> getRoles() {
return roles;
}
/**
* @param id
* the id to set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @param password
* the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @param enable
* the enable to set
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* @param roles
* the roles to set
*/
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -