Author: beve
Date: 2009-09-28 04:38:47 -0400 (Mon, 28 Sep 2009)
New Revision: 811
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustClient.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/wstrust/STSClient.java
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/wstrust/STSClientUnitTestCase.java
Log:
Work for
https://jira.jboss.org/jira/browse/JBID-195 "Add 'AppliesTo' support
for WSTrustClient and STSClient"
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustClient.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustClient.java 2009-09-25
17:41:16 UTC (rev 810)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustClient.java 2009-09-28
08:38:47 UTC (rev 811)
@@ -80,8 +80,22 @@
{
return stsClient.issueToken(tokenType);
}
-
+
/**
+ * This method will send a RequestSecurityToken with a RequestType of issue
+ * and the passed-in endpointURI identifies the ultimate recipient of the token.
+ *
+ * @param endpointURI - The ultimate recipient of the token. This will be set at the
AppliesTo for
+ * the RequestSecurityToken which is an optional element so it
may be null.
+ * @return Element - The Security Token element. Will be of the tokenType configured
for the endpointURI.
+ * @throws WSTrustException
+ */
+ public Element issueTokenForEndpoint(String endpointURI) throws WSTrustException
+ {
+ return stsClient.issueTokenForEndpoint(endpointURI);
+ }
+
+ /**
* This method will send a RequestSecurityToken with a RequestType of renew
* and the passed-in tokenType identifies the type of token to be renewed by
* the STS.
@@ -93,7 +107,6 @@
public Element renewToken(String tokenType, Element token) throws WSTrustException
{
return stsClient.renewToken(tokenType, token);
-
}
/**
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/wstrust/STSClient.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/wstrust/STSClient.java 2009-09-25
17:41:16 UTC (rev 810)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/wstrust/STSClient.java 2009-09-28
08:38:47 UTC (rev 811)
@@ -82,16 +82,50 @@
}
dispatchLocal.set(dispatch);
}
-
+
+ /**
+ * Issues a Security Token for the ultimate recipient of the token.
+ *
+ * @param endpointURI - The ultimate recipient of the token. This will be set at the
AppliesTo for
+ * the RequestSecurityToken which is an optional element so it
may be null.
+ * @return Element - The Security Token Element which will be of the TokenType
configured
+ * for the endpointURI passed in.
+ * @throws WSTrustException
+ */
+ public Element issueTokenForEndpoint(final String endpointURI) throws
WSTrustException
+ {
+ RequestSecurityToken request = new RequestSecurityToken();
+ setAppliesTo(endpointURI, request);
+ return issueToken(request);
+ }
+
public Element issueToken(String tokenType) throws WSTrustException
{
// create a custom token request message.
RequestSecurityToken request = new RequestSecurityToken();
- request.setTokenType(URI.create(tokenType));
+ setTokenType(tokenType, request);
+ // send the token request to JBoss STS and get the response.
+ return issueToken(request);
+ }
+
+ private RequestSecurityToken setAppliesTo(String endpointURI, RequestSecurityToken
rst)
+ {
+ if (endpointURI != null)
+ rst.setAppliesTo(WSTrustUtil.createAppliesTo(endpointURI));
+ return rst;
+ }
+
+ private RequestSecurityToken setTokenType(String tokenType, RequestSecurityToken
rst)
+ {
+ if (tokenType != null)
+ rst.setTokenType(URI.create(tokenType));
+ return rst;
+ }
+
+ private Element issueToken(RequestSecurityToken request) throws WSTrustException
+ {
request.setRequestType(URI.create(WSTrustConstants.ISSUE_REQUEST));
request.setContext("context");
-
- // send the token request to JBoss STS and get the response.
WSTrustJAXBFactory jaxbFactory = WSTrustJAXBFactory.getInstance();
DOMSource requestSource = (DOMSource)
jaxbFactory.marshallRequestSecurityToken(request);
Source response = dispatchLocal.get().invoke(requestSource);
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/wstrust/STSClientUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/wstrust/STSClientUnitTestCase.java 2009-09-25
17:41:16 UTC (rev 810)
+++
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/wstrust/STSClientUnitTestCase.java 2009-09-28
08:38:47 UTC (rev 811)
@@ -200,6 +200,28 @@
Element renewedToken = client.renewToken(SAMLUtil.SAML2_TOKEN_TYPE, token);
System.out.println("Renewed Token=" +
DocumentUtil.getNodeAsString(renewedToken));
}
+
+ public void testIssue_Validate_Renew_Using_AppliesTo() throws Exception
+ {
+ if(usetest == false)
+ return;
+
+ Builder stsConfigBuilder = new STSClientConfig.Builder();
+ stsConfigBuilder.serviceName("JBossSTS");
+ stsConfigBuilder.portName("JBossSTSPort");
+
stsConfigBuilder.endpointAddress("http://localhost:8080/jboss-sts/JBossSTS");
+ stsConfigBuilder.username("admin").password("admin");
+ STSClient client = new STSClient(stsConfigBuilder.build());
+
+ // This endpointURI is specified in src/test/resource/jboss-sts.xml
+ String endpointURI = "http://services.testcorp.org/provider2";
+
+ Element token = client.issueTokenForEndpoint(endpointURI);
+ assertTrue("Token is valid" , client.validateToken(token));
+
+ Element renewedToken = client.renewToken(SAMLUtil.SAML2_TOKEN_TYPE, token);
+ System.out.println("Renewed Token=" +
DocumentUtil.getNodeAsString(renewedToken));
+ }
private Dispatch<Source> createDispatch() throws MalformedURLException,
JAXBException