diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java index 77cc6c316d88aaad2a5900cdef4da33c06021312..059af2c588c0147d909db58db60796feb9f3bade 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java @@ -94,6 +94,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.CustomASServiceExecution import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.fetchoptions.CustomASServiceFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.id.ICustomASServiceId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.search.CustomASServiceSearchCriteria; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.session.SessionInformation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.Space; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create.SpaceCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.delete.SpaceDeletionOptions; @@ -142,6 +143,7 @@ import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.IGetExperimen import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.IGetMaterialMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.IGetProjectMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.IGetSampleMethodExecutor; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.IGetSessionInformationExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.IGetSpaceMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.IGetTagMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.IGetVocabularyTermMethodExecutor; @@ -358,6 +360,9 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> @Autowired private IUnarchiveDataSetMethodExecutor unarchiveDataSetExecutor; + @Autowired + private IGetSessionInformationExecutor getSessionInformationExecutor; + // Default constructor needed by Spring public ApplicationServerApi() { @@ -892,6 +897,14 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> unarchiveDataSetExecutor.unarchive(sessionToken, dataSetIds, options); } + @Override + @Transactional(readOnly = true) + @RolesAllowed({ RoleWithHierarchy.SPACE_OBSERVER, RoleWithHierarchy.SPACE_ETL_SERVER }) + public SessionInformation getSessionInformation(String sessionToken) + { + return getSessionInformationExecutor.getSessionInformation(sessionToken); + } + @Override public IApplicationServerApi createLogger(IInvocationLoggerContext context) { @@ -909,5 +922,4 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> { return 0; } - } diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApiLogger.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApiLogger.java index aba10d2a215ad26781ac49e3fbf18a8584fd2f2b..4ac39619bb5b0835305b25d551ff55521991c46b 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApiLogger.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApiLogger.java @@ -90,6 +90,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.CustomASServiceExecution import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.fetchoptions.CustomASServiceFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.id.ICustomASServiceId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.search.CustomASServiceSearchCriteria; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.session.SessionInformation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.Space; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create.SpaceCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.delete.SpaceDeletionOptions; @@ -527,4 +528,11 @@ public class ApplicationServerApiLogger extends AbstractServerLogger implements logAccess(sessionToken, "unarchive-data-sets", "DATA_SET_IDS(%s) UNARCHIVE_OPTIONS(%s)", abbreviate(dataSetIds), options); } + @Override + public SessionInformation getSessionInformation(String sessionToken) + { + logAccess(sessionToken, "session-info"); + return null; + } + } diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/GetSessionInformationExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/GetSessionInformationExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..50a4c0a427d44d5f85578d38f61ca079c393b136 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/GetSessionInformationExecutor.java @@ -0,0 +1,68 @@ +package ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method; + +import org.springframework.stereotype.Component; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.Person; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.session.SessionInformation; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.IOperationContext; +import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSession; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; + +@Component +public class GetSessionInformationExecutor extends AbstractMethodExecutor implements IGetSessionInformationExecutor +{ + + @Override + public SessionInformation getSessionInformation(final String sessionToken) + { + return executeInContext(sessionToken, new IMethodAction<SessionInformation>() + { + + @Override + public SessionInformation execute(IOperationContext context) + { + IAuthSession session = null; + + try + { + session = context.getSession(); + } catch (Exception ex) + { + // Ignore, if session is no longer available and error is thrown + } + + SessionInformation sessionInfo = null; + if (session != null) + { + sessionInfo = new SessionInformation(); + sessionInfo.setUserName(session.getUserName()); + sessionInfo.setHomeGroupCode(session.tryGetHomeGroupCode()); + + PersonPE personPE = session.tryGetPerson(); + Person person = new Person(); + person.setFirstName(personPE.getFirstName()); + person.setLastName(personPE.getLastName()); + person.setUserId(personPE.getUserId()); + person.setEmail(personPE.getEmail()); + person.setRegistrationDate(personPE.getRegistrationDate()); + person.setActive(personPE.isActive()); + sessionInfo.setPerson(person); + + PersonPE creatorPersonPE = session.tryGetCreatorPerson(); + Person creatorPerson = new Person(); + creatorPerson.setFirstName(creatorPersonPE.getFirstName()); + creatorPerson.setLastName(creatorPersonPE.getLastName()); + creatorPerson.setUserId(creatorPersonPE.getUserId()); + creatorPerson.setEmail(creatorPersonPE.getEmail()); + creatorPerson.setRegistrationDate(creatorPersonPE.getRegistrationDate()); + creatorPerson.setActive(creatorPersonPE.isActive()); + sessionInfo.setCreatorPerson(creatorPerson); + } + + return sessionInfo; + } + + }); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/IGetSessionInformationExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/IGetSessionInformationExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..41862b19c7a02682adbf88990ab75ea9bf3c0a56 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/IGetSessionInformationExecutor.java @@ -0,0 +1,8 @@ +package ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.session.SessionInformation; + +public interface IGetSessionInformationExecutor +{ + public SessionInformation getSessionInformation(final String sessionToken); +} diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java index 957ffd8d7ed0c8754340f1b4ebbe65e7b3307bf5..017b15474c9479b8a1b3fd4b71d83eb86bf6a275 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java @@ -89,6 +89,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.CustomASServiceExecution import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.fetchoptions.CustomASServiceFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.id.ICustomASServiceId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.service.search.CustomASServiceSearchCriteria; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.session.SessionInformation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.Space; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create.SpaceCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.delete.SpaceDeletionOptions; @@ -140,6 +141,8 @@ public interface IApplicationServerApi extends IRpcService public void logout(String sessionToken); + public SessionInformation getSessionInformation(String sessionToken); + public List<SpacePermId> createSpaces(String sessionToken, List<SpaceCreation> newSpaces); public List<ProjectPermId> createProjects(String sessionToken, List<ProjectCreation> newProjects); diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/session/SessionInformation.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/session/SessionInformation.java new file mode 100644 index 0000000000000000000000000000000000000000..0a1f1c7de8ff939ea14dea5d798f1eb4d782ea5b --- /dev/null +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/session/SessionInformation.java @@ -0,0 +1,67 @@ +package ch.ethz.sis.openbis.generic.asapi.v3.dto.session; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.Person; +import ch.systemsx.cisd.base.annotation.JsonObject; + +@JsonObject("as.dto.session.SessionInformation") +public class SessionInformation implements Serializable +{ + private static final long serialVersionUID = 1L; + + @JsonProperty + private String homeGroupCode; + + @JsonProperty + private String userName; + + @JsonProperty + private Person person; + + @JsonProperty + private Person creatorPerson; + + public String getHomeGroupCode() + { + return homeGroupCode; + } + + public void setHomeGroupCode(String homeGroupCode) + { + this.homeGroupCode = homeGroupCode; + } + + public String getUserName() + { + return userName; + } + + public void setUserName(String userName) + { + this.userName = userName; + } + + public Person getPerson() + { + return person; + } + + public void setPerson(Person person) + { + this.person = person; + } + + public Person getCreatorPerson() + { + return creatorPerson; + } + + public void setCreatorPerson(Person creatorPerson) + { + this.creatorPerson = creatorPerson; + } + +}