<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.umiacs.umd.edu/adapt/index.php?action=history&amp;feed=atom&amp;title=Saml%3AGetSamlToken</id>
	<title>Saml:GetSamlToken - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.umiacs.umd.edu/adapt/index.php?action=history&amp;feed=atom&amp;title=Saml%3AGetSamlToken"/>
	<link rel="alternate" type="text/html" href="https://wiki.umiacs.umd.edu/adapt/index.php?title=Saml:GetSamlToken&amp;action=history"/>
	<updated>2026-04-07T09:12:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.7</generator>
	<entry>
		<id>https://wiki.umiacs.umd.edu/adapt/index.php?title=Saml:GetSamlToken&amp;diff=1985&amp;oldid=prev</id>
		<title>Scsong at 23:39, 11 September 2008</title>
		<link rel="alternate" type="text/html" href="https://wiki.umiacs.umd.edu/adapt/index.php?title=Saml:GetSamlToken&amp;diff=1985&amp;oldid=prev"/>
		<updated>2008-09-11T23:39:30Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Client connection to Authority==&lt;br /&gt;
&lt;br /&gt;
===Prepare keystore===&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll need to have a keystore that contains the following items:&lt;br /&gt;
&lt;br /&gt;
# Client keypair with public key signed by a CA that is known to the Authority&lt;br /&gt;
# Copy of the Authorities public key to validate the returned assertion.&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s a sample on how to load the keystore and required certs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import static edu.umiacs.wssec.Wss4jConstants.KEYSTORE_TYPE_DEFAULT;&lt;br /&gt;
import static edu.umiacs.wssec.Wss4jConstants.KEYSTORE_PROVIDER_DEFAULT;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
    public static final String  KEYSTORE_PATH      = &amp;quot;client.p12&amp;quot;;&lt;br /&gt;
    public static final String  KEYSTORE_ALIAS     = &amp;quot;client&amp;quot;;&lt;br /&gt;
    public static final String  KEYSTORE_PASS      = &amp;quot;client&amp;quot;;&lt;br /&gt;
    public static final String  KEYSTORE_AUTHORITY = &amp;quot;authority&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    Certificate clientCert;&lt;br /&gt;
    Certificate authorityCert;&lt;br /&gt;
    KeyStore    keyStore;&lt;br /&gt;
            &lt;br /&gt;
    keyStore = KeyStore.getInstance(KEYSTORE_TYPE_DEFAULT,KEYSTORE_PROVIDER_DEFAULT);&lt;br /&gt;
    keyStore.load(new FileInputStream( new File(KEYSTORE_PATH) ), KEYSTORE_PASS.toCharArray());&lt;br /&gt;
            &lt;br /&gt;
    // check for alias of private key&lt;br /&gt;
    if (!keyStore.containsAlias(KEYSTORE_ALIAS)&lt;br /&gt;
        || !(keyStore.getKey(KEYSTORE_ALIAS, KEYSTORE_PASS.toCharArray()) != null )) {&lt;br /&gt;
                &lt;br /&gt;
        System.err.println(&amp;quot;cannot load keystore alias&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    clientCert      = keyStore.getCertificateChain(KEYSTORE_ALIAS)[0];&lt;br /&gt;
    authorityCert   = keyStore.getCertificate(KEYSTORE_AUTHORITY);&lt;br /&gt;
&lt;br /&gt;
    //For later, cache keystore&lt;br /&gt;
    CachedDoAllSender.setSignatureKeyStore(keyStore);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Call Authority===&lt;br /&gt;
&lt;br /&gt;
Next, call the authority, get the certificate and convert it to a SAMLAssertion&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    // standard axis wsdl2java generated stubs. You can add extra handlers, wss4j, etc if you&lt;br /&gt;
    // authority uses it for authentication.&lt;br /&gt;
    Authority               auth;&lt;br /&gt;
    AuthorityServiceLocator authSL;&lt;br /&gt;
&lt;br /&gt;
    authSL = new AuthorityServiceLocator();&lt;br /&gt;
    authSL.setAuthorityEndpointAddress(SERVICE_AUTH_URL);&lt;br /&gt;
    auth = authSL.getAuthority();&lt;br /&gt;
&lt;br /&gt;
    String samlToken = auth.authenticateClient(clientCert.getEncoded());&lt;br /&gt;
&lt;br /&gt;
    // convert assertion&lt;br /&gt;
    SAMLAssertion assertion = new SAMLAssertion(&lt;br /&gt;
            new ByteArrayInputStream(samlToken.getBytes()));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
            &lt;br /&gt;
===Validate Assertion===&lt;br /&gt;
&lt;br /&gt;
You need to validate that the assertion was issued by the authority you expected and not merely by another party w/ a key signed by the same CA as the authorities key. The easiet way to do this is to keep a copy of the authorities key locally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    // throws exception if it can&amp;#039;t verify&lt;br /&gt;
    assertion.verify(authorityCert);&lt;br /&gt;
&lt;br /&gt;
    // For later, cache assertion.&lt;br /&gt;
    CachedDoAllSender.setSamlAssertion(assertion);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Scsong</name></author>
	</entry>
</feed>