Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
*/
package com.corundumstudio.socketio;

import java.util.Map;

public interface AuthorizationListener {

/**
* Checks is client with handshake data is authorized
*
* @param data - handshake data
* @param saveData - data need to save to store
* @return - <b>true</b> if client is authorized of <b>false</b> otherwise
*/
boolean isAuthorized(HandshakeData data);
boolean isAuthorized(HandshakeData data, Map<String, Object> saveData);

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ private boolean authorize(ChannelHandlerContext ctx, Channel channel, String ori
headers.put(name, values);
}

HandshakeData data = new HandshakeData(req.headers(), params,
HandshakeData handshakeData = new HandshakeData(req.headers(), params,
(InetSocketAddress)channel.remoteAddress(),
(InetSocketAddress)channel.localAddress(),
req.uri(), origin != null && !origin.equalsIgnoreCase("null"));

boolean result = false;
Map<String, Object> saveData = new HashMap<String, Object>();
try {
result = configuration.getAuthorizationListener().isAuthorized(data);
result = configuration.getAuthorizationListener().isAuthorized(handshakeData, saveData);
} catch (Exception e) {
log.error("Authorization error", e);
}
Expand Down Expand Up @@ -187,7 +188,8 @@ private boolean authorize(ChannelHandlerContext ctx, Channel channel, String ori
return false;
}

ClientHead client = new ClientHead(sessionId, ackManager, disconnectable, storeFactory, data, clientsBox, transport, disconnectScheduler, configuration);

ClientHead client = new ClientHead(sessionId, ackManager, disconnectable, storeFactory, handshakeData, saveData, clientsBox, transport, disconnectScheduler, configuration);
channel.attr(ClientHead.CLIENT).set(client);
clientsBox.addClient(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class ClientHead {
private volatile Transport currentTransport;

public ClientHead(UUID sessionId, AckManager ackManager, DisconnectableHub disconnectable,
StoreFactory storeFactory, HandshakeData handshakeData, ClientsBox clientsBox, Transport transport, CancelableScheduler disconnectScheduler,
StoreFactory storeFactory, HandshakeData handshakeData, Map<String, Object> saveData, ClientsBox clientsBox, Transport transport, CancelableScheduler disconnectScheduler,
Configuration configuration) {
this.sessionId = sessionId;
this.ackManager = ackManager;
Expand All @@ -81,7 +81,9 @@ public ClientHead(UUID sessionId, AckManager ackManager, DisconnectableHub disco
this.currentTransport = transport;
this.disconnectScheduler = disconnectScheduler;
this.configuration = configuration;

for(Map.Entry<String, Object> entry : saveData.entrySet()) {
this.store.set(entry.getKey(), entry.getValue());
}
channels.put(Transport.POLLING, new TransportState());
channels.put(Transport.WEBSOCKET, new TransportState());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import com.corundumstudio.socketio.AuthorizationListener;
import com.corundumstudio.socketio.HandshakeData;

import java.util.Map;

public class SuccessAuthorizationListener implements AuthorizationListener {

@Override
public boolean isAuthorized(HandshakeData data) {
public boolean isAuthorized(HandshakeData data, Map<String, Object> saveData) {
return true;
}

}