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 2014/11/28 16:31:57 UTC
cxf git commit: [CXF-5607] More of OIDC utility support
Repository: cxf
Updated Branches:
refs/heads/master 127612eb1 -> 6388f2e0e
[CXF-5607] More of OIDC utility support
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6388f2e0
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6388f2e0
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6388f2e0
Branch: refs/heads/master
Commit: 6388f2e0e512860763460c8fe8d1cd751f167f26
Parents: 127612e
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Fri Nov 28 15:31:40 2014 +0000
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Fri Nov 28 15:31:40 2014 +0000
----------------------------------------------------------------------
.../cxf/rs/security/oidc/rp/OidcUtils.java | 1 +
.../oidc/rp/idp/UserInfoCodeResponseFilter.java | 86 ++++++++++++++++++++
.../security/oidc/rp/idp/UserInfoProvider.java | 28 +++++++
3 files changed, 115 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/6388f2e0/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/OidcUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/OidcUtils.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/OidcUtils.java
index 10ece56..b978c4f 100644
--- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/OidcUtils.java
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/OidcUtils.java
@@ -27,6 +27,7 @@ import org.apache.cxf.rs.security.jose.jwt.JwtToken;
import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
public final class OidcUtils {
+ public static final String ID_TOKEN = "id_token";
private OidcUtils() {
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/6388f2e0/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/idp/UserInfoCodeResponseFilter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/idp/UserInfoCodeResponseFilter.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/idp/UserInfoCodeResponseFilter.java
new file mode 100644
index 0000000..62be869
--- /dev/null
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/idp/UserInfoCodeResponseFilter.java
@@ -0,0 +1,86 @@
+/**
+ * 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.oidc.rp.idp;
+
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.rs.security.jose.JoseHeaders;
+import org.apache.cxf.rs.security.jose.jwe.JweEncryptionProvider;
+import org.apache.cxf.rs.security.jose.jwe.JweUtils;
+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.oauth2.common.Client;
+import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
+import org.apache.cxf.rs.security.oauth2.common.UserSubject;
+import org.apache.cxf.rs.security.oauth2.provider.AccessTokenResponseFilter;
+import org.apache.cxf.rs.security.oidc.common.UserIdToken;
+import org.apache.cxf.rs.security.oidc.rp.OidcUtils;
+
+public class UserInfoCodeResponseFilter implements AccessTokenResponseFilter {
+ private JwsSignatureProvider sigProvider;
+ private JweEncryptionProvider encryptionProvider;
+ private UserInfoProvider userInfoProvider;
+ private String issuer;
+ @Override
+ public void process(Client client, ClientAccessToken ct, UserSubject endUser) {
+ UserIdToken token = userInfoProvider.getUserIdToken(endUser);
+ token.setIssuer(issuer);
+ token.setAudience(client.getClientId());
+
+ JwsJwtCompactProducer producer = new JwsJwtCompactProducer(token);
+ JoseHeaders headers = new JoseHeaders();
+ JwsSignatureProvider theSigProvider = getInitializedSigProvider(headers);
+ String idToken = producer.signWith(theSigProvider);
+
+ JweEncryptionProvider theEncryptionProvider = getInitializedEncryptionProvider();
+ if (theEncryptionProvider != null) {
+ idToken = theEncryptionProvider.encrypt(StringUtils.toBytesUTF8(idToken), null);
+ }
+ ct.getParameters().put(OidcUtils.ID_TOKEN, idToken);
+
+ }
+ public void setSignatureProvider(JwsSignatureProvider signatureProvider) {
+ this.sigProvider = signatureProvider;
+ }
+
+ protected JwsSignatureProvider getInitializedSigProvider(JoseHeaders headers) {
+ if (sigProvider != null) {
+ return sigProvider;
+ }
+ JwsSignatureProvider theSigProvider = JwsUtils.loadSignatureProvider(true);
+ headers.setAlgorithm(theSigProvider.getAlgorithm());
+ return theSigProvider;
+ }
+ protected JweEncryptionProvider getInitializedEncryptionProvider() {
+ if (encryptionProvider != null) {
+ return encryptionProvider;
+ }
+ return JweUtils.loadEncryptionProvider(false);
+ }
+
+ public void setIssuer(String issuer) {
+ this.issuer = issuer;
+ }
+ public UserInfoProvider getUserInfoProvider() {
+ return userInfoProvider;
+ }
+ public void setUserInfoProvider(UserInfoProvider userInfoProvider) {
+ this.userInfoProvider = userInfoProvider;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/6388f2e0/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/idp/UserInfoProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/idp/UserInfoProvider.java b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/idp/UserInfoProvider.java
new file mode 100644
index 0000000..d36dec9
--- /dev/null
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/rp/idp/UserInfoProvider.java
@@ -0,0 +1,28 @@
+/**
+ * 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.oidc.rp.idp;
+
+import org.apache.cxf.rs.security.oauth2.common.UserSubject;
+import org.apache.cxf.rs.security.oidc.common.UserIdToken;
+import org.apache.cxf.rs.security.oidc.common.UserProfile;
+
+public interface UserInfoProvider {
+ UserIdToken getUserIdToken(UserSubject authenticatedUser);
+ UserProfile getUserProfile(UserSubject authenticatedUser);
+}