Skip to content

Commit

Permalink
Add some javadoc + rename methods named xml(String) -> fromXml(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsotrifork committed Oct 8, 2024
1 parent 0daeccd commit 3892a6e
Show file tree
Hide file tree
Showing 14 changed files with 552 additions and 30 deletions.
26 changes: 26 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,32 @@

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/trifork/unsealed/AbstractBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.trifork.unsealed;


public abstract class AbstractBuilder<ParamsType extends AbstractBuilderParams> {

protected ParamsType params;
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/trifork/unsealed/BootstrapToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public class BootstrapToken {
this.jwt = jwt;
}

/**
* Invoke SOSI STS to exchange this bootstrap token to an IDWS identity token.
* @param audience The audience for the identity token, e.g., "https://minlog"
* @param cpr The CPR of the user
* @return The identity token
* @throws IOException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws InvalidAlgorithmParameterException
* @throws MarshalException
* @throws XMLSignatureException
* @throws XPathExpressionException
* @throws STSInvocationException
* @throws ParserConfigurationException
* @throws SAXException
*/
public IdentityToken exchangeToIdentityToken(String audience, String cpr)
throws IOException, InterruptedException,
NoSuchAlgorithmException, InvalidAlgorithmParameterException,
Expand All @@ -75,6 +91,24 @@ public IdentityToken exchangeToIdentityToken(String audience, String cpr)
return exchangeToIdentityToken(audience, cpr, null);
}

/**
*
* Invoke SOSI STS to exchange this bootstrap token to an IDWS identity token that includes verified procuration access.
* @param audience The audience for the identity token, e.g., "https://minlog"
* @param cpr The CPR of the user
* @param procurationCpr The CPR of the person being the procuration subject
* @return The identity token
* @throws IOException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws InvalidAlgorithmParameterException
* @throws MarshalException
* @throws XMLSignatureException
* @throws XPathExpressionException
* @throws STSInvocationException
* @throws ParserConfigurationException
* @throws SAXException
*/
public IdentityToken exchangeToIdentityToken(String audience, String cpr, String procurationCpr)
throws IOException, InterruptedException,
NoSuchAlgorithmException, InvalidAlgorithmParameterException,
Expand Down Expand Up @@ -199,6 +233,28 @@ private Element createBootstrapExchangeRequest(String audience, List<Claim> clai
return envelope;
}

/**
* Exchange thie bootstrap token to a IDCard of type user
* @param audience The <code>AppliesTo</code> for the security token request. This has no effect on the returned IDCard
* @param role The role of the IDCard
* @param occupation The occupation of the IDCard
* @param authId The auth id of the IDCard
* @param systemName The system name of the IDCard
* @return
* @throws IOException
* @throws InterruptedException
* @throws NoSuchAlgorithmException
* @throws InvalidAlgorithmParameterException
* @throws MarshalException
* @throws XMLSignatureException
* @throws XPathExpressionException
* @throws STSInvocationException
* @throws ParserConfigurationException
* @throws SAXException
* @throws UnrecoverableKeyException
* @throws KeyStoreException
* @throws CertificateException
*/
public UserIdCard exchangeToUserIdCard(String audience, String role, String occupation,
String authId, String systemName)
throws IOException, InterruptedException,
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/trifork/unsealed/BootstrapTokenBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ private BootstrapTokenBuilder(BootstrapTokenBuilderParams params) {
super(params);
}

/**
* Specify the NSP environment which will be the context for bootstrap tokens built by this builder
*
* @param env Either {@link NSPEnv#fromUrl(stsBaseUrl)} or one of the enum values of {@link com.trifork.unsealed.NSPTestEnv}
* @return A new immutable builder instance that encapsulates the supplied parameter
*/
public BootstrapTokenBuilder env(NSPEnv env) {
var params = this.params.copy();

Expand All @@ -24,18 +30,38 @@ public BootstrapTokenBuilder env(NSPEnv env) {
return new BootstrapTokenBuilder(params);
}

/**
* Set the supplied XML String as the bootstrap token source.
* @param xml A bootstrap token represented as an XML String
* @return A new immutable builder instance that encapsulates the supplied parameter
*/
public BootstrapTokenBuilder fromXml(String xml) {
var params = this.params.copy();
params.xml = xml;
return new BootstrapTokenBuilder(params);
}

/**
* Set the supplied JWT String as the bootstrap token source.
* @param jwt A bootstrap token represented as a JWT String
* @return
*/
public BootstrapTokenBuilder fromJwt(String jwt) {
var params = this.params.copy();
params.jwt = jwt;
return new BootstrapTokenBuilder(params);
}

/**
* Specify the SP (Service Provider) {@link CertAndKey} (certificate keypair). This is used if the issued bootstrap token is exchanged to an IDWS IdentityToken or a DGWS
* Idcard.
* @see BootstrapToken#exchangeToIdentityToken(String, String)
* @see BootstrapToken#exchangeToIdentityToken(String, String, String)
* @see BootstrapToken#exchangeToUserIdCard(String, String, String, String, String)
*
* @param spCertAndKey The SP keypair
* @return
*/
public BootstrapTokenBuilder spCertAndKey(CertAndKey spCertAndKey) {
var params = this.params.copy();
params.spCertAndKey = spCertAndKey;
Expand Down
68 changes: 66 additions & 2 deletions src/main/java/com/trifork/unsealed/BootstrapTokenIssuer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
* BootstrapTokenIssuer is an immutable builder that issues bootstrap tokens for the danish national health infrastructure. Intended for test use, since
* production bootstrap tokens typically are issued by official IdPs.
*
* @author Jeppe Sommer
*/
public class BootstrapTokenIssuer extends AbstractBuilder<BootstrapTokenIssuerParams> {
private static final String WELLKNOWN_STS_TEST_ISSUER_HOK = "https://idp.test.nspop.dk";

/**
* Create a blank builder instance.
*/
public BootstrapTokenIssuer() {
super(new BootstrapTokenIssuerParams());
}
Expand All @@ -30,6 +39,12 @@ private BootstrapTokenIssuer(BootstrapTokenIssuerParams params) {
super(params);
}

/**
* Specify the NSP environment which will be the context for the issued bootstrap tokens
*
* @param env Either {@link NSPEnv#fromUrl(stsBaseUrl)} or one of the enum values of {@link com.trifork.unsealed.NSPTestEnv}
* @return A new immutable builder instance that encapsulates the supplied parameter
*/
public BootstrapTokenIssuer env(NSPEnv env) {
var params = this.params.copy();

Expand All @@ -38,42 +53,88 @@ public BootstrapTokenIssuer env(NSPEnv env) {
return new BootstrapTokenIssuer(params);
}

/**
* Specify the CPR number of the user
*
* @param cpr
* The CPR number
* @return A new immutable builder instance that encapsulates the supplied parameter
*/
public BootstrapTokenIssuer cpr(String cpr) {
var params = this.params.copy();
params.cpr = cpr;
return new BootstrapTokenIssuer(params);
}

/**
* Specify the UUID of the user
*
* @param uuid The UUID
* @return A new immutable builder instance that encapsulates the supplied parameter
*/
public BootstrapTokenIssuer uuid(String uuid) {
var params = this.params.copy();
params.uuid = uuid;
return new BootstrapTokenIssuer(params);
}

/**
* Specify the CVR number of the users login organisation
*
* @param cvr The CVR number
* @return A new immutable builder instance that encapsulates the supplied parameter
*/
public BootstrapTokenIssuer cvr(String cvr) {
var params = this.params.copy();
params.cvr = cvr;
return new BootstrapTokenIssuer(params);
}

/**
* Specify the name of the users login organisation
*
* @param orgName The organisation name
* @return A new immutable builder instance that encapsulates the supplied parameter
*/
public BootstrapTokenIssuer orgName(String orgName) {
var params = this.params.copy();
params.orgName = orgName;
return new BootstrapTokenIssuer(params);
}

/**
* Specify the SP (Service Provider) {@link CertAndKey} (certificate keypair). This is used if the issued bootstrap token is exchanged to an IDWS IdentityToken or a DGWS
* Idcard.
* @see BootstrapToken#exchangeToIdentityToken(String, String)
* @see BootstrapToken#exchangeToIdentityToken(String, String, String)
* @see BootstrapToken#exchangeToUserIdCard(String, String, String, String, String)
*
* @param spCertAndKey The SP keypair
* @return
*/
public BootstrapTokenIssuer spCertAndKey(CertAndKey spCertAndKey) {
var params = this.params.copy();
params.spCertAndKey = spCertAndKey;
return new BootstrapTokenIssuer(params);
}

/**
* Specify the IdP (Identify Provider) {@link CertAndKey} (certificate keypair). This will be the issuer of issued tokens.
*
* @param idpCertAndKey The IdP keypair
* @return A new immutable builder instance that encapsulates the supplied parameter
*/
public BootstrapTokenIssuer idpCertAndKey(CertAndKey idpCertAndKey) {
var params = this.params.copy();
params.idpCertAndKey = idpCertAndKey;
return new BootstrapTokenIssuer(params);
}

/**
* Issue a bootstrap token for a citizen.
* @return The issued bootstrap token
* @throws Exception
*/
public BootstrapToken issueForCitizen()
throws Exception {

Expand All @@ -98,6 +159,11 @@ public BootstrapToken issueForCitizen()
xml, null);
}

/**
* Issue a bootstrap token for a healthcare professional
* @return The issued bootstrap token
* @throws Exception
*/
public BootstrapToken issueForProfessional()
throws Exception {

Expand Down Expand Up @@ -179,7 +245,6 @@ private Element createBootstrapToken(String audience, String nameId, String name

}


private static void signAssertion(X509Certificate idpCert, Key idpPrivateKey, Element assertion)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException,
XMLSignatureException {
Expand All @@ -193,5 +258,4 @@ private static void signAssertion(X509Certificate idpCert, Key idpPrivateKey, El
true);
}


}
Loading

0 comments on commit 3892a6e

Please sign in to comment.