User management

This commit is contained in:
Fabio Sinibaldi 2022-10-18 15:09:49 +02:00
parent 4c9455fd76
commit 3a2a42f3b8
3 changed files with 22 additions and 22 deletions

View File

@ -64,6 +64,12 @@
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId>
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
</dependency>
<!-- MONGO -->
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
<dependency>

View File

@ -7,10 +7,9 @@ import org.gcube.application.geoportal.common.model.document.accounting.Accounti
import org.gcube.application.geoportal.common.model.document.accounting.Context;
import org.gcube.application.geoportal.common.model.document.accounting.User;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import java.time.LocalDateTime;
import java.util.ArrayList;
@ -24,25 +23,19 @@ public class UserUtils {
public static List<String> DEFAULT_ROLES=new ArrayList<>();
public static AuthenticatedUser getCurrent() throws SecurityException {
String context=ScopeProvider.instance.get();
log.debug("Loading caller info..");
SecretManager cm = SecretManagerProvider.instance.get();
String context = cm.getContext();
if(context==null) throw new SecurityException("Cannot determine context");
org.gcube.common.authorization.utils.user.User user = cm.getUser();
log.info("Identified caller {} in context {}",user.getUsername(),context);
log.debug("Context is {}, checking tokens..",context);
ClientInfo client = null;
Set<String> roles=new HashSet<>();
try{
client = AuthorizationProvider.instance.get().getClient();
roles= new HashSet<>(client.getRoles());
}catch(Throwable e) {
log.warn("Unable to get client info ",e);
roles = new HashSet<>();
}
roles.addAll(user.getRoles());
AuthenticatedUser toReturn =
new AuthenticatedUser(client,roles, AccessTokenProvider.instance.get(),SecurityTokenProvider.instance.get(),context);
new AuthenticatedUser(user,roles, AccessTokenProvider.instance.get(),SecurityTokenProvider.instance.get(),context);
log.info("Current User is {} ",toReturn);
return toReturn;
@ -52,7 +45,8 @@ public class UserUtils {
@AllArgsConstructor
@Getter
public static class AuthenticatedUser {
private ClientInfo user;
private org.gcube.common.authorization.utils.user.User user;
private Set<String> roles;
@ -86,11 +80,11 @@ public class UserUtils {
AccountingInfo info=new AccountingInfo();
User user = new User();
try{
user.setUsername(this.getUser().getId());
user.setUsername(this.getUser().getUsername());
user.setRoles(roles);
}catch(Exception e){
log.warn("Unable to determine user id, using FAKE",e);
user.setUsername("fabio.sinibaldi");
user.setUsername("FAKE");
user.setRoles(new HashSet<>());
user.getRoles().addAll(DEFAULT_ROLES);
}

View File

@ -58,7 +58,7 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
"$.posizionamentoScavo."+ Field.CHILDREN+"[?(@.fileset)]",
null,
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,
"pos.shp");
"concessioni/pos.shp");
System.out.println("Registered posizionamento, result is "+ Serialization.write(doc));
@ -66,7 +66,7 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
StepExecutionRequest submitReq=new StepExecutionRequest();
submitReq.setStepID("SUBMIT-FOR-REVIEW");
// doc=step(doc.getId(),submitReq);
doc=step("630f912755e2947b0278c1be",submitReq);
doc=step(doc.getId(),submitReq);
System.out.println(doc);
assertTrue(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK));