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