}
@Override
public StompFrame onConnect(StompFrame frame)
{
StompFrame response = null;
Map<String, String> headers = frame.getHeadersMap();
String login = headers.get(Stomp.Headers.Connect.LOGIN);
String passcode = headers.get(Stomp.Headers.Connect.PASSCODE);
String clientID = headers.get(Stomp.Headers.Connect.CLIENT_ID);
String requestID = headers.get(Stomp.Headers.Connect.REQUEST_ID);
if (connection.validateUser(login, passcode))
{
connection.setClientID(clientID);
connection.setValid(true);
response = new StompFrameV10(Stomp.Responses.CONNECTED);
if (frame.hasHeader(Stomp.Headers.ACCEPT_VERSION))
{
response.addHeader(Stomp.Headers.Connected.VERSION, "1.0");
}
response.addHeader(Stomp.Headers.Connected.SESSION, connection.getID().toString());
if (requestID != null)
{
response.addHeader(Stomp.Headers.Connected.RESPONSE_ID, requestID);
}
}
else
{
//not valid
response = new StompFrameV10(Stomp.Responses.ERROR);
response.addHeader(Stomp.Headers.Error.MESSAGE, "Failed to connect");
try
{
response.setBody("The login account is not valid.");
}
catch (UnsupportedEncodingException e)
{
HornetQServerLogger.LOGGER.errorEncodingStompPacket(e);
}