Tiny security library for SparkJava.
To use the library add the following lines:
SparkSecurity.setSecurityHandlerClass(SimpleSecurityHandler.class);
SparkSecurity.init();
The security handler needs to be implemented to set the correct authentication:
public class SimpleSecurityHandler implements SecurityHandler {
private static final String AUTH_TOKEN = "AUTH-TOKEN";
@Override
public void handle(Request request, SecurityContext context) {
String authToken = request.headers(AUTH_TOKEN);
if (StringUtils.equals(authToken, "secrettoken")) {
AuthenticationImpl authentication = new AuthenticationImpl();
authentication.addPermission(new PermissionImpl("login"));
context.setAuthentication(authentication);
}
}
}
The code has not been tested.