mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 15:37:56 +01:00
Fix unlock issues.
This commit is contained in:
parent
31fb342ef1
commit
a230dd104c
@ -0,0 +1,44 @@
|
||||
package com.wisemapping.listener;
|
||||
|
||||
|
||||
import com.wisemapping.exceptions.AccessDeniedSecurityException;
|
||||
import com.wisemapping.exceptions.LockException;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.LockManager;
|
||||
import com.wisemapping.service.MindmapService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSessionEvent;
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
|
||||
public class UnlockOnExpireListener implements HttpSessionListener {
|
||||
|
||||
@Override
|
||||
public void sessionCreated(@NotNull HttpSessionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionDestroyed(@NotNull HttpSessionEvent event) {
|
||||
|
||||
final ServletContext servletContext = event.getSession().getServletContext();
|
||||
final WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
|
||||
final MindmapService mindmapService = (MindmapService) wc.getBean("mindmapService");
|
||||
final LockManager lockManager = mindmapService.getLockManager();
|
||||
|
||||
final User user = Utils.getUser(false);
|
||||
if (user != null) {
|
||||
try {
|
||||
lockManager.unlockAll(user);
|
||||
} catch (LockException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AccessDeniedSecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -34,13 +34,12 @@ public interface LockManager {
|
||||
|
||||
void unlock(@NotNull Mindmap mindmap, @NotNull User user) throws LockException, AccessDeniedSecurityException;
|
||||
|
||||
void unlockAll(@NotNull User user) throws LockException, AccessDeniedSecurityException;
|
||||
|
||||
boolean isLockedBy(@NotNull Mindmap mindmap, @NotNull User collaborator);
|
||||
|
||||
@NotNull
|
||||
LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws WiseMappingException;
|
||||
|
||||
@NotNull
|
||||
LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user) throws WiseMappingException;
|
||||
|
||||
long generateSession();
|
||||
}
|
||||
|
@ -79,6 +79,17 @@ class LockManagerImpl implements LockManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlockAll(@NotNull final User user) throws LockException, AccessDeniedSecurityException {
|
||||
final Set<Integer> mapIds = lockInfoByMapId.keySet();
|
||||
for (final Integer mapId : mapIds) {
|
||||
final LockInfo lockInfo = lockInfoByMapId.get(mapId);
|
||||
if (lockInfo.getUser().identityEquality(user)) {
|
||||
unlock(mapId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlock(@NotNull Mindmap mindmap, @NotNull User user) throws LockException, AccessDeniedSecurityException {
|
||||
if (isLocked(mindmap) && !isLockedBy(mindmap, user)) {
|
||||
@ -93,6 +104,8 @@ class LockManagerImpl implements LockManager {
|
||||
}
|
||||
|
||||
private void unlock(int mapId) {
|
||||
System.out.println("Unlocking:"+mapId);
|
||||
|
||||
logger.debug("Unlock map id:" + mapId);
|
||||
lockInfoByMapId.remove(mapId);
|
||||
}
|
||||
@ -108,12 +121,6 @@ class LockManagerImpl implements LockManager {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user) throws WiseMappingException {
|
||||
return this.lock(mindmap, user, System.nanoTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long generateSession() {
|
||||
return System.nanoTime();
|
||||
@ -135,7 +142,7 @@ class LockManagerImpl implements LockManager {
|
||||
// Update timeout only...
|
||||
logger.debug("Update timestamp:" + mindmap.getId());
|
||||
updateExpirationTimeout(mindmap, user);
|
||||
// result.setSession(session);
|
||||
// result.setSession(session);
|
||||
} else {
|
||||
logger.debug("Lock map id:" + mindmap.getId());
|
||||
result = new LockInfo(user, mindmap, session);
|
||||
|
@ -47,6 +47,9 @@
|
||||
<listener>
|
||||
<listener-class>com.wisemapping.service.HibernateAppListener</listener-class>
|
||||
</listener>
|
||||
<listener>
|
||||
<listener-class>com.wisemapping.listener.UnlockOnExpireListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<filter>
|
||||
<filter-name>hibernate</filter-name>
|
||||
|
Loading…
Reference in New Issue
Block a user