improving code
This commit is contained in:
parent
5dc635d134
commit
8a023759a8
|
@ -1,53 +1,32 @@
|
|||
package org.gcube.common.authorization.utils.user;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class GCubeUser implements User {
|
||||
|
||||
// This key contains the fullname
|
||||
// protected static final String OAUTH_USER_PROFILE_FULLNAME_KEY = "name";
|
||||
|
||||
protected static final String USERNAME_KEY = "id";
|
||||
|
||||
protected static final String ROLES_KEY = "roles";
|
||||
|
||||
protected static final String NAME_KEY = "given_name";
|
||||
protected static final String MIDDLE_NAME_KEY = "middle_name";
|
||||
protected static final String SURNAME_KEY = "family_name";
|
||||
protected static final String EMAIL_KEY = "email";
|
||||
|
||||
|
||||
@JsonProperty(USERNAME_KEY)
|
||||
@JsonProperty("id")
|
||||
protected String username;
|
||||
|
||||
@JsonProperty(ROLES_KEY)
|
||||
@JsonProperty("roles")
|
||||
protected Set<String> roles;
|
||||
|
||||
@JsonProperty(NAME_KEY)
|
||||
protected String name;
|
||||
@JsonProperty(SURNAME_KEY)
|
||||
protected String surname;
|
||||
@JsonProperty(EMAIL_KEY)
|
||||
@JsonProperty("given_name")
|
||||
protected String givenName;
|
||||
@JsonProperty("family_name")
|
||||
protected String familyName;
|
||||
@JsonProperty("email")
|
||||
protected String eMail;
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
protected Map<String, Object> additionalProperties;
|
||||
|
||||
public GCubeUser() {
|
||||
this.additionalProperties = new HashMap<>();
|
||||
}
|
||||
@JsonProperty("picture")
|
||||
protected String picture;
|
||||
@JsonProperty("middle_name")
|
||||
protected String middleName;
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
|
@ -60,36 +39,26 @@ public class GCubeUser implements User {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getGivenName() {
|
||||
return givenName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
public String getFamilyName() {
|
||||
return familyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEmail() {
|
||||
return eMail;
|
||||
}
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String,Object> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
public void setAdditionalProperties(Map<String,Object> additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
|
||||
public Object getAdditionalProperty(String key) {
|
||||
return this.additionalProperties.get(key);
|
||||
}
|
||||
|
||||
@JsonAnySetter
|
||||
public void setAdditionalProperty(String key, Object value) {
|
||||
this.additionalProperties.put(key, value);
|
||||
|
||||
public String getPicture() {
|
||||
return picture;
|
||||
}
|
||||
|
||||
public String getMiddleName() {
|
||||
return middleName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,10 +27,4 @@ public class KeycloakUser extends AccessToken implements User {
|
|||
return getRealmAccess().getRoles();
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String getSurname() {
|
||||
return getFamilyName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,18 +11,18 @@ public interface User {
|
|||
|
||||
public Collection<String> getRoles();
|
||||
|
||||
public String getName();
|
||||
public String getGivenName();
|
||||
|
||||
public String getSurname();
|
||||
public String getFamilyName();
|
||||
|
||||
public String getEmail();
|
||||
|
||||
public default String getSurnameName() {
|
||||
return String.format("%s %s", getSurname(), getName());
|
||||
return String.format("%s %s", getFamilyName(), getGivenName());
|
||||
}
|
||||
|
||||
public default String getNameSurname() {
|
||||
return String.format("%s %s", getName(), getSurname());
|
||||
return String.format("%s %s", getGivenName(), getFamilyName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue