1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.picketlink;
18
19 import org.picketlink.identity.federation.api.wstrust.WSTrustClient;
20 import org.picketlink.identity.federation.api.wstrust.WSTrustClient.SecurityInfo;
21 import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
22 import org.picketlink.identity.federation.core.wstrust.WSTrustException;
23 import org.picketlink.identity.federation.core.wstrust.plugins.saml.SAMLUtil;
24 import org.w3c.dom.Element;
25
26
27
28
29
30
31
32 public class WSTrustClientExample {
33
34 public static void main(String[] args) throws Exception {
35
36 String userName = (args.length > 0 ? args[0] : "tomcat");
37 String password = (args.length > 1 ? args[1] : "tomcat");
38
39
40 WSTrustClient client = new WSTrustClient("PicketLinkSTS", "PicketLinkSTSPort", "http://localhost:8080/picketlink-sts/PicketLinkSTS",
41 new SecurityInfo(userName, password));
42 Element assertionElement = null;
43 try {
44 System.out.println("Invoking token service to get SAML assertion for user:" + userName + " with password:" + password);
45
46 assertionElement = client.issueToken(SAMLUtil.SAML2_TOKEN_TYPE);
47 System.out.println("SAML assertion for user:" + userName + " successfully obtained!");
48 } catch (WSTrustException wse) {
49 System.out.println("Unable to issue assertion: " + wse.getMessage());
50 wse.printStackTrace();
51 System.exit(1);
52 } catch (Exception e) {
53 System.out.println("Problem:" + e.getMessage());
54 e.printStackTrace();
55 System.exit(2);
56 }
57
58
59 String el = DocumentUtil.getDOMElementAsString(assertionElement);
60 System.out.println(el);
61 }
62
63 }