You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2015/04/08 18:24:58 UTC
[1/3] cxf git commit: Adding the missing resource
Repository: cxf
Updated Branches:
refs/heads/3.0.x-fixes 90bd0ea2c -> 51bc2f2e4
Adding the missing resource
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ac399de6
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ac399de6
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ac399de6
Branch: refs/heads/3.0.x-fixes
Commit: ac399de658838748bc8b8ef876c4121c6e14c454
Parents: e2782f7
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Wed Apr 8 17:18:07 2015 +0100
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Wed Apr 8 17:19:54 2015 +0100
----------------------------------------------------------------------
.../oauth2/client/CodeAuthSupplier.java | 72 ++++++++++++++++++++
1 file changed, 72 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/ac399de6/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java
new file mode 100644
index 0000000..c85a8de
--- /dev/null
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java
@@ -0,0 +1,72 @@
+/**
+ * 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.rs.security.oauth2.client;
+
+import java.net.URI;
+
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
+import org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrant;
+import org.apache.cxf.transport.http.auth.HttpAuthSupplier;
+
+public class CodeAuthSupplier implements HttpAuthSupplier {
+ private volatile String code;
+ private BearerAuthSupplier tokenSupplier = new BearerAuthSupplier();
+ public CodeAuthSupplier() {
+ }
+
+ public boolean requiresRequestCaching() {
+ return true;
+ }
+
+ public String getAuthorization(AuthorizationPolicy authPolicy,
+ URI currentURI,
+ Message message,
+ String fullHeader) {
+ if (code != null) {
+ synchronized (tokenSupplier) {
+ if (tokenSupplier.getClientAccessToken().getTokenKey() == null) {
+ WebClient wc = tokenSupplier.createAccessTokenServiceClient();
+ ClientAccessToken at = OAuthClientUtils.getAccessToken(wc,
+ tokenSupplier.getConsumer(),
+ new AuthorizationCodeGrant(code));
+ code = null;
+ tokenSupplier.setClientAccessToken(at);
+ }
+ }
+ }
+ return tokenSupplier.getAuthorization(authPolicy, currentURI, message, fullHeader);
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+ public void setRefreshEarly(boolean refreshEarly) {
+ tokenSupplier.setRefreshEarly(refreshEarly);
+ }
+ public void setAccessTokenServiceUri(String uri) {
+ tokenSupplier.setAccessTokenServiceUri(uri);
+ }
+ public void setConsumer(Consumer consumer) {
+ tokenSupplier.setConsumer(consumer);
+ }
+}
[2/3] cxf git commit: Prototyping an oauth2 code auth supplier
Posted by se...@apache.org.
Prototyping an oauth2 code auth supplier
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e2782f77
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e2782f77
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e2782f77
Branch: refs/heads/3.0.x-fixes
Commit: e2782f7738f20af922cc7b11a582ed79ef17b1c6
Parents: 90bd0ea
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Wed Apr 8 17:17:01 2015 +0100
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Wed Apr 8 17:19:54 2015 +0100
----------------------------------------------------------------------
.../oauth2/client/AbstractAuthSupplier.java | 8 +++++++-
.../oauth2/client/BearerAuthSupplier.java | 19 +++++++++++--------
2 files changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/e2782f77/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AbstractAuthSupplier.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AbstractAuthSupplier.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AbstractAuthSupplier.java
index 5932f28..aecc472 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AbstractAuthSupplier.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/AbstractAuthSupplier.java
@@ -22,7 +22,7 @@ package org.apache.cxf.rs.security.oauth2.client;
import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
public abstract class AbstractAuthSupplier {
- protected ClientAccessToken clientAccessToken = new ClientAccessToken();
+ private ClientAccessToken clientAccessToken = new ClientAccessToken();
protected AbstractAuthSupplier(String type) {
clientAccessToken = new ClientAccessToken();
clientAccessToken.setTokenType(type);
@@ -33,5 +33,11 @@ public abstract class AbstractAuthSupplier {
protected String createAuthorizationHeader() {
return clientAccessToken.getTokenType() + " " + clientAccessToken.getTokenKey();
}
+ protected ClientAccessToken getClientAccessToken() {
+ return clientAccessToken;
+ }
+ protected void setClientAccessToken(ClientAccessToken clientAccessToken) {
+ this.clientAccessToken = clientAccessToken;
+ }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/e2782f77/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java
index 04c94ab..1ad0722 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java
@@ -25,6 +25,7 @@ import java.util.Collections;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.message.Message;
+import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
import org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider;
import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants;
import org.apache.cxf.rs.security.oauth2.utils.OAuthUtils;
@@ -46,7 +47,7 @@ public class BearerAuthSupplier extends AbstractAuthSupplier implements HttpAuth
URI currentURI,
Message message,
String fullHeader) {
- if (clientAccessToken.getTokenKey() == null) {
+ if (getClientAccessToken().getTokenKey() == null) {
return null;
}
@@ -67,9 +68,10 @@ public class BearerAuthSupplier extends AbstractAuthSupplier implements HttpAuth
}
}
private void refreshAccessTokenIfExpired(AuthorizationPolicy authPolicy) {
- if (clientAccessToken.getExpiresIn() != -1
- && OAuthUtils.isExpired(clientAccessToken.getIssuedAt(),
- clientAccessToken.getExpiresIn())) {
+ ClientAccessToken at = getClientAccessToken();
+ if (at.getExpiresIn() != -1
+ && OAuthUtils.isExpired(at.getIssuedAt(),
+ at.getExpiresIn())) {
refreshAccessToken(authPolicy);
}
@@ -77,7 +79,8 @@ public class BearerAuthSupplier extends AbstractAuthSupplier implements HttpAuth
private boolean refreshAccessToken(AuthorizationPolicy authPolicy) {
- if (clientAccessToken.getRefreshToken() == null) {
+ ClientAccessToken at = getClientAccessToken();
+ if (at.getRefreshToken() == null) {
return false;
}
// Client id and secret are needed to refresh the tokens
@@ -100,16 +103,16 @@ public class BearerAuthSupplier extends AbstractAuthSupplier implements HttpAuth
// not be done on every request the current approach is quite reasonable
WebClient accessTokenService = createAccessTokenServiceClient();
- clientAccessToken = OAuthClientUtils.refreshAccessToken(accessTokenService, theConsumer, clientAccessToken);
+ setClientAccessToken(OAuthClientUtils.refreshAccessToken(accessTokenService, theConsumer, at));
return true;
}
- private WebClient createAccessTokenServiceClient() {
+ WebClient createAccessTokenServiceClient() {
return WebClient.create(accessTokenServiceUri, Collections.singletonList(new OAuthJSONProvider()));
}
public void setRefreshToken(String refreshToken) {
- clientAccessToken.setRefreshToken(refreshToken);
+ getClientAccessToken().setRefreshToken(refreshToken);
}
public void setAccessTokenServiceUri(String uri) {
[3/3] cxf git commit: Prototyping an oauth2 code auth supplier
Posted by se...@apache.org.
Prototyping an oauth2 code auth supplier
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/51bc2f2e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/51bc2f2e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/51bc2f2e
Branch: refs/heads/3.0.x-fixes
Commit: 51bc2f2e412a2f4d1115681f892eb14009d52558
Parents: ac399de
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Wed Apr 8 17:24:33 2015 +0100
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Wed Apr 8 17:24:33 2015 +0100
----------------------------------------------------------------------
.../cxf/rs/security/oauth2/client/BearerAuthSupplier.java | 8 +++++---
.../cxf/rs/security/oauth2/client/CodeAuthSupplier.java | 2 +-
2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/51bc2f2e/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java
index 1ad0722..475c2cb 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/BearerAuthSupplier.java
@@ -119,10 +119,12 @@ public class BearerAuthSupplier extends AbstractAuthSupplier implements HttpAuth
this.accessTokenServiceUri = uri;
}
- public void setConsumer(OAuthClientUtils.Consumer consumer) {
- this.consumer = consumer;
+ public void setConsumer(OAuthClientUtils.Consumer c) {
+ this.consumer = c;
+ }
+ public OAuthClientUtils.Consumer getConsumer() {
+ return consumer;
}
-
public void setRefreshEarly(boolean refreshEarly) {
this.refreshEarly = refreshEarly;
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/51bc2f2e/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java
index c85a8de..f286b07 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/client/CodeAuthSupplier.java
@@ -66,7 +66,7 @@ public class CodeAuthSupplier implements HttpAuthSupplier {
public void setAccessTokenServiceUri(String uri) {
tokenSupplier.setAccessTokenServiceUri(uri);
}
- public void setConsumer(Consumer consumer) {
+ public void setConsumer(OAuthClientUtils.Consumer consumer) {
tokenSupplier.setConsumer(consumer);
}
}