package at.gv.egovernment.moa.id.auth.builder; import java.io.ByteArrayOutputStream; import java.security.MessageDigest; import at.gv.egovernment.moa.id.BuildException; import at.gv.egovernment.moa.util.Base64Utils; /** * Builder for the SAML artifact, as defined in the * Browser/Artifact profile of SAML. * * @author Paul Ivancsics * @version $Id$ */ public class SAMLArtifactBuilder { /** * Constructor for SAMLArtifactBuilder. */ public SAMLArtifactBuilder() { super(); } /** * Builds the SAML artifact, encoded BASE64. * * @param authURL URL auf the MOA-ID Auth component to be used for construction * of SourceID * @param sessionID MOASessionID to be used for construction * of AssertionHandle * @return the 42-byte SAML artifact, encoded BASE64 */ public String build(String authURL, String sessionID) throws BuildException { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] sourceID = md.digest(authURL.getBytes()); byte[] assertionHandle = md.digest(sessionID.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(42); out.write(0); out.write(1); out.write(sourceID, 0, 20); out.write(assertionHandle, 0, 20); byte[] samlArtifact = out.toByteArray(); String samlArtifactBase64 = Base64Utils.encode(samlArtifact); return samlArtifactBase64; } catch (Throwable ex) { throw new BuildException( "builder.00", new Object[] {"SAML Artifact, MOASessionID=" + sessionID, ex.toString()}, ex); } } }