Got WS-Trust issuing working again
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1e0db84b Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1e0db84b Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1e0db84b Branch: refs/heads/master Commit: 1e0db84b4b732a090e31a59623f806b74b9337da Parents: 4102f1d Author: Colm O hEigeartaigh <[email protected]> Authored: Mon Feb 8 14:42:35 2016 +0000 Committer: Colm O hEigeartaigh <[email protected]> Committed: Mon Feb 8 16:34:01 2016 +0000 ---------------------------------------------------------------------- .../cxf/sts/rest/RESTSecurityTokenService.java | 3 +- .../sts/rest/RESTSecurityTokenServiceImpl.java | 12 +++-- .../cxf/systest/sts/rest/RESTUnitTest.java | 47 ++++++++++---------- 3 files changed, 34 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/1e0db84b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenService.java ---------------------------------------------------------------------- diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenService.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenService.java index 3014da3..3458c4a 100644 --- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenService.java +++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenService.java @@ -56,6 +56,7 @@ public interface RESTSecurityTokenService { /** * @return Issues required token type with default token settings. */ + @GET @Path("{tokenType}") @Produces({ @@ -72,7 +73,7 @@ public interface RESTSecurityTokenService { }) Response getTokenViaWSTrust(@PathParam("tokenType") String tokenType, @QueryParam("keyType") String keyType, @QueryParam("claim") List<String> requestedClaims, @QueryParam("appliesTo") String appliesTo); - + @POST @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON http://git-wip-us.apache.org/repos/asf/cxf/blob/1e0db84b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java index f1291c0..1b39bf7 100644 --- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java +++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java @@ -96,15 +96,21 @@ public class RESTSecurityTokenServiceImpl extends SecurityTokenServiceImpl imple public Response getToken(String tokenType, String keyType, List<String> requestedClaims, String appliesTo) { RequestSecurityTokenResponseType response = issueToken(tokenType, keyType, requestedClaims, appliesTo); - RequestedSecurityTokenType requestedToken = getRequestedSecurityToken(response); return Response.ok(requestedToken.getAny()).build(); } @Override - public Response getTokenViaWSTrust(String tokenType, String keyType, List<String> requestedClaims, String appliesTo) { - return getToken(tokenType, keyType, requestedClaims, appliesTo); + public Response getTokenViaWSTrust(String tokenType, String keyType, + List<String> requestedClaims, String appliesTo) { + RequestSecurityTokenResponseType response = + issueToken(tokenType, keyType, requestedClaims, appliesTo); + + JAXBElement<RequestSecurityTokenResponseType> jaxbResponse = + QNameConstants.WS_TRUST_FACTORY.createRequestSecurityTokenResponse(response); + + return Response.ok(jaxbResponse).build(); } private RequestedSecurityTokenType getRequestedSecurityToken(RequestSecurityTokenResponseType response) { http://git-wip-us.apache.org/repos/asf/cxf/blob/1e0db84b/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/rest/RESTUnitTest.java ---------------------------------------------------------------------- diff --git a/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/rest/RESTUnitTest.java b/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/rest/RESTUnitTest.java index 8ecd2b6..e682911 100644 --- a/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/rest/RESTUnitTest.java +++ b/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/rest/RESTUnitTest.java @@ -55,6 +55,8 @@ import org.junit.BeforeClass; */ public class RESTUnitTest extends AbstractBusClientServerTestBase { + static final String STSPORT = allocatePort(STSRESTServer.class); + private static final String SYMMETRIC_KEY_KEYTYPE = "http://docs.oasis-open.org/ws-sx/ws-trust/200512/SymmetricKey"; private static final String PUBLIC_KEY_KEYTYPE = @@ -64,8 +66,6 @@ public class RESTUnitTest extends AbstractBusClientServerTestBase { private static final String DEFAULT_ADDRESS = "https://localhost:8081/doubleit/services/doubleittransportsaml1"; - static final String STSPORT = allocatePort(STSRESTServer.class); - @BeforeClass public static void startServers() throws Exception { assertTrue( @@ -229,7 +229,7 @@ public class RESTUnitTest extends AbstractBusClientServerTestBase { bus.shutdown(true); } - /* + @org.junit.Test public void testIssueBearerSAML1Token() throws Exception { SpringBusFactory bf = new SpringBusFactory(); @@ -391,28 +391,8 @@ public class RESTUnitTest extends AbstractBusClientServerTestBase { bus.shutdown(true); } -*/ - @org.junit.Test - @org.junit.Ignore - public void testIssueJWTToken() throws Exception { - SpringBusFactory bf = new SpringBusFactory(); - URL busFile = RESTUnitTest.class.getResource("cxf-client.xml"); - - Bus bus = bf.createBus(busFile.toString()); - SpringBusFactory.setDefaultBus(bus); - SpringBusFactory.setThreadDefaultBus(bus); - - String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token"; - WebClient client = WebClient.create(address, "alice", "clarinet", busFile.toString()); - client.type("application/json").accept("application/json"); - client.path("jwt"); - - client.get(); - } - @org.junit.Test - @org.junit.Ignore public void testIssueSAML2TokenViaWSTrust() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = RESTUnitTest.class.getResource("cxf-client.xml"); @@ -421,7 +401,7 @@ public class RESTUnitTest extends AbstractBusClientServerTestBase { SpringBusFactory.setDefaultBus(bus); SpringBusFactory.setThreadDefaultBus(bus); - String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token"; + String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token/ws-trust"; WebClient client = WebClient.create(address, busFile.toString()); client.type("application/xml").accept("application/xml"); @@ -457,6 +437,25 @@ public class RESTUnitTest extends AbstractBusClientServerTestBase { bus.shutdown(true); } + @org.junit.Test + @org.junit.Ignore + public void testIssueJWTToken() throws Exception { + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = RESTUnitTest.class.getResource("cxf-client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token"; + WebClient client = WebClient.create(address, "alice", "clarinet", busFile.toString()); + + client.type("application/json").accept("application/json"); + client.path("jwt"); + + client.get(); + } + private List<WSSecurityEngineResult> processToken(Element assertionElement) throws Exception { RequestData requestData = new RequestData();
