Author: beve
Date: 2009-09-28 15:04:19 -0400 (Mon, 28 Sep 2009)
New Revision: 812
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 re-opened
https://jira.jboss.org/jira/browse/JBID-195 "Add
'AppliesTo' support for WSTrustClient and STSClient"
Re-opened to add an additional method: issueToken(String endpointURI, String tokenType)
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-28
08:38:47 UTC (rev 811)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustClient.java 2009-09-28
19:04:19 UTC (rev 812)
@@ -96,6 +96,23 @@
}
/**
+ * Issues a Security Token from the STS. This methods has the option of
+ * specifying both or one of endpointURI/tokenType but at least one must
+ * specified.
+ *
+ * @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.
+ * @param tokenType - The type of security token to be issued.
+ * @return Element - The Security Token Element issued.
+ * @throws IllegalArgumentException If neither endpointURI nor tokenType was
specified.
+ * @throws WSTrustException
+ */
+ public Element issueToken(String endpointURI, String tokenType) throws
WSTrustException
+ {
+ return stsClient.issueToken(endpointURI, tokenType);
+ }
+
+ /**
* 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.
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-28
08:38:47 UTC (rev 811)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/wstrust/STSClient.java 2009-09-28
19:04:19 UTC (rev 812)
@@ -92,13 +92,36 @@
* for the endpointURI passed in.
* @throws WSTrustException
*/
- public Element issueTokenForEndpoint(final String endpointURI) throws
WSTrustException
+ public Element issueTokenForEndpoint(String endpointURI) throws WSTrustException
{
RequestSecurityToken request = new RequestSecurityToken();
setAppliesTo(endpointURI, request);
return issueToken(request);
}
+ /**
+ * Issues a Security Token from the STS. This methods has the option of
+ * specifying one or both of endpointURI/tokenType but at least one must
+ * specified.
+ *
+ * @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.
+ * @param tokenType - The type of security token to be issued.
+ * @return Element - The Security Token Element issued.
+ * @throws IllegalArgumentException If neither endpointURI nor tokenType was
specified.
+ * @throws WSTrustException
+ */
+ public Element issueToken(String endpointURI, String tokenType) throws
WSTrustException
+ {
+ if (endpointURI == null && tokenType == null)
+ throw new IllegalArgumentException("One of endpointURI or tokenType must
be provided.");
+
+ RequestSecurityToken request = new RequestSecurityToken();
+ setAppliesTo(endpointURI, request);
+ setTokenType(tokenType, request);
+ return issueToken(request);
+ }
+
public Element issueToken(String tokenType) throws WSTrustException
{
// create a custom token request message.
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-28
08:38:47 UTC (rev 811)
+++
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/wstrust/STSClientUnitTestCase.java 2009-09-28
19:04:19 UTC (rev 812)
@@ -222,6 +222,29 @@
Element renewedToken = client.renewToken(SAMLUtil.SAML2_TOKEN_TYPE, token);
System.out.println("Renewed Token=" +
DocumentUtil.getNodeAsString(renewedToken));
}
+
+ public void testIssue_Niehter_AppliesTo_Or_TokenType_Specified()
+ {
+ 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());
+
+ try
+ {
+ client.issueToken(null, null);
+ fail("issueTokenForEndpoint shoud throw an exception if endpointURI and
tokenType are null");
+ }
+ catch(Exception e)
+ {
+ assertTrue("Excpetion was not of type IllegalException", e instanceof
IllegalArgumentException);
+ }
+ }
private Dispatch<Source> createDispatch() throws MalformedURLException,
JAXBException