Skip to content
Snippets Groups Projects
Commit b28db2a8 authored by uhensler's avatar uhensler
Browse files

OO-3932: Send a globally unique user id to external editors

parent e07b6823
No related branches found
No related tags found
No related merge requests found
Showing with 201 additions and 29 deletions
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.commons.services.doceditor;
import org.olat.core.id.Identity;
/**
*
* Initial date: 17 May 2019<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public interface DocEditorIdentityService {
/**
* Get globally unique identity id.
*
* @param identity
* @return
*/
public String getGlobalIdentityId(Identity identity);
/**
* Get identity by globally unique userId.
*
*
* @param globalIdentityId
* @return
*/
public Identity getIdentity(String globalIdentityId);
public String getUserDisplayName(Identity identity);
}
...@@ -42,13 +42,13 @@ import javax.ws.rs.core.Response; ...@@ -42,13 +42,13 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.olat.core.commons.services.doceditor.DocEditorIdentityService;
import org.olat.core.commons.services.doceditor.collabora.CollaboraModule; import org.olat.core.commons.services.doceditor.collabora.CollaboraModule;
import org.olat.core.commons.services.doceditor.collabora.CollaboraService; import org.olat.core.commons.services.doceditor.collabora.CollaboraService;
import org.olat.core.commons.services.doceditor.wopi.Access; import org.olat.core.commons.services.doceditor.wopi.Access;
import org.olat.core.commons.services.vfs.VFSMetadata; import org.olat.core.commons.services.vfs.VFSMetadata;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.VFSLeaf;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -72,7 +72,7 @@ public class CollaboraWebService { ...@@ -72,7 +72,7 @@ public class CollaboraWebService {
@Autowired @Autowired
private CollaboraService collaboraService; private CollaboraService collaboraService;
@Autowired @Autowired
private UserManager userManager; private DocEditorIdentityService identityService;
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
...@@ -100,13 +100,13 @@ public class CollaboraWebService { ...@@ -100,13 +100,13 @@ public class CollaboraWebService {
} }
VFSMetadata metadata = access.getMetadata(); VFSMetadata metadata = access.getMetadata();
String ownerId = metadata.getAuthor() != null? metadata.getAuthor().getKey().toString(): null; String ownerId = metadata.getAuthor() != null? identityService.getGlobalIdentityId(metadata.getAuthor()): null;
CheckFileInfoVO checkFileInfoVO = CheckFileInfoVO.builder() CheckFileInfoVO checkFileInfoVO = CheckFileInfoVO.builder()
.withBaseFileName(metadata.getFilename()) // suffix is mandatory .withBaseFileName(metadata.getFilename()) // suffix is mandatory
.withOwnerId(ownerId) .withOwnerId(ownerId)
.withSize(metadata.getFileSize()) .withSize(metadata.getFileSize())
.withUserId(access.getIdentity().getKey().toString()) .withUserId(identityService.getGlobalIdentityId(access.getIdentity()))
.withUserFriendlyName(userManager.getUserDisplayName(access.getIdentity())) .withUserFriendlyName(identityService.getUserDisplayName(access.getIdentity()))
.withVersion(String.valueOf(metadata.getRevisionNr())) .withVersion(String.valueOf(metadata.getRevisionNr()))
.withLastModifiedTime(getAsIso8601(metadata.getLastModified())) .withLastModifiedTime(getAsIso8601(metadata.getLastModified()))
.withUserCanWrite(access.isCanEdit()) .withUserCanWrite(access.isCanEdit())
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.commons.services.doceditor.manager;
import org.apache.logging.log4j.Logger;
import org.olat.basesecurity.BaseSecurityManager;
import org.olat.core.commons.services.doceditor.DocEditorIdentityService;
import org.olat.core.id.Identity;
import org.olat.core.logging.Tracing;
import org.olat.core.util.WebappHelper;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
* Initial date: 17 May 2019<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
@Service
public class DocEditorIdentityServiceImpl implements DocEditorIdentityService {
private static final Logger log = Tracing.createLoggerFor(DocEditorIdentityServiceImpl.class);
@Autowired
private BaseSecurityManager securityManager;
@Autowired
private UserManager userManager;
@Override
public String getGlobalIdentityId(Identity identity) {
return getGlobalUserIdPrefix() + identity.getName();
}
@Override
public Identity getIdentity(String globalIdenityId) {
try {
String username = globalIdenityId.substring(getGlobalUserIdPrefix().length());
return securityManager.findIdentityByNameCaseInsensitive(username);
} catch (NumberFormatException e) {
log.warn("Try to load identity with global unique id " + globalIdenityId, e);
}
return null;
}
private String getGlobalUserIdPrefix() {
return "openolat." + WebappHelper.getInstanceId() + ".";
}
@Override
public String getUserDisplayName(Identity identity) {
return userManager.getUserDisplayName(identity);
}
}
...@@ -31,6 +31,7 @@ import java.util.Set; ...@@ -31,6 +31,7 @@ import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.apache.logging.log4j.Logger;
import org.olat.core.commons.services.doceditor.DocEditor.Mode; import org.olat.core.commons.services.doceditor.DocEditor.Mode;
import org.olat.core.commons.services.doceditor.DocEditorSecurityCallback; import org.olat.core.commons.services.doceditor.DocEditorSecurityCallback;
import org.olat.core.commons.services.doceditor.office365.Office365Module; import org.olat.core.commons.services.doceditor.office365.Office365Module;
...@@ -45,7 +46,6 @@ import org.olat.core.commons.services.vfs.VFSRepositoryService; ...@@ -45,7 +46,6 @@ import org.olat.core.commons.services.vfs.VFSRepositoryService;
import org.olat.core.gui.control.Event; import org.olat.core.gui.control.Event;
import org.olat.core.helpers.Settings; import org.olat.core.helpers.Settings;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.apache.logging.log4j.Logger;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils; import org.olat.core.util.FileUtils;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
......
...@@ -40,15 +40,15 @@ import javax.ws.rs.core.Response; ...@@ -40,15 +40,15 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.apache.logging.log4j.Logger;
import org.olat.core.commons.services.doceditor.DocEditorIdentityService;
import org.olat.core.commons.services.doceditor.office365.Office365Module; import org.olat.core.commons.services.doceditor.office365.Office365Module;
import org.olat.core.commons.services.doceditor.office365.Office365Service; import org.olat.core.commons.services.doceditor.office365.Office365Service;
import org.olat.core.commons.services.doceditor.wopi.Access; import org.olat.core.commons.services.doceditor.wopi.Access;
import org.olat.core.commons.services.vfs.VFSMetadata; import org.olat.core.commons.services.vfs.VFSMetadata;
import org.apache.logging.log4j.Logger;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.VFSLeaf;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -74,7 +74,7 @@ public class Office365WebService { ...@@ -74,7 +74,7 @@ public class Office365WebService {
@Autowired @Autowired
private Office365Service office365Service; private Office365Service office365Service;
@Autowired @Autowired
private UserManager userManager; private DocEditorIdentityService identityService;
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
...@@ -112,14 +112,18 @@ public class Office365WebService { ...@@ -112,14 +112,18 @@ public class Office365WebService {
return Response.serverError().status(Status.NOT_FOUND).build(); return Response.serverError().status(Status.NOT_FOUND).build();
} }
String userId = identityService.getGlobalIdentityId(access.getIdentity());
VFSMetadata metadata = access.getMetadata(); VFSMetadata metadata = access.getMetadata();
String ownerId = metadata.getAuthor() != null? metadata.getAuthor().getKey().toString(): null; // ownerId is mandatory (this hack seens to work)
String ownerId = metadata.getAuthor() != null
? identityService.getGlobalIdentityId(metadata.getAuthor())
: userId;
CheckFileInfoVO checkFileInfoVO = CheckFileInfoVO.builder() CheckFileInfoVO checkFileInfoVO = CheckFileInfoVO.builder()
.withBaseFileName(metadata.getFilename()) // suffix is mandatory .withBaseFileName(metadata.getFilename()) // suffix is mandatory
.withOwnerId(ownerId) .withOwnerId(ownerId)
.withSize(metadata.getFileSize()) .withSize(metadata.getFileSize())
.withUserId(access.getIdentity().getKey().toString()) .withUserId(userId)
.withUserFriendlyName(userManager.getUserDisplayName(access.getIdentity())) .withUserFriendlyName(identityService.getUserDisplayName(access.getIdentity()))
.withVersion(String.valueOf(metadata.getRevisionNr())) .withVersion(String.valueOf(metadata.getRevisionNr()))
.withLastModifiedTime(getAsIso8601(metadata.getLastModified())) .withLastModifiedTime(getAsIso8601(metadata.getLastModified()))
.withSupportsGetLock(true) .withSupportsGetLock(true)
......
...@@ -30,8 +30,9 @@ import org.apache.http.client.methods.CloseableHttpResponse; ...@@ -30,8 +30,9 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.olat.basesecurity.BaseSecurityManager; import org.apache.logging.log4j.Logger;
import org.olat.core.commons.services.doceditor.DocEditor.Mode; import org.olat.core.commons.services.doceditor.DocEditor.Mode;
import org.olat.core.commons.services.doceditor.DocEditorIdentityService;
import org.olat.core.commons.services.doceditor.DocEditorSecurityCallback; import org.olat.core.commons.services.doceditor.DocEditorSecurityCallback;
import org.olat.core.commons.services.doceditor.onlyoffice.ApiConfig; import org.olat.core.commons.services.doceditor.onlyoffice.ApiConfig;
import org.olat.core.commons.services.doceditor.onlyoffice.OnlyOfficeSecurityService; import org.olat.core.commons.services.doceditor.onlyoffice.OnlyOfficeSecurityService;
...@@ -46,7 +47,6 @@ import org.olat.core.commons.services.vfs.VFSMetadata; ...@@ -46,7 +47,6 @@ import org.olat.core.commons.services.vfs.VFSMetadata;
import org.olat.core.commons.services.vfs.VFSRepositoryService; import org.olat.core.commons.services.vfs.VFSRepositoryService;
import org.olat.core.helpers.Settings; import org.olat.core.helpers.Settings;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.apache.logging.log4j.Logger;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils; import org.olat.core.util.FileUtils;
import org.olat.core.util.vfs.VFSConstants; import org.olat.core.util.vfs.VFSConstants;
...@@ -58,7 +58,6 @@ import org.olat.core.util.vfs.VFSManager; ...@@ -58,7 +58,6 @@ import org.olat.core.util.vfs.VFSManager;
import org.olat.core.util.vfs.lock.LockInfo; import org.olat.core.util.vfs.lock.LockInfo;
import org.olat.core.util.vfs.lock.LockResult; import org.olat.core.util.vfs.lock.LockResult;
import org.olat.restapi.security.RestSecurityHelper; import org.olat.restapi.security.RestSecurityHelper;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -84,13 +83,11 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService { ...@@ -84,13 +83,11 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService {
@Autowired @Autowired
private OnlyOfficeSecurityService onlyOfficeSecurityService; private OnlyOfficeSecurityService onlyOfficeSecurityService;
@Autowired @Autowired
private DocEditorIdentityService identityService;
@Autowired
private VFSRepositoryService vfsRepositoryService; private VFSRepositoryService vfsRepositoryService;
@Autowired @Autowired
private VFSLockManager lockManager; private VFSLockManager lockManager;
@Autowired
private BaseSecurityManager securityManager;
@Autowired
private UserManager userManager;
@Override @Override
public boolean fileExists(String fileId) { public boolean fileExists(String fileId) {
...@@ -142,7 +139,7 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService { ...@@ -142,7 +139,7 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService {
InfoImpl info = new InfoImpl(); InfoImpl info = new InfoImpl();
String author = vfsMetadata.getAuthor() != null String author = vfsMetadata.getAuthor() != null
? userManager.getUserDisplayName(vfsMetadata.getAuthor()) ? identityService.getUserDisplayName(vfsMetadata.getAuthor())
: null; : null;
info.setAuthor(author); info.setAuthor(author);
info.setCreated(null); // not in metadata info.setCreated(null); // not in metadata
...@@ -168,9 +165,9 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService { ...@@ -168,9 +165,9 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService {
apiConfig.setEditor(editorConfig); apiConfig.setEditor(editorConfig);
UserImpl user = new UserImpl(); UserImpl user = new UserImpl();
String name = userManager.getUserDisplayName(identity); String name = identityService.getUserDisplayName(identity);
user.setName(name); user.setName(name);
user.setId(identity.getKey().toString()); user.setId(identityService.getGlobalIdentityId(identity));
editorConfig.setUser(user); editorConfig.setUser(user);
String token = onlyOfficeSecurityService.getApiConfigToken(document, editorConfig); String token = onlyOfficeSecurityService.getApiConfigToken(document, editorConfig);
...@@ -304,13 +301,7 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService { ...@@ -304,13 +301,7 @@ public class OnlyOfficeServiceImpl implements OnlyOfficeService {
@Override @Override
public Identity getIdentity(String identityId) { public Identity getIdentity(String identityId) {
try { return identityService.getIdentity(identityId);
Long identityKey = Long.valueOf(identityId);
return securityManager.loadIdentityByKey(identityKey);
} catch (NumberFormatException e) {
log.warn("Try to load identity with key " + identityId, e);
}
return null;
} }
} }
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.commons.services.doceditor.manager;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.olat.core.commons.services.doceditor.DocEditorIdentityService;
import org.olat.core.id.Identity;
import org.olat.test.JunitTestHelper;
import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Initial date: 17 May 2019<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public class DocEditorIdentityServiceTest extends OlatTestCase {
@Autowired
private DocEditorIdentityService sut;
@Test
public void shouldIdentifyIdentityBaGlobalId() {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("doc-editor-1");
String globalUserId = sut.getGlobalIdentityId(identity);
Identity reloadedIdentity = sut.getIdentity(globalUserId);
assertThat(reloadedIdentity).isEqualTo(identity);
}
}
...@@ -99,6 +99,7 @@ import org.junit.runners.Suite; ...@@ -99,6 +99,7 @@ import org.junit.runners.Suite;
org.olat.commons.coordinate.cluster.lock.LockTest.class, org.olat.commons.coordinate.cluster.lock.LockTest.class,
org.olat.commons.coordinate.CoordinatorTest.class, org.olat.commons.coordinate.CoordinatorTest.class,
org.olat.core.commons.services.csp.manager.CSPManagerTest.class, org.olat.core.commons.services.csp.manager.CSPManagerTest.class,
org.olat.core.commons.services.doceditor.manager.DocEditorIdentityServiceTest.class,
org.olat.core.commons.services.doceditor.wopi.manager.AccessDAOTest.class, org.olat.core.commons.services.doceditor.wopi.manager.AccessDAOTest.class,
org.olat.core.commons.services.doceditor.wopi.manager.WopiServiceTest.class, org.olat.core.commons.services.doceditor.wopi.manager.WopiServiceTest.class,
org.olat.core.commons.services.vfs.manager.VFSXStreamTest.class, org.olat.core.commons.services.vfs.manager.VFSXStreamTest.class,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment