
net.scattersphere.util.AuthenticationHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scattersphere-core Show documentation
Show all versions of scattersphere-core Show documentation
Scattersphere Core library, used to run the main server.
The newest version!
package net.scattersphere.util;
import net.scattersphere.data.DataSerializer;
import net.scattersphere.data.message.ServerAuthResponseMessage;
import net.scattersphere.registry.AuthRegistry;
import net.scattersphere.server.ClientConnection;
import org.vertx.java.core.buffer.Buffer;
/**
* This class handles authentication for the specified {@link ClientConnection}.
*
* Created by kenji on 3/13/15.
*/
public class AuthenticationHelper {
/**
* Indicates whether or not the server requires authentication.
*
* @return {@code true} if authentication is required, {@code false} otherwise.
*/
public static boolean requiresAuthentication() {
return AuthRegistry.instance().size() > 0;
}
/**
* Sends a response to the client indicating that authentication is required.
*
* @param client {@link ClientConnection} connection object.
*/
public static void sendAuthRequired(ClientConnection client) {
ServerAuthResponseMessage sarMessage = new ServerAuthResponseMessage(true, false);
Buffer buffer = new Buffer(DataSerializer.packetize(sarMessage.toByteArray()));
client.getEndpoint().write(buffer);
}
/**
* Sends a message back to the client indicating successful authentication.
*
* @param client {@link ClientConnection} object.
*/
public static void sendAuthSuccessful(ClientConnection client) {
ServerAuthResponseMessage sarMessage = new ServerAuthResponseMessage(true, true);
Buffer buffer = new Buffer(DataSerializer.packetize(sarMessage.toByteArray()));
client.setAuthenticated(true);
client.getEndpoint().write(buffer);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy