|
|
|
@ -6,6 +6,7 @@ import javax.ws.rs.InternalServerErrorException;
|
|
|
|
|
import javax.ws.rs.WebApplicationException;
|
|
|
|
|
import javax.ws.rs.core.Response.Status;
|
|
|
|
|
|
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
|
|
|
|
import org.gcube.common.authorization.utils.user.User;
|
|
|
|
@ -47,6 +48,8 @@ public class CKANUser extends CKAN {
|
|
|
|
|
|
|
|
|
|
private static final String API_KEY = "apikey";
|
|
|
|
|
|
|
|
|
|
public static final String PORTAL_ROLES = "portal_roles";
|
|
|
|
|
|
|
|
|
|
protected Role role;
|
|
|
|
|
protected Boolean catalogueModerator;
|
|
|
|
|
|
|
|
|
@ -187,15 +190,32 @@ public class CKANUser extends CKAN {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void parseResult() {
|
|
|
|
|
protected String parseResult() {
|
|
|
|
|
name = result.get(NAME).asText();
|
|
|
|
|
try {
|
|
|
|
|
apiKey = result.get(API_KEY).asText();
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
if(name.compareTo(getCKANUsername())==0) {
|
|
|
|
|
throw e;
|
|
|
|
|
|
|
|
|
|
// Only managers can read Ckan API key
|
|
|
|
|
if(getRole().ordinal()<Role.MANAGER.ordinal()) {
|
|
|
|
|
try {
|
|
|
|
|
apiKey = result.get(API_KEY).asText();
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
// The user reading its own Ckan profile must be able to read its API key
|
|
|
|
|
if(name.compareTo(getCKANUsername())==0) {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
((ObjectNode) result).remove(API_KEY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(name.compareTo(getCKANUsername())==0) {
|
|
|
|
|
ArrayNode roles = ((ObjectNode) result).putArray(PORTAL_ROLES);
|
|
|
|
|
roles.add(getRole().getPortalRole());
|
|
|
|
|
if(isCatalogueModerator()) {
|
|
|
|
|
roles.add(Moderated.CATALOGUE_MODERATOR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getAsString(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static String getCKANUsername(String username) {
|
|
|
|
@ -218,9 +238,21 @@ public class CKANUser extends CKAN {
|
|
|
|
|
return getCKANUsername(username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String create(String json) {
|
|
|
|
|
super.create(json);
|
|
|
|
|
String ret = parseResult();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String read() {
|
|
|
|
|
String ret = super.read();
|
|
|
|
|
parseResult();
|
|
|
|
|
super.read();
|
|
|
|
|
String ret = parseResult();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String update(String json) {
|
|
|
|
|
super.update(json);
|
|
|
|
|
String ret = parseResult();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|