-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrated websocket to api gateway. bump version
- Loading branch information
1 parent
434a02f
commit 2efaf74
Showing
13 changed files
with
875 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/edu/stanford/protege/webprotege/gateway/websocket/AccessManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package edu.stanford.protege.webprotege.gateway.websocket; | ||
|
||
|
||
import edu.stanford.protege.webprotege.authorization.*; | ||
import edu.stanford.protege.webprotege.gateway.websocket.dto.BuiltInAction; | ||
import edu.stanford.protege.webprotege.ipc.CommandExecutor; | ||
import edu.stanford.protege.webprotege.ipc.ExecutionContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
@Service | ||
public class AccessManager { | ||
|
||
private final static Logger LOGGER = LoggerFactory.getLogger(AccessManager.class); | ||
|
||
private final CommandExecutor<GetAuthorizationStatusRequest, GetAuthorizationStatusResponse> getAuthorizationStatusExecutor; | ||
|
||
public AccessManager(CommandExecutor<GetAuthorizationStatusRequest, GetAuthorizationStatusResponse> getAuthorizationStatusExecutor) { | ||
this.getAuthorizationStatusExecutor = getAuthorizationStatusExecutor; | ||
} | ||
|
||
public boolean hasPermission(@Nonnull Subject subject, | ||
@Nonnull Resource resource, | ||
@Nonnull BuiltInAction builtInAction, | ||
ExecutionContext executionContext) { | ||
try { | ||
GetAuthorizationStatusResponse response = getAuthorizationStatusExecutor.execute(new GetAuthorizationStatusRequest(resource, subject, builtInAction.getActionId()), | ||
executionContext) | ||
.get(); | ||
return response.authorizationStatus().equals(AuthorizationStatus.AUTHORIZED); | ||
|
||
} catch (InterruptedException | ExecutionException e) { | ||
LOGGER.error("Error when getting authorization status", e); | ||
return false; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |
60 changes: 60 additions & 0 deletions
60
.../java/edu/stanford/protege/webprotege/gateway/websocket/ProjectChangedEmitterHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package edu.stanford.protege.webprotege.gateway.websocket; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import edu.stanford.protege.webprotege.event.EventTag; | ||
import edu.stanford.protege.webprotege.gateway.websocket.dto.EventList; | ||
import edu.stanford.protege.webprotege.gateway.websocket.dto.PackagedProjectChangeEvent; | ||
import edu.stanford.protege.webprotege.gateway.websocket.dto.ProjectEventsQueryResponse; | ||
import edu.stanford.protege.webprotege.ipc.EventHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.messaging.support.GenericMessage; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@Component | ||
public class ProjectChangedEmitterHandler implements EventHandler<PackagedProjectChangeEvent> { | ||
|
||
private final static Logger LOGGER = LoggerFactory.getLogger(ProjectChangedEmitterHandler.class); | ||
|
||
private final SimpMessagingTemplate simpMessagingTemplate; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
public ProjectChangedEmitterHandler(SimpMessagingTemplate simpMessagingTemplate, ObjectMapper objectMapper) { | ||
this.simpMessagingTemplate = simpMessagingTemplate; | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
|
||
@Nonnull | ||
@Override | ||
public String getChannelName() { | ||
return "webprotege.events.projects.PackagedProjectChange"; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getHandlerName() { | ||
return this.getClass().getName(); | ||
} | ||
|
||
@Override | ||
public Class<PackagedProjectChangeEvent> getEventClass() { | ||
return PackagedProjectChangeEvent.class; | ||
} | ||
|
||
@Override | ||
public void handleEvent(PackagedProjectChangeEvent event) { | ||
try { | ||
ProjectEventsQueryResponse response = new ProjectEventsQueryResponse(); | ||
response.events = new EventList(EventTag.getFirst(), event.projectEvents(), EventTag.get(1)); | ||
simpMessagingTemplate.send("/topic/project-events/" + event.projectId().id(), new GenericMessage<>(objectMapper.writeValueAsBytes(response))); | ||
|
||
} catch (Exception e) { | ||
LOGGER.error("Error forwarding the events through websocket"); | ||
} | ||
} | ||
} |
Oops, something went wrong.