2021-05-24 16:31:46 +02:00
|
|
|
package org.gcube.smartgears.utils;
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.ArrayList;
|
2021-09-29 12:36:26 +02:00
|
|
|
import java.util.Arrays;
|
2021-05-24 16:31:46 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
|
|
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
|
|
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
|
|
public class GcubeJwt {
|
|
|
|
|
2021-09-29 12:36:26 +02:00
|
|
|
protected final static List<String> MINIMAL_ROLES = Arrays.asList("Member");
|
2021-07-02 17:26:59 +02:00
|
|
|
|
2021-05-24 16:31:46 +02:00
|
|
|
@JsonProperty("aud")
|
|
|
|
private String context;
|
|
|
|
|
|
|
|
@JsonProperty("resource_access")
|
|
|
|
private Map<String, Roles> contextAccess = new HashMap<>();
|
|
|
|
|
|
|
|
@JsonProperty("preferred_username")
|
|
|
|
private String username;
|
|
|
|
|
|
|
|
@JsonProperty("given_name")
|
|
|
|
private String firstName;
|
|
|
|
|
|
|
|
@JsonProperty("family_name")
|
|
|
|
private String lastName;
|
|
|
|
|
|
|
|
@JsonProperty("email")
|
|
|
|
private String email;
|
|
|
|
|
|
|
|
public List<String> getRoles(){
|
2021-07-02 17:26:59 +02:00
|
|
|
return contextAccess.get(this.context) == null ? MINIMAL_ROLES : contextAccess.get(this.context).roles;
|
2021-05-24 16:31:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getContext() {
|
|
|
|
try {
|
|
|
|
return URLDecoder.decode(context, StandardCharsets.UTF_8.toString());
|
|
|
|
}catch (UnsupportedEncodingException e) {
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUsername() {
|
|
|
|
return username;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getFirstName() {
|
|
|
|
return firstName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLastName() {
|
|
|
|
return lastName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getEmail() {
|
|
|
|
return email;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "GcubeJwt [context=" + getContext() + ", roles=" + getRoles() + ", username=" + username
|
|
|
|
+ ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Roles {
|
|
|
|
|
|
|
|
@JsonProperty("roles")
|
|
|
|
List<String> roles = new ArrayList<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|