You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2015/12/08 19:06:41 UTC
[1/7] cxf git commit: Minor spelling correction
Repository: cxf
Updated Branches:
refs/heads/3.0.x-fixes 8478e96dd -> ca1d759d9
Minor spelling correction
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d29fa674
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d29fa674
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d29fa674
Branch: refs/heads/3.0.x-fixes
Commit: d29fa6746140cd4702861511896c8f5f3b68a97a
Parents: 8478e96
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Dec 8 10:57:41 2015 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Dec 8 15:37:27 2015 +0000
----------------------------------------------------------------------
.../rs/security/oauth2/provider/AbstractOAuthDataProvider.java | 4 ++--
.../cxf/rs/security/oauth2/provider/OAuthDataProvider.java | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/d29fa674/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
index a17e1c8..11c66da 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
@@ -81,8 +81,8 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider {
@Override
- public List<OAuthPermission> convertScopeToPermissions(Client client, List<String> requestedScope) {
- if (requestedScope.isEmpty()) {
+ public List<OAuthPermission> convertScopeToPermissions(Client client, List<String> requestedScopes) {
+ if (requestedScopes.isEmpty()) {
return Collections.emptyList();
} else {
throw new OAuthServiceException("Requested scopes can not be mapped");
http://git-wip-us.apache.org/repos/asf/cxf/blob/d29fa674/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/OAuthDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/OAuthDataProvider.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/OAuthDataProvider.java
index d2b52e4..8223e9a 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/OAuthDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/OAuthDataProvider.java
@@ -103,9 +103,9 @@ public interface OAuthDataProvider {
/**
* Converts the requested scope to the list of permissions
- * @param requestedScope
+ * @param requestedScopes
* @return list of permissions
*/
List<OAuthPermission> convertScopeToPermissions(Client client,
- List<String> requestedScope);
+ List<String> requestedScopes);
}
[6/7] cxf git commit: Recording .gitmergeinfo Changes
Posted by co...@apache.org.
Recording .gitmergeinfo Changes
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6498f993
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6498f993
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6498f993
Branch: refs/heads/3.0.x-fixes
Commit: 6498f9932dd39a6320d21199cfba191e78ad1d6f
Parents: efbb7f4
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Dec 8 15:38:11 2015 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Dec 8 15:38:11 2015 +0000
----------------------------------------------------------------------
.gitmergeinfo | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/6498f993/.gitmergeinfo
----------------------------------------------------------------------
diff --git a/.gitmergeinfo b/.gitmergeinfo
index 3c89646..c7d7dd0 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -664,6 +664,7 @@ M 5e4a14b4da1f1b27e4df811be80a7f11fc6dae8d
M 5e919271e2e92f9845d6454b37ab0b86cfc66591
M 5e97d1e29e85d80f0679748cc4df0d8e0647ee16
M 5fbe7b49b88deff15f755c15f5a4c421943acc4f
+M 6106f469f5ae311edf2f7de12038822bc03dc073
M 6129ec5f6735a986660a2d05c6b3b0c9230610d9
M 6292346fb110f0517b791f91d03fd2515d575388
M 62d70e977895ae06494730d4f4f04282f0bbeb9e
@@ -677,6 +678,7 @@ M 67f165611178ac59531d774aec8fc2353bd0c8e5
M 6909358dee4beaa00b493b728dd7689331173d2a
M 6b355293a7510afc7a40372e0e4b0265cfc3d0f2
M 6d7ab22d5adcd15bfa3a086345a0b5851fe3e2b2
+M 6d818c6501e8aa16d724e6154fc41e1195c3fccb
M 6d830354143f91f317d9faf24bbbb63c9ceeab44
M 6e3224606ecf56b821dac537241f18a59b44e3e3
M 6fd3ada7af5af1fcb0de337c379e34e7bdb44a56
@@ -798,6 +800,7 @@ M da352523c42bf69ab743f75a5216a03e26a20bef
M daac77b18e2693ef4ad424937aedc764229a63ee
M dbc4a26cd47c2609c601dc3640b655ea0a2b60b9
M dd1b3ebf5b10651a2220a54a1f6e276d2197acf0
+M dfe90b649bee2e7cdd448b16d60b26457385b4e5
M e2225709c37cb289b99db015b3d8ba5b9b317615
M e2ad037fbc74f42655ac968415fcb4bded87bb38
M e3f89d3c07f38f2e01c951d7bad8336e090837ae
[4/7] cxf git commit: Adding SAML + JWT Bearer Grant tests
Posted by co...@apache.org.
Adding SAML + JWT Bearer Grant tests
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d34ba6da
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d34ba6da
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d34ba6da
Branch: refs/heads/3.0.x-fixes
Commit: d34ba6da8912ccad276d9c6432fb5f00b663ecc5
Parents: 3257af6
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Dec 8 15:09:02 2015 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Dec 8 15:38:07 2015 +0000
----------------------------------------------------------------------
.../oauth2/grants/AuthorizationGrantTest.java | 129 +++++++++++++++++++
.../security/oauth2/grants/grants-server.xml | 20 +++
2 files changed, 149 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/d34ba6da/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
index f42c709..5b757f6 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
@@ -21,18 +21,33 @@ package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
+import java.util.Properties;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;
+import org.apache.cxf.common.util.Base64UrlUtility;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.provider.json.JSONProvider;
+import org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm;
+import org.apache.cxf.rs.security.jose.jws.JwsHeaders;
+import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactProducer;
+import org.apache.cxf.rs.security.jose.jws.JwsSignatureProvider;
+import org.apache.cxf.rs.security.jose.jws.JwsUtils;
+import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
import org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData;
import org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider;
+import org.apache.cxf.systest.jaxrs.security.oauth2.SamlCallbackHandler;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.wss4j.common.ext.WSSecurityException;
+import org.apache.wss4j.common.saml.SAMLCallback;
+import org.apache.wss4j.common.saml.SAMLUtil;
+import org.apache.wss4j.common.saml.SamlAssertionWrapper;
import org.junit.BeforeClass;
/**
@@ -253,7 +268,57 @@ public class AuthorizationGrantTest extends AbstractBusClientServerTestBase {
assertNotNull(accessToken.getTokenKey());
assertNotNull(accessToken.getRefreshToken());
}
+
+ @org.junit.Test
+ public void testSAMLAuthorizationGrant() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
+
+ // Create the SAML Assertion
+ String assertion = createToken(address + "token", true);
+
+ // Get Access Token
+ client.type("application/x-www-form-urlencoded").accept("application/json");
+ client.path("token");
+
+ Form form = new Form();
+ form.param("grant_type", "urn:ietf:params:oauth:grant-type:saml2-bearer");
+ form.param("assertion", Base64UrlUtility.encode(assertion));
+ form.param("client_id", "consumer-id");
+ Response response = client.post(form);
+
+ ClientAccessToken accessToken = response.readEntity(ClientAccessToken.class);
+ assertNotNull(accessToken.getTokenKey());
+ assertNotNull(accessToken.getRefreshToken());
+ }
+ @org.junit.Test
+ public void testJWTAuthorizationGrant() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
+
+ // Create the JWT Token
+ String token = createToken("DoubleItSTSIssuer", "consumer-id",
+ "https://localhost:" + PORT + "/services/token", true, true);
+
+ // Get Access Token
+ client.type("application/x-www-form-urlencoded").accept("application/json");
+ client.path("token");
+
+ Form form = new Form();
+ form.param("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");
+ form.param("assertion", token);
+ form.param("client_id", "consumer-id");
+ Response response = client.post(form);
+
+ ClientAccessToken accessToken = response.readEntity(ClientAccessToken.class);
+ assertNotNull(accessToken.getTokenKey());
+ assertNotNull(accessToken.getRefreshToken());
+ }
private String getAuthorizationCode(WebClient client) {
return getAuthorizationCode(client, null);
}
@@ -315,4 +380,68 @@ public class AuthorizationGrantTest extends AbstractBusClientServerTestBase {
return providers;
}
+ private String createToken(String audRestr, boolean sign) throws WSSecurityException {
+ SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true);
+ samlCallbackHandler.setAudience(audRestr);
+
+ SAMLCallback samlCallback = new SAMLCallback();
+ SAMLUtil.doSAMLCallback(samlCallbackHandler, samlCallback);
+
+ SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
+ if (samlCallback.isSignAssertion()) {
+ samlAssertion.signAssertion(
+ samlCallback.getIssuerKeyName(),
+ samlCallback.getIssuerKeyPassword(),
+ samlCallback.getIssuerCrypto(),
+ samlCallback.isSendKeyValue(),
+ samlCallback.getCanonicalizationAlgorithm(),
+ samlCallback.getSignatureAlgorithm()
+ );
+ }
+
+ return samlAssertion.assertionToString();
+ }
+
+ private String createToken(String issuer, String subject, String audience,
+ boolean expiry, boolean sign) {
+ // Create the JWT Token
+ JwtClaims claims = new JwtClaims();
+ claims.setSubject(subject);
+ if (issuer != null) {
+ claims.setIssuer(issuer);
+ }
+ claims.setIssuedAt(new Date().getTime() / 1000L);
+ if (expiry) {
+ Calendar cal = Calendar.getInstance();
+ cal.add(Calendar.SECOND, 60);
+ claims.setExpiryTime(cal.getTimeInMillis() / 1000L);
+ }
+ if (audience != null) {
+ claims.setAudiences(Collections.singletonList(audience));
+ }
+
+ if (sign) {
+ // Sign the JWT Token
+ Properties signingProperties = new Properties();
+ signingProperties.put("rs.security.keystore.type", "jks");
+ signingProperties.put("rs.security.keystore.password", "password");
+ signingProperties.put("rs.security.keystore.alias", "alice");
+ signingProperties.put("rs.security.keystore.file",
+ "org/apache/cxf/systest/jaxrs/security/certs/alice.jks");
+ signingProperties.put("rs.security.key.password", "password");
+ signingProperties.put("rs.security.signature.algorithm", "RS256");
+
+ JwsHeaders jwsHeaders = new JwsHeaders(signingProperties);
+ JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwsHeaders, claims);
+
+ JwsSignatureProvider sigProvider =
+ JwsUtils.loadSignatureProvider(signingProperties, jwsHeaders);
+
+ return jws.signWith(sigProvider);
+ }
+
+ JwsHeaders jwsHeaders = new JwsHeaders(SignatureAlgorithm.NONE);
+ JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwsHeaders, claims);
+ return jws.getSignedEncodedJws();
+ }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/d34ba6da/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
index 74a8fcd..3ef86fb 100644
--- a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
+++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
@@ -89,6 +89,14 @@ under the License.
<property name="dataProvider" ref="oauthProvider"/>
</bean>
+ <bean id="samlGrantHandler" class="org.apache.cxf.rs.security.oauth2.grants.saml.Saml2BearerGrantHandler">
+ <property name="dataProvider" ref="oauthProvider"/>
+ </bean>
+
+ <bean id="jwtGrantHandler" class="org.apache.cxf.rs.security.oauth2.grants.jwt.JwtBearerGrantHandler">
+ <property name="dataProvider" ref="oauthProvider"/>
+ </bean>
+
<bean id="tokenService" class="org.apache.cxf.rs.security.oauth2.services.AccessTokenService">
<property name="dataProvider" ref="oauthProvider"/>
<property name="grantHandlers">
@@ -96,6 +104,8 @@ under the License.
<ref bean="refreshGrantHandler"/>
<ref bean="passwordGrantHandler"/>
<ref bean="clientCredsGrantHandler"/>
+ <ref bean="samlGrantHandler"/>
+ <ref bean="jwtGrantHandler"/>
</list>
</property>
</bean>
@@ -116,6 +126,16 @@ under the License.
<jaxrs:providers>
<ref bean="basicAuthFilter"/>
</jaxrs:providers>
+ <jaxrs:properties>
+ <entry key="security.signature.properties"
+ value="org/apache/cxf/systest/jaxrs/security/bob.properties"/>
+ <entry key="rs.security.keystore.type" value="jks" />
+ <entry key="rs.security.keystore.alias" value="alice"/>
+ <entry key="rs.security.keystore.password" value="password"/>
+ <entry key="rs.security.keystore.file"
+ value="org/apache/cxf/systest/jaxrs/security/certs/alice.jks" />
+ <entry key="rs.security.signature.algorithm" value="RS256" />
+ </jaxrs:properties>
</jaxrs:server>
[3/7] cxf git commit: Adding OAuth authorization grant tests
Posted by co...@apache.org.
Adding OAuth authorization grant tests
# Conflicts:
# systests/rs-security/pom.xml
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3257af6d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3257af6d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3257af6d
Branch: refs/heads/3.0.x-fixes
Commit: 3257af6daf254d7ba19344bfa7ef9f517454cbd5
Parents: 6453dec
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Dec 8 13:08:25 2015 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Dec 8 15:38:05 2015 +0000
----------------------------------------------------------------------
systests/rs-security/pom.xml | 4 +-
.../oauth2/grants/AuthorizationGrantTest.java | 318 +++++++++++++++++++
.../security/oauth2/grants/BasicAuthFilter.java | 117 +++++++
.../oauth2/grants/BookServerOAuth2Grants.java | 48 +++
.../oauth2/grants/CallbackHandlerImpl.java | 52 +++
.../grants/CallbackHandlerLoginHandler.java | 83 +++++
.../oauth2/grants/OAuthDataProviderImpl.java | 101 ++++++
.../jaxrs/security/oauth2/grants/client.xml | 38 +++
.../security/oauth2/grants/grants-server.xml | 122 +++++++
9 files changed, 882 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/pom.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/pom.xml b/systests/rs-security/pom.xml
index b17040d..8c252bb 100644
--- a/systests/rs-security/pom.xml
+++ b/systests/rs-security/pom.xml
@@ -40,6 +40,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
+<<<<<<< HEAD
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
@@ -49,6 +50,8 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
+=======
+>>>>>>> 6106f46... Adding OAuth authorization grant tests
<artifactId>jetty-webapp</artifactId>
</dependency>
<dependency>
@@ -201,7 +204,6 @@
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
- <version>2.4.1</version>
</dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
new file mode 100644
index 0000000..f42c709
--- /dev/null
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
@@ -0,0 +1,318 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.provider.json.JSONProvider;
+import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
+import org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData;
+import org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.junit.BeforeClass;
+
+/**
+ * Some tests for various authorization grants.
+ */
+public class AuthorizationGrantTest extends AbstractBusClientServerTestBase {
+ public static final String PORT = BookServerOAuth2Grants.PORT;
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ assertTrue("server did not launch correctly",
+ launchServer(BookServerOAuth2Grants.class, true));
+ }
+
+ @org.junit.Test
+ public void testAuthorizationCodeGrant() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ // Get Authorization Code
+ String code = getAuthorizationCode(client);
+ assertNotNull(code);
+
+ // Now get the access token
+ client = WebClient.create(address, setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ ClientAccessToken accessToken = getAccessTokenWithAuthorizationCode(client, code);
+ assertNotNull(accessToken.getTokenKey());
+ }
+
+ @org.junit.Test
+ public void testAuthorizationCodeGrantRefresh() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ // Get Authorization Code
+ String code = getAuthorizationCode(client);
+ assertNotNull(code);
+
+ // Now get the access token
+ client = WebClient.create(address, setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ ClientAccessToken accessToken = getAccessTokenWithAuthorizationCode(client, code);
+ assertNotNull(accessToken.getTokenKey());
+ assertNotNull(accessToken.getRefreshToken());
+
+ // Refresh the access token
+ client.type("application/x-www-form-urlencoded").accept("application/json");
+
+ Form form = new Form();
+ form.param("grant_type", "refresh_token");
+ form.param("refresh_token", accessToken.getRefreshToken());
+ form.param("client_id", "consumer-id");
+ Response response = client.post(form);
+
+ accessToken = response.readEntity(ClientAccessToken.class);
+ assertNotNull(accessToken.getTokenKey());
+ assertNotNull(accessToken.getRefreshToken());
+ }
+
+ @org.junit.Test
+ public void testAuthorizationCodeGrantRefreshWithScope() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ // Get Authorization Code
+ String code = getAuthorizationCode(client, "read_balance");
+ assertNotNull(code);
+
+ // Now get the access token
+ client = WebClient.create(address, setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ ClientAccessToken accessToken = getAccessTokenWithAuthorizationCode(client, code);
+ assertNotNull(accessToken.getTokenKey());
+ assertNotNull(accessToken.getRefreshToken());
+
+ // Refresh the access token
+ client.type("application/x-www-form-urlencoded").accept("application/json");
+
+ Form form = new Form();
+ form.param("grant_type", "refresh_token");
+ form.param("refresh_token", accessToken.getRefreshToken());
+ form.param("client_id", "consumer-id");
+ form.param("scope", "read_balance");
+ Response response = client.post(form);
+
+ accessToken = response.readEntity(ClientAccessToken.class);
+ assertNotNull(accessToken.getTokenKey());
+ assertNotNull(accessToken.getRefreshToken());
+ }
+
+ @org.junit.Test
+ public void testAuthorizationCodeGrantWithScope() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ // Get Authorization Code
+ String code = getAuthorizationCode(client, "read_balance");
+ assertNotNull(code);
+
+ // Now get the access token
+ client = WebClient.create(address, setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ ClientAccessToken accessToken = getAccessTokenWithAuthorizationCode(client, code);
+ assertNotNull(accessToken.getTokenKey());
+ }
+
+ @org.junit.Test
+ public void testImplicitGrant() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
+ // Save the Cookie for the second request...
+ WebClient.getConfig(client).getRequestContext().put(
+ org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+
+ // Get Access Token
+ client.type("application/json").accept("application/json");
+ client.query("client_id", "consumer-id");
+ client.query("redirect_uri", "http://www.blah.apache.org");
+ client.query("response_type", "token");
+ client.path("authorize-implicit/");
+ Response response = client.get();
+
+ OAuthAuthorizationData authzData = response.readEntity(OAuthAuthorizationData.class);
+
+ // Now call "decision" to get the access token
+ client.path("decision");
+ client.type("application/x-www-form-urlencoded");
+
+ Form form = new Form();
+ form.param("session_authenticity_token", authzData.getAuthenticityToken());
+ form.param("client_id", authzData.getClientId());
+ form.param("redirect_uri", authzData.getRedirectUri());
+ form.param("oauthDecision", "allow");
+
+ response = client.post(form);
+
+ String location = response.getHeaderString("Location");
+ String accessToken = location.substring(location.indexOf("access_token=") + "access_token=".length());
+ accessToken = accessToken.substring(0, accessToken.indexOf('&'));
+ assertNotNull(accessToken);
+ }
+
+ @org.junit.Test
+ public void testPasswordsCredentialsGrant() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "consumer-id",
+ "this-is-a-secret", busFile.toString());
+
+ // Get Access Token
+ client.type("application/x-www-form-urlencoded").accept("application/json");
+ client.path("token");
+
+ Form form = new Form();
+ form.param("grant_type", "password");
+ form.param("username", "alice");
+ form.param("password", "security");
+ Response response = client.post(form);
+
+ ClientAccessToken accessToken = response.readEntity(ClientAccessToken.class);
+ assertNotNull(accessToken.getTokenKey());
+ assertNotNull(accessToken.getRefreshToken());
+ }
+
+ @org.junit.Test
+ public void testClientCredentialsGrant() throws Exception {
+ URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
+
+ String address = "https://localhost:" + PORT + "/services/";
+ WebClient client = WebClient.create(address, setupProviders(), "consumer-id",
+ "this-is-a-secret", busFile.toString());
+
+ // Get Access Token
+ client.type("application/x-www-form-urlencoded").accept("application/json");
+ client.path("token");
+
+ Form form = new Form();
+ form.param("grant_type", "client_credentials");
+ Response response = client.post(form);
+
+ ClientAccessToken accessToken = response.readEntity(ClientAccessToken.class);
+ assertNotNull(accessToken.getTokenKey());
+ assertNotNull(accessToken.getRefreshToken());
+ }
+
+ private String getAuthorizationCode(WebClient client) {
+ return getAuthorizationCode(client, null);
+ }
+
+ private String getAuthorizationCode(WebClient client, String scope) {
+ // Make initial authorization request
+ client.type("application/json").accept("application/json");
+ client.query("client_id", "consumer-id");
+ client.query("redirect_uri", "http://www.blah.apache.org");
+ client.query("response_type", "code");
+ if (scope != null) {
+ client.query("scope", scope);
+ }
+ client.path("authorize/");
+ Response response = client.get();
+
+ OAuthAuthorizationData authzData = response.readEntity(OAuthAuthorizationData.class);
+
+ // Now call "decision" to get the authorization code grant
+ client.path("decision");
+ client.type("application/x-www-form-urlencoded");
+
+ Form form = new Form();
+ form.param("session_authenticity_token", authzData.getAuthenticityToken());
+ form.param("client_id", authzData.getClientId());
+ form.param("redirect_uri", authzData.getRedirectUri());
+ if (authzData.getProposedScope() != null) {
+ form.param("scope", authzData.getProposedScope());
+ }
+ form.param("oauthDecision", "allow");
+
+ response = client.post(form);
+ String location = response.getHeaderString("Location");
+ return location.substring(location.indexOf("code=") + "code=".length());
+ }
+
+ private ClientAccessToken getAccessTokenWithAuthorizationCode(WebClient client, String code) {
+ client.type("application/x-www-form-urlencoded").accept("application/json");
+ client.path("token");
+
+ Form form = new Form();
+ form.param("grant_type", "authorization_code");
+ form.param("code", code);
+ form.param("client_id", "consumer-id");
+ Response response = client.post(form);
+
+ return response.readEntity(ClientAccessToken.class);
+ }
+
+ private List<Object> setupProviders() {
+ List<Object> providers = new ArrayList<Object>();
+ JSONProvider<OAuthAuthorizationData> jsonP = new JSONProvider<OAuthAuthorizationData>();
+ jsonP.setNamespaceMap(Collections.singletonMap("http://org.apache.cxf.rs.security.oauth",
+ "ns2"));
+ providers.add(jsonP);
+ OAuthJSONProvider oauthProvider = new OAuthJSONProvider();
+ providers.add(oauthProvider);
+
+ return providers;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/BasicAuthFilter.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/BasicAuthFilter.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/BasicAuthFilter.java
new file mode 100644
index 0000000..db8fe4f
--- /dev/null
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/BasicAuthFilter.java
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
+
+import java.io.IOException;
+import java.security.Principal;
+
+import javax.security.auth.callback.CallbackHandler;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.core.Response;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.security.SecurityContext;
+import org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl;
+import org.apache.wss4j.dom.WSConstants;
+import org.apache.wss4j.dom.handler.RequestData;
+import org.apache.wss4j.dom.message.token.UsernameToken;
+import org.apache.wss4j.dom.validate.Credential;
+import org.apache.wss4j.dom.validate.UsernameTokenValidator;
+
+/**
+ * A simple filter to validate a Basic Auth username/password via a CallbackHandler
+ */
+public class BasicAuthFilter implements ContainerRequestFilter {
+
+ private CallbackHandler callbackHandler;
+
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ Message message = JAXRSUtils.getCurrentMessage();
+ AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
+
+ if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
+ requestContext.abortWith(
+ Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build());
+ }
+
+ try {
+ UsernameToken token = convertPolicyToToken(policy);
+ Credential credential = new Credential();
+ credential.setUsernametoken(token);
+
+ RequestData data = new RequestData();
+ data.setMsgContext(message);
+ data.setCallbackHandler(callbackHandler);
+ UsernameTokenValidator validator = new UsernameTokenValidator();
+ credential = validator.validate(credential, data);
+
+ // Create a Principal/SecurityContext
+ Principal p = null;
+ if (credential != null && credential.getPrincipal() != null) {
+ p = credential.getPrincipal();
+ } else {
+ p = new WSUsernameTokenPrincipalImpl(policy.getUserName(), false);
+ ((WSUsernameTokenPrincipalImpl)p).setPassword(policy.getPassword());
+ }
+ message.put(SecurityContext.class, createSecurityContext(p));
+ } catch (Exception ex) {
+ throw ExceptionUtils.toInternalServerErrorException(ex, null);
+ }
+ }
+
+ protected UsernameToken convertPolicyToToken(AuthorizationPolicy policy)
+ throws Exception {
+
+ Document doc = DOMUtils.createDocument();
+ UsernameToken token = new UsernameToken(false, doc,
+ WSConstants.PASSWORD_TEXT);
+ token.setName(policy.getUserName());
+ token.setPassword(policy.getPassword());
+ return token;
+ }
+
+ protected SecurityContext createSecurityContext(final Principal p) {
+ return new SecurityContext() {
+
+ public Principal getUserPrincipal() {
+ return p;
+ }
+
+ public boolean isUserInRole(String arg0) {
+ return false;
+ }
+ };
+ }
+
+ public CallbackHandler getCallbackHandler() {
+ return callbackHandler;
+ }
+
+ public void setCallbackHandler(CallbackHandler callbackHandler) {
+ this.callbackHandler = callbackHandler;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/BookServerOAuth2Grants.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/BookServerOAuth2Grants.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/BookServerOAuth2Grants.java
new file mode 100644
index 0000000..7ae175f
--- /dev/null
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/BookServerOAuth2Grants.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
+
+import java.net.URL;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.testutil.common.TestUtil;
+
+public class BookServerOAuth2Grants extends AbstractBusTestServerBase {
+ public static final String PORT = TestUtil.getPortNumber("jaxrs-oauth2-grants");
+ private static final URL SERVER_CONFIG_FILE =
+ BookServerOAuth2Grants.class.getResource("grants-server.xml");
+
+ protected void run() {
+ SpringBusFactory bf = new SpringBusFactory();
+ Bus springBus = bf.createBus(SERVER_CONFIG_FILE);
+ BusFactory.setDefaultBus(springBus);
+ setBus(springBus);
+
+ try {
+ new BookServerOAuth2Grants();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerImpl.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerImpl.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerImpl.java
new file mode 100644
index 0000000..12c8658
--- /dev/null
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerImpl.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.apache.wss4j.common.ext.WSPasswordCallback;
+
+public class CallbackHandlerImpl implements CallbackHandler {
+
+ public void handle(Callback[] callbacks) throws IOException,
+ UnsupportedCallbackException {
+ for (int i = 0; i < callbacks.length; i++) {
+ if (callbacks[i] instanceof WSPasswordCallback) { // CXF
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
+ if ("alice".equals(pc.getIdentifier())) {
+ pc.setPassword("security");
+ break;
+ } else if ("bob".equals(pc.getIdentifier())) {
+ pc.setPassword("security");
+ break;
+ } else if ("consumer-id".equals(pc.getIdentifier())) {
+ pc.setPassword("this-is-a-secret");
+ break;
+ } else if ("service".equals(pc.getIdentifier())) {
+ pc.setPassword("service-pass");
+ break;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
new file mode 100644
index 0000000..0442d68
--- /dev/null
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
+
+import javax.security.auth.callback.CallbackHandler;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.rs.security.oauth2.common.UserSubject;
+import org.apache.cxf.rs.security.oauth2.grants.owner.ResourceOwnerLoginHandler;
+import org.apache.wss4j.dom.WSConstants;
+import org.apache.wss4j.dom.engine.WSSConfig;
+import org.apache.wss4j.dom.handler.RequestData;
+import org.apache.wss4j.dom.message.token.UsernameToken;
+import org.apache.wss4j.dom.validate.Credential;
+import org.apache.wss4j.dom.validate.UsernameTokenValidator;
+
+/**
+ * A simple ResourceOwnerLoginHandler implementation that delegates the username/password to a CallbackHandler
+ */
+public class CallbackHandlerLoginHandler implements ResourceOwnerLoginHandler {
+
+ private CallbackHandler callbackHandler;
+
+ static {
+ WSSConfig.init();
+ }
+
+ @Override
+ public UserSubject createSubject(String user, String pass) {
+ Document doc = DOMUtils.createDocument();
+ UsernameToken token = new UsernameToken(false, doc,
+ WSConstants.PASSWORD_TEXT);
+ token.setName(user);
+ token.setPassword(pass);
+
+ Credential credential = new Credential();
+ credential.setUsernametoken(token);
+
+ RequestData data = new RequestData();
+ data.setMsgContext(PhaseInterceptorChain.getCurrentMessage());
+ data.setCallbackHandler(callbackHandler);
+ UsernameTokenValidator validator = new UsernameTokenValidator();
+
+ try {
+ credential = validator.validate(credential, data);
+
+ UserSubject subject = new UserSubject();
+ subject.setLogin(user);
+ return subject;
+ } catch (Exception ex) {
+ throw ExceptionUtils.toInternalServerErrorException(ex, null);
+ }
+ }
+
+ public CallbackHandler getCallbackHandler() {
+ return callbackHandler;
+ }
+
+ public void setCallbackHandler(CallbackHandler callbackHandler) {
+ this.callbackHandler = callbackHandler;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java
new file mode 100644
index 0000000..0ae9708
--- /dev/null
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.cxf.rs.security.oauth2.common.Client;
+import org.apache.cxf.rs.security.oauth2.common.OAuthPermission;
+import org.apache.cxf.rs.security.oauth2.grants.code.DefaultEHCacheCodeDataProvider;
+import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException;
+
+/**
+ * Extend the DefaultEHCacheCodeDataProvider to allow refreshing of tokens
+ */
+public class OAuthDataProviderImpl extends DefaultEHCacheCodeDataProvider {
+
+ public OAuthDataProviderImpl() {
+ Client client = new Client("consumer-id", "this-is-a-secret", true);
+ client.setRedirectUris(Collections.singletonList("http://www.blah.apache.org"));
+
+ client.getAllowedGrantTypes().add("authorization_code");
+ client.getAllowedGrantTypes().add("refresh_token");
+ client.getAllowedGrantTypes().add("implicit");
+ client.getAllowedGrantTypes().add("password");
+ client.getAllowedGrantTypes().add("client_credentials");
+ client.getAllowedGrantTypes().add("urn:ietf:params:oauth:grant-type:saml2-bearer");
+ client.getAllowedGrantTypes().add("urn:ietf:params:oauth:grant-type:jwt-bearer");
+
+ client.getRegisteredScopes().add("read_balance");
+ client.getRegisteredScopes().add("create_balance");
+ client.getRegisteredScopes().add("read_data");
+
+ this.setClient(client);
+ }
+
+ @Override
+ protected boolean isRefreshTokenSupported(List<String> theScopes) {
+ return true;
+ }
+
+ @Override
+ public List<OAuthPermission> convertScopeToPermissions(Client client, List<String> requestedScopes) {
+ if (requestedScopes.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ List<OAuthPermission> permissions = new ArrayList<>();
+ for (String requestedScope : requestedScopes) {
+ if ("read_balance".equals(requestedScope)) {
+ OAuthPermission permission = new OAuthPermission();
+ permission.setHttpVerbs(Collections.singletonList("GET"));
+ List<String> uris = new ArrayList<>();
+ String partnerAddress = "/partners/balance/*";
+ uris.add(partnerAddress);
+ permission.setUris(uris);
+
+ permissions.add(permission);
+ } else if ("create_balance".equals(requestedScope)) {
+ OAuthPermission permission = new OAuthPermission();
+ permission.setHttpVerbs(Collections.singletonList("POST"));
+ List<String> uris = new ArrayList<>();
+ String partnerAddress = "/partners/balance/*";
+ uris.add(partnerAddress);
+ permission.setUris(uris);
+
+ permissions.add(permission);
+ } else if ("read_data".equals(requestedScope)) {
+ OAuthPermission permission = new OAuthPermission();
+ permission.setHttpVerbs(Collections.singletonList("GET"));
+ List<String> uris = new ArrayList<>();
+ String partnerAddress = "/partners/data/*";
+ uris.add(partnerAddress);
+ permission.setUris(uris);
+
+ permissions.add(permission);
+ } else {
+ throw new OAuthServiceException("invalid_scope");
+ }
+ }
+
+ return permissions;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/client.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/client.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/client.xml
new file mode 100644
index 0000000..13eaea1
--- /dev/null
+++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/client.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core" xmlns:p="http://cxf.apache.org/policy" xmlns:sec="http://cxf.apache.org/configuration/security" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/policy http://cxf.apache.org/schemas/poli
cy.xsd">
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+ <cxf:bus>
+ <cxf:features>
+ <cxf:logging/>
+ </cxf:features>
+ </cxf:bus>
+ <http:conduit name="https://localhost.*">
+ <http:client ConnectionTimeout="3000000" ReceiveTimeout="3000000"/>
+ <http:tlsClientParameters disableCNCheck="true">
+ <sec:keyManagers keyPassword="password">
+ <sec:keyStore type="JKS" password="password" file="src/test/java/org/apache/cxf/systest/http/resources/Morpit.jks"/>
+ </sec:keyManagers>
+ <sec:trustManagers>
+ <sec:keyStore type="JKS" password="password" file="src/test/java/org/apache/cxf/systest/http/resources/Truststore.jks"/>
+ </sec:trustManagers>
+ </http:tlsClientParameters>
+ </http:conduit>
+</beans>
http://git-wip-us.apache.org/repos/asf/cxf/blob/3257af6d/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
new file mode 100644
index 0000000..74a8fcd
--- /dev/null
+++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:http="http://cxf.apache.org/transports/http/configuration"
+ xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
+ xmlns:sec="http://cxf.apache.org/configuration/security"
+ xmlns:cxf="http://cxf.apache.org/core"
+ xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
+ http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
+ http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
+ http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd
+ http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd">
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+ <cxf:bus>
+ <cxf:features>
+ <cxf:logging/>
+ </cxf:features>
+ <cxf:properties>
+ <entry key="org.apache.cxf.jaxrs.bus.providers" value-ref="busProviders"/>
+ </cxf:properties>
+ </cxf:bus>
+ <!-- providers -->
+ <util:list id="busProviders">
+ <ref bean="oauthJson"/>
+ </util:list>
+ <bean id="oauthJson" class="org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider"/>
+
+ <httpj:engine-factory id="tls-config">
+ <httpj:engine port="${testutil.ports.jaxrs-oauth2-grants}">
+ <httpj:tlsServerParameters>
+ <sec:keyManagers keyPassword="password">
+ <sec:keyStore type="JKS" password="password" file="src/test/java/org/apache/cxf/systest/http/resources/Bethal.jks"/>
+ </sec:keyManagers>
+ <sec:trustManagers>
+ <sec:keyStore type="JKS" password="password" file="src/test/java/org/apache/cxf/systest/http/resources/Truststore.jks"/>
+ </sec:trustManagers>
+ <sec:clientAuthentication want="true" required="true"/>
+ </httpj:tlsServerParameters>
+ <httpj:sessionSupport>true</httpj:sessionSupport>
+ </httpj:engine>
+ </httpj:engine-factory>
+
+ <bean id="oauthProvider" class="org.apache.cxf.systest.jaxrs.security.oauth2.grants.OAuthDataProviderImpl" />
+
+ <bean id="authorizationService" class="org.apache.cxf.rs.security.oauth2.services.AuthorizationCodeGrantService">
+ <property name="dataProvider" ref="oauthProvider"/>
+ </bean>
+
+ <bean id="implicitService" class="org.apache.cxf.rs.security.oauth2.services.ImplicitGrantService">
+ <property name="dataProvider" ref="oauthProvider"/>
+ </bean>
+
+ <bean id="refreshGrantHandler" class="org.apache.cxf.rs.security.oauth2.grants.refresh.RefreshTokenGrantHandler">
+ <property name="dataProvider" ref="oauthProvider"/>
+ </bean>
+
+ <bean id="callbackHandlerLoginHandler" class="org.apache.cxf.systest.jaxrs.security.oauth2.grants.CallbackHandlerLoginHandler">
+ <property name="callbackHandler" ref="callbackHandler"/>
+ </bean>
+
+ <bean id="passwordGrantHandler" class="org.apache.cxf.rs.security.oauth2.grants.owner.ResourceOwnerGrantHandler">
+ <property name="dataProvider" ref="oauthProvider"/>
+ <property name="loginHandler" ref="callbackHandlerLoginHandler"/>
+ </bean>
+
+ <bean id="clientCredsGrantHandler" class="org.apache.cxf.rs.security.oauth2.grants.clientcred.ClientCredentialsGrantHandler">
+ <property name="dataProvider" ref="oauthProvider"/>
+ </bean>
+
+ <bean id="tokenService" class="org.apache.cxf.rs.security.oauth2.services.AccessTokenService">
+ <property name="dataProvider" ref="oauthProvider"/>
+ <property name="grantHandlers">
+ <list>
+ <ref bean="refreshGrantHandler"/>
+ <ref bean="passwordGrantHandler"/>
+ <ref bean="clientCredsGrantHandler"/>
+ </list>
+ </property>
+ </bean>
+
+ <bean id="callbackHandler" class="org.apache.cxf.systest.jaxrs.security.oauth2.grants.CallbackHandlerImpl"/>
+ <bean id="basicAuthFilter" class="org.apache.cxf.systest.jaxrs.security.oauth2.grants.BasicAuthFilter">
+ <property name="callbackHandler" ref="callbackHandler"/>
+ </bean>
+
+ <jaxrs:server
+ depends-on="tls-config"
+ address="https://localhost:${testutil.ports.jaxrs-oauth2-grants}/services">
+ <jaxrs:serviceBeans>
+ <ref bean="authorizationService"/>
+ <ref bean="implicitService"/>
+ <ref bean="tokenService"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <ref bean="basicAuthFilter"/>
+ </jaxrs:providers>
+ </jaxrs:server>
+
+
+</beans>
[5/7] cxf git commit: Adding JWT Grant + Authn tests
Posted by co...@apache.org.
Adding JWT Grant + Authn tests
# Conflicts:
# systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/efbb7f47
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/efbb7f47
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/efbb7f47
Branch: refs/heads/3.0.x-fixes
Commit: efbb7f47d0ee6f72db8c23b2781c577a33dea46c
Parents: d34ba6d
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Dec 8 15:21:52 2015 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Dec 8 15:38:11 2015 +0000
----------------------------------------------------------------------
.../jaxrs/security/oauth2/JAXRSOAuth2Test.java | 89 ++++++++++++++++++++
.../security/oauth2/OAuthDataProviderImpl.java | 1 +
.../systest/jaxrs/security/oauth2/server.xml | 33 ++++++++
3 files changed, 123 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/efbb7f47/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
index 04faa05..6558d87 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
@@ -20,8 +20,12 @@
package org.apache.cxf.systest.jaxrs.security.oauth2;
import java.net.URL;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -33,10 +37,17 @@ import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.rs.security.common.CryptoLoader;
+import org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm;
+import org.apache.cxf.rs.security.jose.jws.JwsHeaders;
+import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactProducer;
+import org.apache.cxf.rs.security.jose.jws.JwsSignatureProvider;
+import org.apache.cxf.rs.security.jose.jws.JwsUtils;
+import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
import org.apache.cxf.rs.security.oauth2.auth.saml.Saml2BearerAuthOutInterceptor;
import org.apache.cxf.rs.security.oauth2.client.OAuthClientUtils;
import org.apache.cxf.rs.security.oauth2.common.AccessTokenGrant;
import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
+import org.apache.cxf.rs.security.oauth2.grants.jwt.JwtBearerGrant;
import org.apache.cxf.rs.security.oauth2.grants.saml.Saml2BearerGrant;
import org.apache.cxf.rs.security.oauth2.saml.Constants;
import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants;
@@ -140,6 +151,41 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
assertNotNull(at.getTokenKey());
}
+ @Test
+ public void testJWTBearerGrant() throws Exception {
+ String address = "https://localhost:" + PORT + "/oauth2/token";
+ WebClient wc = createWebClient(address);
+
+ // Create the JWT Token
+ String token = createToken("resourceOwner", "alice", address, true, true);
+
+ JwtBearerGrant grant = new JwtBearerGrant(token);
+ ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
+ new Consumer("alice", "alice"),
+ grant,
+ false);
+ assertNotNull(at.getTokenKey());
+ }
+
+ @Test
+ public void testJWTBearerAuthenticationDirect() throws Exception {
+ String address = "https://localhost:" + PORT + "/oauth2-auth-jwt/token";
+ WebClient wc = createWebClient(address);
+
+ // Create the JWT Token
+ String token = createToken("resourceOwner", "alice", address, true, true);
+
+ Map<String, String> extraParams = new HashMap<String, String>();
+ extraParams.put(Constants.CLIENT_AUTH_ASSERTION_TYPE,
+ "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
+ extraParams.put(Constants.CLIENT_AUTH_ASSERTION_PARAM, token);
+
+ ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
+ new CustomGrant(),
+ extraParams);
+ assertNotNull(at.getTokenKey());
+ }
+
private WebClient createWebClient(String address) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
@@ -191,6 +237,49 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
return wc;
}
+ private String createToken(String issuer, String subject, String audience,
+ boolean expiry, boolean sign) {
+ // Create the JWT Token
+ JwtClaims claims = new JwtClaims();
+ claims.setSubject(subject);
+ if (issuer != null) {
+ claims.setIssuer(issuer);
+ }
+ claims.setIssuedAt(new Date().getTime() / 1000L);
+ if (expiry) {
+ Calendar cal = Calendar.getInstance();
+ cal.add(Calendar.SECOND, 60);
+ claims.setExpiryTime(cal.getTimeInMillis() / 1000L);
+ }
+ if (audience != null) {
+ claims.setAudiences(Collections.singletonList(audience));
+ }
+
+ if (sign) {
+ // Sign the JWT Token
+ Properties signingProperties = new Properties();
+ signingProperties.put("rs.security.keystore.type", "jks");
+ signingProperties.put("rs.security.keystore.password", "password");
+ signingProperties.put("rs.security.keystore.alias", "alice");
+ signingProperties.put("rs.security.keystore.file",
+ "org/apache/cxf/systest/jaxrs/security/certs/alice.jks");
+ signingProperties.put("rs.security.key.password", "password");
+ signingProperties.put("rs.security.signature.algorithm", "RS256");
+
+ JwsHeaders jwsHeaders = new JwsHeaders(signingProperties);
+ JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwsHeaders, claims);
+
+ JwsSignatureProvider sigProvider =
+ JwsUtils.loadSignatureProvider(signingProperties, jwsHeaders);
+
+ return jws.signWith(sigProvider);
+ }
+
+ JwsHeaders jwsHeaders = new JwsHeaders(SignatureAlgorithm.NONE);
+ JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwsHeaders, claims);
+ return jws.getSignedEncodedJws();
+ }
+
private static class CustomGrant implements AccessTokenGrant {
private static final long serialVersionUID = -4007538779198315873L;
http://git-wip-us.apache.org/repos/asf/cxf/blob/efbb7f47/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/OAuthDataProviderImpl.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/OAuthDataProviderImpl.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/OAuthDataProviderImpl.java
index ce89320..b1472e5 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/OAuthDataProviderImpl.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/OAuthDataProviderImpl.java
@@ -45,6 +45,7 @@ public class OAuthDataProviderImpl implements OAuthDataProvider {
public OAuthDataProviderImpl() throws Exception {
Client client = new Client("alice", "alice", true);
client.getAllowedGrantTypes().add(Constants.SAML2_BEARER_GRANT);
+ client.getAllowedGrantTypes().add("urn:ietf:params:oauth:grant-type:jwt-bearer");
client.getAllowedGrantTypes().add("custom_grant");
clients.put(client.getClientId(), client);
http://git-wip-us.apache.org/repos/asf/cxf/blob/efbb7f47/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
index f3f6fbe..fa196b9 100644
--- a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
+++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
@@ -62,7 +62,13 @@ under the License.
<bean id="samlGrantHandler" class="org.apache.cxf.rs.security.oauth2.grants.saml.Saml2BearerGrantHandler">
<property name="dataProvider" ref="dataProvider"/>
</bean>
+ <bean id="jwtGrantHandler" class="org.apache.cxf.rs.security.oauth2.grants.jwt.JwtBearerGrantHandler">
+ <property name="dataProvider" ref="dataProvider"/>
+ </bean>
+
<bean id="samlAuthHandler" class="org.apache.cxf.rs.security.oauth2.auth.saml.Saml2BearerAuthHandler"/>
+ <bean id="jwtAuthHandler" class="org.apache.cxf.rs.security.oauth2.grants.jwt.JwtBearerAuthHandler"/>
+
<bean id="customGrantHandler" class="org.apache.cxf.systest.jaxrs.security.oauth2.CustomGrantHandler">
<property name="dataProvider" ref="dataProvider"/>
</bean>
@@ -72,6 +78,7 @@ under the License.
<property name="grantHandlers">
<list>
<ref bean="samlGrantHandler"/>
+ <ref bean="jwtGrantHandler"/>
<ref bean="customGrantHandler"/>
</list>
</property>
@@ -81,7 +88,17 @@ under the License.
<ref bean="serviceBean"/>
</jaxrs:serviceBeans>
<jaxrs:properties>
+<<<<<<< HEAD
<entry key="ws-security.signature.properties" value="org/apache/cxf/systest/jaxrs/security/alice.properties"/>
+=======
+ <entry key="security.signature.properties" value="org/apache/cxf/systest/jaxrs/security/alice.properties"/>
+ <entry key="rs.security.keystore.type" value="jks" />
+ <entry key="rs.security.keystore.alias" value="alice"/>
+ <entry key="rs.security.keystore.password" value="password"/>
+ <entry key="rs.security.keystore.file"
+ value="org/apache/cxf/systest/jaxrs/security/certs/alice.jks" />
+ <entry key="rs.security.signature.algorithm" value="RS256" />
+>>>>>>> dfe90b6... Adding JWT Grant + Authn tests
</jaxrs:properties>
</jaxrs:server>
<jaxrs:server address="https://localhost:${testutil.ports.jaxrs-oauth2}/oauth2-auth">
@@ -95,4 +112,20 @@ under the License.
<entry key="ws-security.signature.properties" value="org/apache/cxf/systest/jaxrs/security/alice.properties"/>
</jaxrs:properties>
</jaxrs:server>
+ <jaxrs:server address="https://localhost:${testutil.ports.jaxrs-oauth2}/oauth2-auth-jwt">
+ <jaxrs:serviceBeans>
+ <ref bean="serviceBean"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <ref bean="jwtAuthHandler"/>
+ </jaxrs:providers>
+ <jaxrs:properties>
+ <entry key="rs.security.keystore.type" value="jks" />
+ <entry key="rs.security.keystore.alias" value="alice"/>
+ <entry key="rs.security.keystore.password" value="password"/>
+ <entry key="rs.security.keystore.file"
+ value="org/apache/cxf/systest/jaxrs/security/certs/alice.jks" />
+ <entry key="rs.security.signature.algorithm" value="RS256" />
+ </jaxrs:properties>
+ </jaxrs:server>
</beans>
[2/7] cxf git commit: Minor test modification
Posted by co...@apache.org.
Minor test modification
# Conflicts:
# systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
# systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
# systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler2.java
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6453dec1
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6453dec1
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6453dec1
Branch: refs/heads/3.0.x-fixes
Commit: 6453dec1f047663c8a6a5f0de0dce7b3ea2d23a6
Parents: d29fa67
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Dec 8 11:28:40 2015 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Dec 8 15:37:59 2015 +0000
----------------------------------------------------------------------
.../jaxrs/security/oauth2/JAXRSOAuth2Test.java | 33 +++++++++++
.../security/oauth2/SamlCallbackHandler.java | 60 +++++++++++++++++---
2 files changed, 85 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/6453dec1/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
index 0a4f079..04faa05 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
@@ -67,8 +67,17 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES);
SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password");
+<<<<<<< HEAD
String assertion = SAMLUtils.createAssertion(new SamlCallbackHandler(),
signInfo).assertionToString();
+=======
+ SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(new SamlCallbackHandler(false),
+ signInfo);
+ Document doc = DOMUtils.newDocument();
+ Element assertionElement = assertionWrapper.toDOM(doc);
+ String assertion = DOM2Writer.nodeToString(assertionElement);
+
+>>>>>>> 6d818c6... Minor test modification
Saml2BearerGrant grant = new Saml2BearerGrant(assertion);
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
new OAuthClientUtils.Consumer("alice", "alice"),
@@ -85,8 +94,20 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES);
SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password");
+<<<<<<< HEAD
String assertion = SAMLUtils.createAssertion(new SamlCallbackHandler2(),
signInfo).assertionToString();
+=======
+ SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true);
+ samlCallbackHandler.setIssuer("alice");
+ String audienceURI = "https://localhost:" + PORT + "/oauth2-auth/token";
+ samlCallbackHandler.setAudience(audienceURI);
+ SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(samlCallbackHandler,
+ signInfo);
+ Document doc = DOMUtils.newDocument();
+ Element assertionElement = assertionWrapper.toDOM(doc);
+ String assertion = DOM2Writer.nodeToString(assertionElement);
+>>>>>>> 6d818c6... Minor test modification
String encodedAssertion = Base64UrlUtility.encode(assertion);
@@ -145,10 +166,22 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("ws-security.callback-handler",
"org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
+<<<<<<< HEAD
properties.put("ws-security.saml-callback-handler",
"org.apache.cxf.systest.jaxrs.security.oauth2.SamlCallbackHandler2");
properties.put("ws-security.signature.username", "alice");
properties.put("ws-security.signature.properties", CRYPTO_RESOURCE_PROPERTIES);
+=======
+
+ SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true);
+ samlCallbackHandler.setIssuer("alice");
+ String audienceURI = "https://localhost:" + PORT + "/oauth2-auth/token";
+ samlCallbackHandler.setAudience(audienceURI);
+ properties.put("security.saml-callback-handler", samlCallbackHandler);
+
+ properties.put("security.signature.username", "alice");
+ properties.put("security.signature.properties", CRYPTO_RESOURCE_PROPERTIES);
+>>>>>>> 6d818c6... Minor test modification
bean.setProperties(properties);
bean.getOutInterceptors().add(new Saml2BearerAuthOutInterceptor());
http://git-wip-us.apache.org/repos/asf/cxf/blob/6453dec1/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
index c105523..821d7a1 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
@@ -31,7 +31,14 @@ import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
+<<<<<<< HEAD
import org.apache.cxf.rt.security.claims.SAMLClaim;
+=======
+import org.apache.cxf.rt.security.saml.claims.SAMLClaim;
+import org.apache.wss4j.common.crypto.Crypto;
+import org.apache.wss4j.common.crypto.CryptoFactory;
+import org.apache.wss4j.common.ext.WSSecurityException;
+>>>>>>> 6d818c6... Minor test modification
import org.apache.wss4j.common.saml.SAMLCallback;
import org.apache.wss4j.common.saml.bean.ActionBean;
import org.apache.wss4j.common.saml.bean.AttributeBean;
@@ -51,12 +58,12 @@ import org.joda.time.DateTime;
public class SamlCallbackHandler implements CallbackHandler {
public static final String PORT = BookServerOAuth2.PORT;
private String confirmationMethod = SAML2Constants.CONF_BEARER;
-
- public SamlCallbackHandler() {
- }
-
- public void setConfirmationMethod(String confirmationMethod) {
- this.confirmationMethod = confirmationMethod;
+ private boolean signAssertion = true;
+ private String issuer = "resourceOwner";
+ private String audience = "https://localhost:" + PORT + "/oauth2/token";
+
+ public SamlCallbackHandler(boolean signAssertion) {
+ this.signAssertion = signAssertion;
}
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
@@ -65,7 +72,12 @@ public class SamlCallbackHandler implements CallbackHandler {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof SAMLCallback) {
SAMLCallback callback = (SAMLCallback) callbacks[i];
+<<<<<<< HEAD
callback.setIssuer("resourceOwner");
+=======
+ callback.setSamlVersion(Version.SAML_20);
+ callback.setIssuer(issuer);
+>>>>>>> 6d818c6... Minor test modification
String subjectName = m != null ? (String)m.getContextualProperty("saml.subject.name") : null;
if (subjectName == null) {
@@ -81,8 +93,7 @@ public class SamlCallbackHandler implements CallbackHandler {
ConditionsBean conditions = new ConditionsBean();
AudienceRestrictionBean audienceRestriction = new AudienceRestrictionBean();
- String audienceURI = "https://localhost:" + PORT + "/oauth2/token";
- audienceRestriction.setAudienceURIs(Collections.singletonList(audienceURI));
+ audienceRestriction.setAudienceURIs(Collections.singletonList(audience));
conditions.setAudienceRestrictions(Collections.singletonList(audienceRestriction));
callback.setConditions(conditions);
@@ -136,8 +147,41 @@ public class SamlCallbackHandler implements CallbackHandler {
attrBean.setSamlAttributes(claims);
callback.setAttributeStatementData(Collections.singletonList(attrBean));
+
+ if (signAssertion) {
+ try {
+ Crypto crypto =
+ CryptoFactory.getInstance("org/apache/cxf/systest/jaxrs/security/alice.properties");
+ callback.setIssuerCrypto(crypto);
+ callback.setIssuerKeyName("alice");
+ callback.setIssuerKeyPassword("password");
+ callback.setSignAssertion(true);
+ } catch (WSSecurityException e) {
+ throw new IOException(e);
+ }
+ }
}
}
}
+ public String getIssuer() {
+ return issuer;
+ }
+
+ public void setIssuer(String issuer) {
+ this.issuer = issuer;
+ }
+
+ public String getAudience() {
+ return audience;
+ }
+
+ public void setAudience(String audience) {
+ this.audience = audience;
+ }
+
+ public void setConfirmationMethod(String confMethod) {
+ this.confirmationMethod = confMethod;
+ }
+
}
[7/7] cxf git commit: Fixing merge
Posted by co...@apache.org.
Fixing merge
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ca1d759d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ca1d759d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ca1d759d
Branch: refs/heads/3.0.x-fixes
Commit: ca1d759d977d81634c1116d8e92e819024a900a4
Parents: 6498f99
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Dec 8 18:06:30 2015 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Dec 8 18:06:30 2015 +0000
----------------------------------------------------------------------
systests/rs-security/pom.xml | 12 --
.../jaxrs/security/oauth2/JAXRSOAuth2Test.java | 128 +------------------
.../security/oauth2/SamlCallbackHandler.java | 9 +-
.../oauth2/grants/AuthorizationGrantTest.java | 76 -----------
.../grants/CallbackHandlerLoginHandler.java | 2 +-
.../oauth2/grants/OAuthDataProviderImpl.java | 13 +-
.../security/oauth2/grants/grants-server.xml | 2 +-
.../systest/jaxrs/security/oauth2/server.xml | 4 -
8 files changed, 18 insertions(+), 228 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/ca1d759d/systests/rs-security/pom.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/pom.xml b/systests/rs-security/pom.xml
index 8c252bb..fad52e6 100644
--- a/systests/rs-security/pom.xml
+++ b/systests/rs-security/pom.xml
@@ -40,18 +40,6 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
-<<<<<<< HEAD
- <artifactId>jetty-server</artifactId>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-plus</artifactId>
- <version>${cxf.jetty.version}</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
-=======
->>>>>>> 6106f46... Adding OAuth authorization grant tests
<artifactId>jetty-webapp</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/ca1d759d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
index 6558d87..664752f 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/JAXRSOAuth2Test.java
@@ -20,12 +20,8 @@
package org.apache.cxf.systest.jaxrs.security.oauth2;
import java.net.URL;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -37,17 +33,10 @@ import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.rs.security.common.CryptoLoader;
-import org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm;
-import org.apache.cxf.rs.security.jose.jws.JwsHeaders;
-import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactProducer;
-import org.apache.cxf.rs.security.jose.jws.JwsSignatureProvider;
-import org.apache.cxf.rs.security.jose.jws.JwsUtils;
-import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
import org.apache.cxf.rs.security.oauth2.auth.saml.Saml2BearerAuthOutInterceptor;
import org.apache.cxf.rs.security.oauth2.client.OAuthClientUtils;
import org.apache.cxf.rs.security.oauth2.common.AccessTokenGrant;
import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
-import org.apache.cxf.rs.security.oauth2.grants.jwt.JwtBearerGrant;
import org.apache.cxf.rs.security.oauth2.grants.saml.Saml2BearerGrant;
import org.apache.cxf.rs.security.oauth2.saml.Constants;
import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants;
@@ -55,7 +44,6 @@ import org.apache.cxf.rs.security.saml.SAMLUtils;
import org.apache.cxf.rs.security.saml.SAMLUtils.SelfSignInfo;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.wss4j.common.crypto.Crypto;
-
import org.junit.BeforeClass;
import org.junit.Test;
@@ -78,17 +66,8 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES);
SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password");
-<<<<<<< HEAD
- String assertion = SAMLUtils.createAssertion(new SamlCallbackHandler(),
+ String assertion = SAMLUtils.createAssertion(new SamlCallbackHandler(false),
signInfo).assertionToString();
-=======
- SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(new SamlCallbackHandler(false),
- signInfo);
- Document doc = DOMUtils.newDocument();
- Element assertionElement = assertionWrapper.toDOM(doc);
- String assertion = DOM2Writer.nodeToString(assertionElement);
-
->>>>>>> 6d818c6... Minor test modification
Saml2BearerGrant grant = new Saml2BearerGrant(assertion);
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
new OAuthClientUtils.Consumer("alice", "alice"),
@@ -104,22 +83,14 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES);
SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password");
-
-<<<<<<< HEAD
- String assertion = SAMLUtils.createAssertion(new SamlCallbackHandler2(),
- signInfo).assertionToString();
-=======
+
SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true);
samlCallbackHandler.setIssuer("alice");
String audienceURI = "https://localhost:" + PORT + "/oauth2-auth/token";
samlCallbackHandler.setAudience(audienceURI);
- SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(samlCallbackHandler,
- signInfo);
- Document doc = DOMUtils.newDocument();
- Element assertionElement = assertionWrapper.toDOM(doc);
- String assertion = DOM2Writer.nodeToString(assertionElement);
->>>>>>> 6d818c6... Minor test modification
+ String assertion = SAMLUtils.createAssertion(samlCallbackHandler,
+ signInfo).assertionToString();
String encodedAssertion = Base64UrlUtility.encode(assertion);
Map<String, String> extraParams = new HashMap<String, String>();
@@ -151,41 +122,6 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
assertNotNull(at.getTokenKey());
}
- @Test
- public void testJWTBearerGrant() throws Exception {
- String address = "https://localhost:" + PORT + "/oauth2/token";
- WebClient wc = createWebClient(address);
-
- // Create the JWT Token
- String token = createToken("resourceOwner", "alice", address, true, true);
-
- JwtBearerGrant grant = new JwtBearerGrant(token);
- ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
- new Consumer("alice", "alice"),
- grant,
- false);
- assertNotNull(at.getTokenKey());
- }
-
- @Test
- public void testJWTBearerAuthenticationDirect() throws Exception {
- String address = "https://localhost:" + PORT + "/oauth2-auth-jwt/token";
- WebClient wc = createWebClient(address);
-
- // Create the JWT Token
- String token = createToken("resourceOwner", "alice", address, true, true);
-
- Map<String, String> extraParams = new HashMap<String, String>();
- extraParams.put(Constants.CLIENT_AUTH_ASSERTION_TYPE,
- "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
- extraParams.put(Constants.CLIENT_AUTH_ASSERTION_PARAM, token);
-
- ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
- new CustomGrant(),
- extraParams);
- assertNotNull(at.getTokenKey());
- }
-
private WebClient createWebClient(String address) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
@@ -212,22 +148,15 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("ws-security.callback-handler",
"org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
-<<<<<<< HEAD
- properties.put("ws-security.saml-callback-handler",
- "org.apache.cxf.systest.jaxrs.security.oauth2.SamlCallbackHandler2");
- properties.put("ws-security.signature.username", "alice");
- properties.put("ws-security.signature.properties", CRYPTO_RESOURCE_PROPERTIES);
-=======
SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true);
samlCallbackHandler.setIssuer("alice");
String audienceURI = "https://localhost:" + PORT + "/oauth2-auth/token";
samlCallbackHandler.setAudience(audienceURI);
- properties.put("security.saml-callback-handler", samlCallbackHandler);
+ properties.put("ws-security.saml-callback-handler", samlCallbackHandler);
- properties.put("security.signature.username", "alice");
- properties.put("security.signature.properties", CRYPTO_RESOURCE_PROPERTIES);
->>>>>>> 6d818c6... Minor test modification
+ properties.put("ws-security.signature.username", "alice");
+ properties.put("ws-security.signature.properties", CRYPTO_RESOURCE_PROPERTIES);
bean.setProperties(properties);
bean.getOutInterceptors().add(new Saml2BearerAuthOutInterceptor());
@@ -237,49 +166,6 @@ public class JAXRSOAuth2Test extends AbstractBusClientServerTestBase {
return wc;
}
- private String createToken(String issuer, String subject, String audience,
- boolean expiry, boolean sign) {
- // Create the JWT Token
- JwtClaims claims = new JwtClaims();
- claims.setSubject(subject);
- if (issuer != null) {
- claims.setIssuer(issuer);
- }
- claims.setIssuedAt(new Date().getTime() / 1000L);
- if (expiry) {
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.SECOND, 60);
- claims.setExpiryTime(cal.getTimeInMillis() / 1000L);
- }
- if (audience != null) {
- claims.setAudiences(Collections.singletonList(audience));
- }
-
- if (sign) {
- // Sign the JWT Token
- Properties signingProperties = new Properties();
- signingProperties.put("rs.security.keystore.type", "jks");
- signingProperties.put("rs.security.keystore.password", "password");
- signingProperties.put("rs.security.keystore.alias", "alice");
- signingProperties.put("rs.security.keystore.file",
- "org/apache/cxf/systest/jaxrs/security/certs/alice.jks");
- signingProperties.put("rs.security.key.password", "password");
- signingProperties.put("rs.security.signature.algorithm", "RS256");
-
- JwsHeaders jwsHeaders = new JwsHeaders(signingProperties);
- JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwsHeaders, claims);
-
- JwsSignatureProvider sigProvider =
- JwsUtils.loadSignatureProvider(signingProperties, jwsHeaders);
-
- return jws.signWith(sigProvider);
- }
-
- JwsHeaders jwsHeaders = new JwsHeaders(SignatureAlgorithm.NONE);
- JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwsHeaders, claims);
- return jws.getSignedEncodedJws();
- }
-
private static class CustomGrant implements AccessTokenGrant {
private static final long serialVersionUID = -4007538779198315873L;
http://git-wip-us.apache.org/repos/asf/cxf/blob/ca1d759d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
index 821d7a1..dbd9eb8 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/SamlCallbackHandler.java
@@ -31,14 +31,10 @@ import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
-<<<<<<< HEAD
import org.apache.cxf.rt.security.claims.SAMLClaim;
-=======
-import org.apache.cxf.rt.security.saml.claims.SAMLClaim;
import org.apache.wss4j.common.crypto.Crypto;
import org.apache.wss4j.common.crypto.CryptoFactory;
import org.apache.wss4j.common.ext.WSSecurityException;
->>>>>>> 6d818c6... Minor test modification
import org.apache.wss4j.common.saml.SAMLCallback;
import org.apache.wss4j.common.saml.bean.ActionBean;
import org.apache.wss4j.common.saml.bean.AttributeBean;
@@ -49,6 +45,7 @@ import org.apache.wss4j.common.saml.bean.AuthDecisionStatementBean.Decision;
import org.apache.wss4j.common.saml.bean.AuthenticationStatementBean;
import org.apache.wss4j.common.saml.bean.ConditionsBean;
import org.apache.wss4j.common.saml.bean.SubjectBean;
+import org.apache.wss4j.common.saml.bean.Version;
import org.apache.wss4j.common.saml.builder.SAML2Constants;
import org.joda.time.DateTime;
@@ -72,12 +69,8 @@ public class SamlCallbackHandler implements CallbackHandler {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof SAMLCallback) {
SAMLCallback callback = (SAMLCallback) callbacks[i];
-<<<<<<< HEAD
- callback.setIssuer("resourceOwner");
-=======
callback.setSamlVersion(Version.SAML_20);
callback.setIssuer(issuer);
->>>>>>> 6d818c6... Minor test modification
String subjectName = m != null ? (String)m.getContextualProperty("saml.subject.name") : null;
if (subjectName == null) {
http://git-wip-us.apache.org/repos/asf/cxf/blob/ca1d759d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
index 5b757f6..0d6c3c5 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/AuthorizationGrantTest.java
@@ -21,11 +21,8 @@ package org.apache.cxf.systest.jaxrs.security.oauth2.grants;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
-import java.util.Properties;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;
@@ -33,12 +30,6 @@ import javax.ws.rs.core.Response;
import org.apache.cxf.common.util.Base64UrlUtility;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.provider.json.JSONProvider;
-import org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm;
-import org.apache.cxf.rs.security.jose.jws.JwsHeaders;
-import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactProducer;
-import org.apache.cxf.rs.security.jose.jws.JwsSignatureProvider;
-import org.apache.cxf.rs.security.jose.jws.JwsUtils;
-import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
import org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData;
import org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider;
@@ -294,31 +285,6 @@ public class AuthorizationGrantTest extends AbstractBusClientServerTestBase {
assertNotNull(accessToken.getRefreshToken());
}
- @org.junit.Test
- public void testJWTAuthorizationGrant() throws Exception {
- URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
-
- String address = "https://localhost:" + PORT + "/services/";
- WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
-
- // Create the JWT Token
- String token = createToken("DoubleItSTSIssuer", "consumer-id",
- "https://localhost:" + PORT + "/services/token", true, true);
-
- // Get Access Token
- client.type("application/x-www-form-urlencoded").accept("application/json");
- client.path("token");
-
- Form form = new Form();
- form.param("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");
- form.param("assertion", token);
- form.param("client_id", "consumer-id");
- Response response = client.post(form);
-
- ClientAccessToken accessToken = response.readEntity(ClientAccessToken.class);
- assertNotNull(accessToken.getTokenKey());
- assertNotNull(accessToken.getRefreshToken());
- }
private String getAuthorizationCode(WebClient client) {
return getAuthorizationCode(client, null);
}
@@ -402,46 +368,4 @@ public class AuthorizationGrantTest extends AbstractBusClientServerTestBase {
return samlAssertion.assertionToString();
}
- private String createToken(String issuer, String subject, String audience,
- boolean expiry, boolean sign) {
- // Create the JWT Token
- JwtClaims claims = new JwtClaims();
- claims.setSubject(subject);
- if (issuer != null) {
- claims.setIssuer(issuer);
- }
- claims.setIssuedAt(new Date().getTime() / 1000L);
- if (expiry) {
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.SECOND, 60);
- claims.setExpiryTime(cal.getTimeInMillis() / 1000L);
- }
- if (audience != null) {
- claims.setAudiences(Collections.singletonList(audience));
- }
-
- if (sign) {
- // Sign the JWT Token
- Properties signingProperties = new Properties();
- signingProperties.put("rs.security.keystore.type", "jks");
- signingProperties.put("rs.security.keystore.password", "password");
- signingProperties.put("rs.security.keystore.alias", "alice");
- signingProperties.put("rs.security.keystore.file",
- "org/apache/cxf/systest/jaxrs/security/certs/alice.jks");
- signingProperties.put("rs.security.key.password", "password");
- signingProperties.put("rs.security.signature.algorithm", "RS256");
-
- JwsHeaders jwsHeaders = new JwsHeaders(signingProperties);
- JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwsHeaders, claims);
-
- JwsSignatureProvider sigProvider =
- JwsUtils.loadSignatureProvider(signingProperties, jwsHeaders);
-
- return jws.signWith(sigProvider);
- }
-
- JwsHeaders jwsHeaders = new JwsHeaders(SignatureAlgorithm.NONE);
- JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwsHeaders, claims);
- return jws.getSignedEncodedJws();
- }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/ca1d759d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
index 0442d68..48c509c 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
@@ -28,7 +28,7 @@ import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.rs.security.oauth2.common.UserSubject;
import org.apache.cxf.rs.security.oauth2.grants.owner.ResourceOwnerLoginHandler;
import org.apache.wss4j.dom.WSConstants;
-import org.apache.wss4j.dom.engine.WSSConfig;
+import org.apache.wss4j.dom.WSSConfig;
import org.apache.wss4j.dom.handler.RequestData;
import org.apache.wss4j.dom.message.token.UsernameToken;
import org.apache.wss4j.dom.validate.Credential;
http://git-wip-us.apache.org/repos/asf/cxf/blob/ca1d759d/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java
index 0ae9708..94df132 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/OAuthDataProviderImpl.java
@@ -62,12 +62,13 @@ public class OAuthDataProviderImpl extends DefaultEHCacheCodeDataProvider {
return Collections.emptyList();
}
- List<OAuthPermission> permissions = new ArrayList<>();
+ List<OAuthPermission> permissions = new ArrayList<OAuthPermission>();
for (String requestedScope : requestedScopes) {
if ("read_balance".equals(requestedScope)) {
OAuthPermission permission = new OAuthPermission();
+ permission.setPermission("read_balance");
permission.setHttpVerbs(Collections.singletonList("GET"));
- List<String> uris = new ArrayList<>();
+ List<String> uris = new ArrayList<String>();
String partnerAddress = "/partners/balance/*";
uris.add(partnerAddress);
permission.setUris(uris);
@@ -75,8 +76,9 @@ public class OAuthDataProviderImpl extends DefaultEHCacheCodeDataProvider {
permissions.add(permission);
} else if ("create_balance".equals(requestedScope)) {
OAuthPermission permission = new OAuthPermission();
+ permission.setPermission("create_balance");
permission.setHttpVerbs(Collections.singletonList("POST"));
- List<String> uris = new ArrayList<>();
+ List<String> uris = new ArrayList<String>();
String partnerAddress = "/partners/balance/*";
uris.add(partnerAddress);
permission.setUris(uris);
@@ -84,8 +86,9 @@ public class OAuthDataProviderImpl extends DefaultEHCacheCodeDataProvider {
permissions.add(permission);
} else if ("read_data".equals(requestedScope)) {
OAuthPermission permission = new OAuthPermission();
+ permission.setPermission("read_data");
permission.setHttpVerbs(Collections.singletonList("GET"));
- List<String> uris = new ArrayList<>();
+ List<String> uris = new ArrayList<String>();
String partnerAddress = "/partners/data/*";
uris.add(partnerAddress);
permission.setUris(uris);
@@ -98,4 +101,4 @@ public class OAuthDataProviderImpl extends DefaultEHCacheCodeDataProvider {
return permissions;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/ca1d759d/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
index 3ef86fb..91a6c33 100644
--- a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
+++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/grants/grants-server.xml
@@ -127,7 +127,7 @@ under the License.
<ref bean="basicAuthFilter"/>
</jaxrs:providers>
<jaxrs:properties>
- <entry key="security.signature.properties"
+ <entry key="ws-security.signature.properties"
value="org/apache/cxf/systest/jaxrs/security/bob.properties"/>
<entry key="rs.security.keystore.type" value="jks" />
<entry key="rs.security.keystore.alias" value="alice"/>
http://git-wip-us.apache.org/repos/asf/cxf/blob/ca1d759d/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
----------------------------------------------------------------------
diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
index fa196b9..d3af847 100644
--- a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
+++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/oauth2/server.xml
@@ -88,17 +88,13 @@ under the License.
<ref bean="serviceBean"/>
</jaxrs:serviceBeans>
<jaxrs:properties>
-<<<<<<< HEAD
<entry key="ws-security.signature.properties" value="org/apache/cxf/systest/jaxrs/security/alice.properties"/>
-=======
- <entry key="security.signature.properties" value="org/apache/cxf/systest/jaxrs/security/alice.properties"/>
<entry key="rs.security.keystore.type" value="jks" />
<entry key="rs.security.keystore.alias" value="alice"/>
<entry key="rs.security.keystore.password" value="password"/>
<entry key="rs.security.keystore.file"
value="org/apache/cxf/systest/jaxrs/security/certs/alice.jks" />
<entry key="rs.security.signature.algorithm" value="RS256" />
->>>>>>> dfe90b6... Adding JWT Grant + Authn tests
</jaxrs:properties>
</jaxrs:server>
<jaxrs:server address="https://localhost:${testutil.ports.jaxrs-oauth2}/oauth2-auth">