cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1175786 - in /cxf/trunk/services/sts/sts-core/src: main/java/org/apache/cxf/sts/operation/TokenIssueOperation.java test/java/org/apache/cxf/sts/operation/IssueUnitTest.java
Date Mon, 26 Sep 2011 10:53:36 GMT
Author: coheigea
Date: Mon Sep 26 10:53:36 2011
New Revision: 1175786

URL: http://svn.apache.org/viewvc?rev=1175786&view=rev
Log:
Added support to the issue token operation in the STS to issue a single token.

Modified:
    cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenIssueOperation.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueUnitTest.java

Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenIssueOperation.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenIssueOperation.java?rev=1175786&r1=1175785&r2=1175786&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenIssueOperation.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/TokenIssueOperation.java
Mon Sep 26 10:53:36 2011
@@ -52,12 +52,13 @@ import org.apache.cxf.ws.security.sts.pr
 import org.apache.cxf.ws.security.sts.provider.model.RequestedReferenceType;
 import org.apache.cxf.ws.security.sts.provider.model.RequestedSecurityTokenType;
 import org.apache.cxf.ws.security.sts.provider.operation.IssueOperation;
+import org.apache.cxf.ws.security.sts.provider.operation.IssueSingleOperation;
 import org.apache.ws.security.WSSecurityException;
 
 /**
  * An implementation of the IssueOperation interface.
  */
-public class TokenIssueOperation extends AbstractOperation implements IssueOperation {
+public class TokenIssueOperation extends AbstractOperation implements IssueOperation, IssueSingleOperation
{
 
     private static final Logger LOG = LogUtils.getL7dLogger(TokenIssueOperation.class);
 
@@ -71,10 +72,22 @@ public class TokenIssueOperation extends
         this.claimsManager = claimsManager;
     }
         
+    
     public RequestSecurityTokenResponseCollectionType issue(
         RequestSecurityTokenType request,
         WebServiceContext context
     ) {
+        RequestSecurityTokenResponseType response = issueSingle(request, context);
+        RequestSecurityTokenResponseCollectionType responseCollection = 
+            QNameConstants.WS_TRUST_FACTORY.createRequestSecurityTokenResponseCollectionType();
+        responseCollection.getRequestSecurityTokenResponse().add(response);
+        return responseCollection;
+    }
+    
+    public RequestSecurityTokenResponseType issueSingle(
+        RequestSecurityTokenType request,
+        WebServiceContext context
+    ) {
         RequestParser requestParser = parseRequest(request, context);
         
         TokenProviderParameters providerParameters = createTokenProviderParameters(requestParser,
context);
@@ -135,10 +148,7 @@ public class TokenIssueOperation extends
                 createResponse(
                     encryptionProperties, tokenResponse, tokenRequirements, keyRequirements,
context
                 );
-            RequestSecurityTokenResponseCollectionType responseCollection = 
-                QNameConstants.WS_TRUST_FACTORY.createRequestSecurityTokenResponseCollectionType();
-            responseCollection.getRequestSecurityTokenResponse().add(response);
-            return responseCollection;
+            return response;
         } catch (Throwable ex) {
             LOG.log(Level.WARNING, "", ex);
             throw new STSException("Error in creating the response", ex, STSException.REQUEST_FAILED);

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueUnitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueUnitTest.java?rev=1175786&r1=1175785&r2=1175786&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueUnitTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueUnitTest.java
Mon Sep 26 10:53:36 2011
@@ -352,6 +352,47 @@ public class IssueUnitTest extends org.j
         assertTrue(!securityTokenResponse.isEmpty());
     }
     
+    /**
+     * Test to successfully issue a single (dummy) token.
+     */
+    @org.junit.Test
+    public void testIssueSingleToken() throws Exception {
+        TokenIssueOperation issueOperation = new TokenIssueOperation();
+        
+        // Add Token Provider
+        List<TokenProvider> providerList = new ArrayList<TokenProvider>();
+        providerList.add(new DummyTokenProvider());
+        issueOperation.setTokenProviders(providerList);
+        
+        // Add Service
+        ServiceMBean service = new StaticService();
+        service.setEndpoints(Collections.singletonList("http://dummy-service.com/dummy"));
+        issueOperation.setServices(Collections.singletonList(service));
+        
+        // Add STSProperties object
+        STSPropertiesMBean stsProperties = new StaticSTSProperties();
+        issueOperation.setStsProperties(stsProperties);
+        
+        // Mock up a request
+        RequestSecurityTokenType request = new RequestSecurityTokenType();
+        JAXBElement<String> tokenType = 
+            new JAXBElement<String>(
+                QNameConstants.TOKEN_TYPE, String.class, DummyTokenProvider.TOKEN_TYPE
+            );
+        request.getAny().add(tokenType);
+        request.getAny().add(createAppliesToElement("http://dummy-service.com/dummy"));
+        
+        // Mock up message context
+        MessageImpl msg = new MessageImpl();
+        WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
+        WebServiceContextImpl webServiceContext = new WebServiceContextImpl(msgCtx);
+        
+        // Issue a token
+        RequestSecurityTokenResponseType response = 
+            issueOperation.issueSingle(request, webServiceContext);
+        assertTrue(!response.getAny().isEmpty());
+    }
+    
     
     /*
      * Mock up an AppliesTo element using the supplied address



Mime
View raw message