-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
5b659d6
commit c5c4cd9
Showing
14 changed files
with
235 additions
and
36 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import io.getlime.security.powerauth.lib.webflow.authentication.service.OperationCancellationService; | ||
import io.getlime.security.powerauth.lib.webflow.authentication.service.OperationSessionService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.socket.CloseStatus; | ||
|
@@ -34,6 +35,7 @@ | |
* @author Roman Strobl, [email protected] | ||
*/ | ||
@Component | ||
@ConditionalOnProperty(name = "powerauth.webflow.websockets.enabled", havingValue = "true") | ||
public class WebSocketDisconnectListener implements ApplicationListener<SessionDisconnectEvent> { | ||
|
||
private final OperationSessionService operationSessionService; | ||
|
63 changes: 63 additions & 0 deletions
63
...urity/powerauth/lib/webflow/authentication/service/websocket/WebSocketMessageService.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,63 @@ | ||
/* | ||
* Copyright 2024 Wultra s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.getlime.security.powerauth.lib.webflow.authentication.service.websocket; | ||
|
||
import io.getlime.security.powerauth.lib.nextstep.model.enumeration.AuthResult; | ||
|
||
/** | ||
* Interface for WebSocket messages. | ||
* | ||
* @author Roman Strobl, [email protected] | ||
*/ | ||
public interface WebSocketMessageService { | ||
|
||
/** | ||
* Notification of clients about completed authorization. | ||
* | ||
* @param operationId Operation ID. | ||
* @param authResult Authorization result. | ||
*/ | ||
void notifyAuthorizationComplete(String operationId, AuthResult authResult); | ||
|
||
/** | ||
* Sends a message about successful websocket registration to the user. | ||
* | ||
* @param operationHash Operation hash. | ||
* @param sessionId Session ID. | ||
* @param registrationSucceeded Whether Web Socket registration was successful. | ||
*/ | ||
void sendRegistrationMessage(String operationHash, String sessionId, boolean registrationSucceeded); | ||
|
||
/** | ||
* Get Web Socket session ID for given operation hash. | ||
* | ||
* @param operationHash Operation hash. | ||
* @return Web Socket session ID. | ||
*/ | ||
String lookupWebSocketSessionId(String operationHash); | ||
|
||
/** | ||
* Store a mapping for new web socket identifier to the Web Socket session with given ID. | ||
* | ||
* @param operationHash Operation hash. | ||
* @param webSocketSessionId Web Socket Session ID. | ||
* @param clientIpAddress Remote client IP address. | ||
* @return Whether Web Socket registration was successful. | ||
*/ | ||
boolean registerWebSocketSession(String operationHash, String webSocketSessionId, String clientIpAddress); | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
.../powerauth/lib/webflow/authentication/service/websocket/WebSocketMessageServiceDummy.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,56 @@ | ||
/* | ||
* Copyright 2024 Wultra s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.getlime.security.powerauth.lib.webflow.authentication.service.websocket; | ||
|
||
import io.getlime.security.powerauth.lib.nextstep.model.enumeration.AuthResult; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Dummy WebSocket service. | ||
* | ||
* @author Roman Strobl, [email protected] | ||
*/ | ||
@Service | ||
@Slf4j | ||
@ConditionalOnProperty(name = "powerauth.webflow.websockets.enabled", havingValue = "false", matchIfMissing = true) | ||
public class WebSocketMessageServiceDummy implements WebSocketMessageService { | ||
|
||
{ | ||
logger.info("WebSocketMessageServiceDummy was initialized."); | ||
} | ||
|
||
@Override | ||
public void notifyAuthorizationComplete(String operationId, AuthResult authResult) { | ||
} | ||
|
||
@Override | ||
public void sendRegistrationMessage(String operationHash, String sessionId, boolean registrationSucceeded) { | ||
} | ||
|
||
@Override | ||
public String lookupWebSocketSessionId(String operationHash) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean registerWebSocketSession(String operationHash, String webSocketSessionId, String clientIpAddress) { | ||
return false; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -14,12 +14,15 @@ | |
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.getlime.security.powerauth.lib.webflow.authentication.service; | ||
package io.getlime.security.powerauth.lib.webflow.authentication.service.websocket; | ||
|
||
import io.getlime.security.powerauth.lib.nextstep.model.enumeration.AuthResult; | ||
import io.getlime.security.powerauth.lib.webflow.authentication.model.response.WebSocketAuthorizationResponse; | ||
import io.getlime.security.powerauth.lib.webflow.authentication.model.response.WebSocketRegistrationResponse; | ||
import io.getlime.security.powerauth.lib.webflow.authentication.service.OperationSessionService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.messaging.MessageHeaders; | ||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; | ||
import org.springframework.messaging.simp.SimpMessageType; | ||
|
@@ -33,7 +36,9 @@ | |
* @author Petr Dvorak, [email protected] | ||
*/ | ||
@Service | ||
public class WebSocketMessageService { | ||
@Slf4j | ||
@ConditionalOnProperty(name = "powerauth.webflow.websockets.enabled", havingValue = "true") | ||
public class WebSocketMessageServiceImpl implements WebSocketMessageService { | ||
|
||
private final SimpMessagingTemplate websocket; | ||
private final OperationSessionService operationSessionService; | ||
|
@@ -44,9 +49,10 @@ public class WebSocketMessageService { | |
* @param operationSessionService Operation to session mapping service. | ||
*/ | ||
@Autowired | ||
public WebSocketMessageService(SimpMessagingTemplate websocket, OperationSessionService operationSessionService) { | ||
public WebSocketMessageServiceImpl(SimpMessagingTemplate websocket, OperationSessionService operationSessionService) { | ||
this.websocket = websocket; | ||
this.operationSessionService = operationSessionService; | ||
logger.info("WebSocketMessageServiceImpl was initialized."); | ||
} | ||
|
||
/** | ||
|
@@ -62,12 +68,7 @@ private MessageHeaders createHeaders(String webSocketSessionId) { | |
return headerAccessor.getMessageHeaders(); | ||
} | ||
|
||
/** | ||
* Notification of clients about completed authorization. | ||
* | ||
* @param operationId Operation ID. | ||
* @param authResult Authorization result. | ||
*/ | ||
@Override | ||
public void notifyAuthorizationComplete(String operationId, AuthResult authResult) { | ||
final String webSocketId = operationSessionService.generateOperationHash(operationId); | ||
final String sessionId = lookupWebSocketSessionId(webSocketId); | ||
|
@@ -79,38 +80,20 @@ public void notifyAuthorizationComplete(String operationId, AuthResult authResul | |
} | ||
} | ||
|
||
/** | ||
* Sends a message about successful websocket registration to the user. | ||
* | ||
* @param operationHash Operation hash. | ||
* @param sessionId Session ID. | ||
* @param registrationSucceeded Whether Web Socket registration was successful. | ||
*/ | ||
@Override | ||
public void sendRegistrationMessage(String operationHash, String sessionId, boolean registrationSucceeded) { | ||
WebSocketRegistrationResponse registrationResponse = new WebSocketRegistrationResponse(); | ||
registrationResponse.setWebSocketId(operationHash); | ||
registrationResponse.setRegistrationSucceeded(registrationSucceeded); | ||
websocket.convertAndSendToUser(sessionId, "/topic/registration", registrationResponse, createHeaders(sessionId)); | ||
} | ||
|
||
/** | ||
* Get Web Socket session ID for given operation hash. | ||
* | ||
* @param operationHash Operation hash. | ||
* @return Web Socket session ID. | ||
*/ | ||
@Override | ||
public String lookupWebSocketSessionId(String operationHash) { | ||
return operationSessionService.lookupWebSocketSessionIdByOperationHash(operationHash); | ||
} | ||
|
||
/** | ||
* Store a mapping for new web socket identifier to the Web Socket session with given ID. | ||
* | ||
* @param operationHash Operation hash. | ||
* @param webSocketSessionId Web Socket Session ID. | ||
* @param clientIpAddress Remote client IP address. | ||
* @return Whether Web Socket registration was successful. | ||
*/ | ||
@Override | ||
public boolean registerWebSocketSession(String operationHash, String webSocketSessionId, String clientIpAddress) { | ||
return operationSessionService.registerWebSocketSession(operationHash, webSocketSessionId, clientIpAddress); | ||
} | ||
|
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
Oops, something went wrong.