Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.lastpass:saml-sdk-java:v0.3.0'
}
dependencies {
implementation("com.github.lastpass:saml-sdk-java:v0.3.0")
}
<dependency>
<groupId>com.github.lastpass</groupId>
<artifactId>saml-sdk-java</artifactId>
<version>v0.3.0</version>
</dependency>
libraryDependencies += "com.github.lastpass" % "saml-sdk-java" % "v0.3.0"
:dependencies [[com.github.lastpass/saml-sdk-java "v0.3.0"]]
The LastPass SAML SDK for Java is a set of Java classes that makes it easy to add SAML 2.0 based single-sign on to your Java applications. The SDK is built on top of the OpenSAML library and provides a simple client interface for service providers.
The SAML standard is a web-based authentication protocol. A typical session operates like this:
This library implements steps one and four of the process: creating a SAML token request, and processing a signed token to test its validity.
There are several providers. We suggest checking out our own IdP service, part of LastPass Enterprise, at https://lastpass.com/.
The SDK requires Java 1.5+ and ant. Simply run ant to build:
$ ant
This will download dependencies with ivy and then build the class files. The output will be in out/lastpass-saml-sdk.jar.
There are two main steps to integrate SAML into your application:
Actual steps for integration are outside the scope of this library, but a synopsis follows:
// at application startup, init library and create the client
SAMLInit.intialize();
IdPConfig idpConfig = new IdPConfig(new File("idp-metadata.xml"));
SPConfig spConfig = new SPConfig(new File("sp-metadata.xml"));
client = new SAMLClient(spConfig, idpConfig);
// ...
// when a login link is clicked, create auth request and
// redirect to the IdP
String requestId = SAMLUtils.generateRequestId();
String authrequest = client.generateAuthnRequest(requestId);
String url = client.getIdPConfig().getLoginUrl() +
"?SAMLRequest=" + URLEncoder.encode(authrequest, "UTF-8");
// redirect to url...
// ...
// when a saml token is posted, extract the subject
String authresponse = request.getParameter("SAMLResponse");
AttributeSet aset;
try {
aset = client.validateResponse(authresponse);
String user = aset.getNameId();
// do something with now-authenticated user...
} catch (SAMLException e) {
// response invalid, return to login page...
}
The LastPass SAML SDK is licensed under the Apache License, version 2.0.