Hi,
First of all thanks for the great library. I've starting developing a proof of concept application at my company and I was restricted to Java, I chose SparkJava as it is very similar to what I'm used in terms of web development in Python (Flask).
I need now to implement authentication into my application using SAML2.0. It's basically a type file server that need to perform authentication, logging and authorization (not SAML, it's an internal API). I also need to use SSL (http) when making the authentication.
My company have a SAML IdP. I'm given a .P12 file from which I created a keygen to use when creating the SAML2 Client.)
The IdP gives me a Metadata file. They also have a link to generate a SP Metadata where we need to change manually some details (entityID, Location and the KeyInfo > X509Certificate). The X509 hash we are supposed to copy from the IdP Metadata, I guess they need to match to establish the trusted link? But I see that Pac4J generates its own SP metadata, so which should I use? Any help would be great as I'm a bit lost (first time I have to deal with SAML).
Other question I ran the app demo (
https://github.com/pac4j/spark-pac4j-demo) and every authentication example works (Facebook, Twitter, etc...) but on SAML I get a
"Needs client redirection" I also get the same on my implementation that is basicaly what the demo app uses.
I have a client builder:
public class ClientsBuilder {
public static Clients build(){
final Saml2Client sapidSaml2Client = new Saml2Client();
sapidSaml2Client.setKeystorePath("src/main/resources/jks/keystore.jks");
sapidSaml2Client.setKeystorePassword("welcome1");
sapidSaml2Client.setPrivateKeyPassword("welcome1");
sapidSaml2Client.setIdpMetadataPath("src/main/resources/idp.xml");
return new Clients("https://localhost:8888/callback", sapidSaml2Client);
}
}
And my authentication is simply this class:
public class Authentication {
public Authentication() {
final Clients clients = ClientsBuilder.build();
final Route callback = new CallbackRoute(clients);
get("/callback", callback);
post("/callback", callback);
// Require authentication before proceeding with the rest of the process
before("/", new RequiresAuthenticationFilter(clients, "Saml2Client"));
get("/", (req, res) -> postAuthentication(req, res, clients)); // After authentication
}
private static String postAuthentication(final Request request, final Response response, final Clients clients) {
final SparkWebContext context = new SparkWebContext(request, response);
final CommonProfile profile = UserUtils.getProfile(request);
return "<a href='" + clients.findClient(Saml2Client.class).getRedirectionUrl(context) + "'>Authenticate</a>";
}
}
If anyone could give me some insight into what I may be doing wrong it would be great, I can also show the metadatas if needed.