Switched code to use authorization-utils improvements
This commit is contained in:
parent
dd6bf694b4
commit
20ae014249
6
pom.xml
6
pom.xml
|
@ -148,12 +148,6 @@
|
|||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>keycloak-client</artifactId>
|
||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.taliox</groupId>
|
||||
<artifactId>zulip-java-rest</artifactId>
|
||||
|
|
|
@ -21,7 +21,7 @@ public class FakeModerationThread extends ModerationThread {
|
|||
@Override
|
||||
public void postUserMessage(CMItemStatus cmItemStatus, String userMessage) throws Exception {
|
||||
logger.info("{} is sending a message to the {} for item '{}' (id={}). ItemStatus={}, Message=\"{}\"",
|
||||
SecretManager.instance.get().getUsername(),
|
||||
SecretManager.instance.get().getUser().getUsername(),
|
||||
ModerationThread.class.getSimpleName(), itemName, itemID, cmItemStatus, userMessage);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ZulipStream extends ModerationThread {
|
|||
}
|
||||
|
||||
protected ZulipRestExecutor getZulipRestExecutor() {
|
||||
ZulipAuth zulipAuth = new ZulipAuth(SecretManager.instance.get().getUsername());
|
||||
ZulipAuth zulipAuth = new ZulipAuth(SecretManager.instance.get().getUser().getUsername());
|
||||
return new ZulipRestExecutor(zulipAuth.getEmail(), zulipAuth.getAPIKey(), zulipAuth.getSite());
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import javax.ws.rs.core.Response.Status;
|
|||
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||
import org.gcube.common.authorization.utils.user.User;
|
||||
import org.gcube.gcat.api.moderation.Moderated;
|
||||
import org.gcube.gcat.api.roles.Role;
|
||||
import org.gcube.gcat.utils.RandomString;
|
||||
|
@ -64,7 +65,7 @@ public class CKANUser extends CKAN {
|
|||
ObjectNode objectNode = mapper.createObjectNode();
|
||||
objectNode.put(NAME, name);
|
||||
objectNode.put(PASSWORD, randomString.nextString());
|
||||
checkAndSetEMail(objectNode);
|
||||
checkAndSetEmail(objectNode);
|
||||
checkAndSetFullName(objectNode);
|
||||
checkAndSetJobTitle(objectNode);
|
||||
return create(getAsString(objectNode));
|
||||
|
@ -81,7 +82,7 @@ public class CKANUser extends CKAN {
|
|||
* @return true if the display name and the full name has been updated in objectNode
|
||||
*/
|
||||
private boolean checkAndSetJobTitle(ObjectNode objectNode) {
|
||||
String jobTitle = SecretManager.instance.get().getTitle();
|
||||
String jobTitle = SecretManager.instance.get().getUser().getAbout();
|
||||
|
||||
String ckanJobTitle = "";
|
||||
if(objectNode.has(ABOUT)) {
|
||||
|
@ -119,8 +120,8 @@ public class CKANUser extends CKAN {
|
|||
* @param objectNode
|
||||
* @return true if the display name and the full name has been updated
|
||||
*/
|
||||
private boolean checkAndSetEMail(ObjectNode objectNode) {
|
||||
String portalEmail = SecretManager.instance.get().getEMail();
|
||||
private boolean checkAndSetEmail(ObjectNode objectNode) {
|
||||
String portalEmail = SecretManager.instance.get().getUser().getEmail();
|
||||
|
||||
String ckanEmail = "";
|
||||
if(objectNode.has(EMAIL)) {
|
||||
|
@ -141,7 +142,7 @@ public class CKANUser extends CKAN {
|
|||
ObjectNode objectNode = (ObjectNode) result;
|
||||
boolean toBeUpdated = false;
|
||||
|
||||
toBeUpdated = checkAndSetEMail(objectNode) || toBeUpdated;
|
||||
toBeUpdated = checkAndSetEmail(objectNode) || toBeUpdated;
|
||||
toBeUpdated = checkAndSetFullName(objectNode) || toBeUpdated;
|
||||
toBeUpdated = checkAndSetJobTitle(objectNode) || toBeUpdated;
|
||||
|
||||
|
@ -193,7 +194,7 @@ public class CKANUser extends CKAN {
|
|||
}
|
||||
|
||||
public static String getCKANUsername() {
|
||||
String username = SecretManager.instance.get().getUsername();
|
||||
String username = SecretManager.instance.get().getUser().getUsername();
|
||||
return getCKANUsername(username);
|
||||
}
|
||||
|
||||
|
@ -214,7 +215,7 @@ public class CKANUser extends CKAN {
|
|||
public Role getRole() {
|
||||
if(role == null) {
|
||||
role = Role.MEMBER;
|
||||
Collection<String> roles = SecretManager.instance.get().getRoles();
|
||||
Collection<String> roles = SecretManager.instance.get().getUser().getRoles();
|
||||
for(String portalRole : roles) {
|
||||
Role gotRole = Role.getRoleFromPortalRole(portalRole);
|
||||
if(gotRole != null && gotRole.ordinal() > role.ordinal()) {
|
||||
|
@ -251,23 +252,23 @@ public class CKANUser extends CKAN {
|
|||
|
||||
public boolean isCatalogueModerator() {
|
||||
if(catalogueModerator == null) {
|
||||
catalogueModerator = SecretManager.instance.get().getRoles().contains(Moderated.CATALOGUE_MODERATOR);
|
||||
catalogueModerator = SecretManager.instance.get().getUser().getRoles().contains(Moderated.CATALOGUE_MODERATOR);
|
||||
}
|
||||
return catalogueModerator;
|
||||
}
|
||||
|
||||
public String getSurnameName(){
|
||||
SecretManager sm = SecretManager.instance.get();
|
||||
return String.format("%s %s", sm.getSurname(), sm.getName()).trim();
|
||||
User user = SecretManager.instance.get().getUser();
|
||||
return String.format("%s %s", user.getFamilyName(), user.getGivenName()).trim();
|
||||
}
|
||||
|
||||
public String getNameSurname() {
|
||||
SecretManager sm = SecretManager.instance.get();
|
||||
return String.format("%s %s", sm.getName(), sm.getSurname()).trim();
|
||||
User user = SecretManager.instance.get().getUser();
|
||||
return String.format("%s %s", user.getGivenName(), user.getFamilyName()).trim();
|
||||
}
|
||||
|
||||
public String getEMail() {
|
||||
return SecretManager.instance.get().getEMail();
|
||||
return SecretManager.instance.get().getUser().getEmail();
|
||||
}
|
||||
|
||||
}
|
|
@ -44,7 +44,7 @@ public abstract class CKANUserCache {
|
|||
userCachePerContext.put(context, userCache);
|
||||
}
|
||||
|
||||
String gcubeUsername = SecretManager.instance.get().getUsername();
|
||||
String gcubeUsername = SecretManager.instance.get().getUser().getUsername();
|
||||
CKANUser ckanUser = userCache.get(gcubeUsername);
|
||||
if(ckanUser == null) {
|
||||
ckanUser = new CKANUser();
|
||||
|
|
|
@ -640,7 +640,7 @@ public class CKANPackageTest extends ContextTest {
|
|||
// logger.debug("{}", res);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// @Ignore
|
||||
@Test
|
||||
public void deleteAllItemsInAllOrganizations() {
|
||||
CKANPackage ckanPackage = new CKANPackage();
|
||||
|
@ -648,8 +648,8 @@ public class CKANPackageTest extends ContextTest {
|
|||
mvm.add(GCatConstants.OWN_ONLY_QUERY_PARAMETER, "false");
|
||||
UriInfo uriInfo = getUriInfo(mvm);
|
||||
ckanPackage.setUriInfo(uriInfo);
|
||||
// String res = ckanPackage.deleteAll(true);
|
||||
// logger.debug("{}", res);
|
||||
String res = ckanPackage.deleteAll(true);
|
||||
logger.debug("{}", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue