Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7002118931 for ; Thu, 25 Feb 2016 17:40:24 +0000 (UTC) Received: (qmail 7257 invoked by uid 500); 25 Feb 2016 17:40:24 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 7176 invoked by uid 500); 25 Feb 2016 17:40:24 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 6931 invoked by uid 99); 25 Feb 2016 17:40:24 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Feb 2016 17:40:24 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E718AE8F31; Thu, 25 Feb 2016 17:40:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Date: Thu, 25 Feb 2016 17:40:25 -0000 Message-Id: <3dd13a3b7933490eb3bdaa11622d08d4@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/3] cxf-fediz git commit: Got OIDC system test working using a browser Got OIDC system test working using a browser Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/785104b7 Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/785104b7 Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/785104b7 Branch: refs/heads/master Commit: 785104b796e706851a80c51d1999fcbc291b2e99 Parents: ed9727c Author: Colm O hEigeartaigh Authored: Thu Feb 25 17:39:59 2016 +0000 Committer: Colm O hEigeartaigh Committed: Thu Feb 25 17:39:59 2016 +0000 ---------------------------------------------------------------------- .../oidc/src/test/resources/cxf-service.xml | 17 ++- .../fediz/oidc/idp/example/BasicAuthFilter.java | 1 + .../idp/example/EHCacheOIDCTokenProvider.java | 53 ++++++++ .../example/EHCacheRefreshTokenProvider.java | 53 -------- .../oidc/idp/example/IdTokenProviderImpl.java | 5 +- .../src/main/resources/clienttrust.jks | Bin 1512 -> 0 bytes .../src/main/resources/stsKeystoreB.properties | 6 - .../src/main/webapp/WEB-INF/cxf-service.xml | 17 ++- .../WEB-INF/views/oAuthAuthorizationData.jsp | 133 +++++++++++++++++++ systests/federation/pom.xml | 1 + 10 files changed, 218 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidc/src/test/resources/cxf-service.xml ---------------------------------------------------------------------- diff --git a/systests/federation/oidc/src/test/resources/cxf-service.xml b/systests/federation/oidc/src/test/resources/cxf-service.xml index 4201a96..acc0a9a 100644 --- a/systests/federation/oidc/src/test/resources/cxf-service.xml +++ b/systests/federation/oidc/src/test/resources/cxf-service.xml @@ -77,7 +77,7 @@ - + @@ -96,22 +96,31 @@ - + + + + + + + + - + + - + + http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java index a85c8c9..7a4e48e 100644 --- a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java +++ b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/BasicAuthFilter.java @@ -42,6 +42,7 @@ public class BasicAuthFilter extends WSS4JBasicAuthValidator implements Containe if (policy == null || policy.getUserName() == null || policy.getPassword() == null) { requestContext.abortWith( Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build()); + return; } try { http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/EHCacheOIDCTokenProvider.java ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/EHCacheOIDCTokenProvider.java b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/EHCacheOIDCTokenProvider.java new file mode 100644 index 0000000..2dfb7de --- /dev/null +++ b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/EHCacheOIDCTokenProvider.java @@ -0,0 +1,53 @@ +/** + * 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.fediz.oidc.idp.example; + +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 OpenId + */ +public class EHCacheOIDCTokenProvider extends DefaultEHCacheCodeDataProvider { + + @Override + public List convertScopeToPermissions(Client client, List requestedScopes) { + if (requestedScopes.isEmpty()) { + return Collections.emptyList(); + } + + List permissions = new ArrayList<>(); + for (String requestedScope : requestedScopes) { + if ("openid".equals(requestedScope)) { + OAuthPermission permission = new OAuthPermission("openid", "Authenticate user"); + permissions.add(permission); + } else { + throw new OAuthServiceException("invalid_scope"); + } + } + + return permissions; + } +} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/EHCacheRefreshTokenProvider.java ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/EHCacheRefreshTokenProvider.java b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/EHCacheRefreshTokenProvider.java deleted file mode 100644 index 43c72d6..0000000 --- a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/EHCacheRefreshTokenProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.fediz.oidc.idp.example; - -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 OpenId - */ -public class EHCacheRefreshTokenProvider extends DefaultEHCacheCodeDataProvider { - - @Override - public List convertScopeToPermissions(Client client, List requestedScopes) { - if (requestedScopes.isEmpty()) { - return Collections.emptyList(); - } - - List permissions = new ArrayList<>(); - for (String requestedScope : requestedScopes) { - if ("openid".equals(requestedScope)) { - OAuthPermission permission = new OAuthPermission("openid", "Authenticate user"); - permissions.add(permission); - } else { - throw new OAuthServiceException("invalid_scope"); - } - } - - return permissions; - } -} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/IdTokenProviderImpl.java ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/IdTokenProviderImpl.java b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/IdTokenProviderImpl.java index 52f8fa8..a6d1684 100644 --- a/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/IdTokenProviderImpl.java +++ b/systests/federation/oidcIdpWebapp/src/main/java/org/apache/cxf/fediz/oidc/idp/example/IdTokenProviderImpl.java @@ -21,6 +21,7 @@ package org.apache.cxf.fediz.oidc.idp.example; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.UUID; import org.apache.cxf.rs.security.oauth2.common.UserSubject; import org.apache.cxf.rs.security.oidc.common.IdToken; @@ -41,7 +42,9 @@ public class IdTokenProviderImpl implements IdTokenProvider { token.setExpiryTime(cal.getTimeInMillis() / 1000L); token.setIssuedAt(new Date().getTime() / 1000L); token.setAudience(clientId); - token.setSubject(authenticatedUser.getLogin()); + token.setTokenId(UUID.randomUUID().toString()); + token.setSubject(authenticatedUser.getLogin().toLowerCase()); + token.setClaim("preferred_username", authenticatedUser.getLogin().toLowerCase()); token.setIssuer("OIDC IdP"); return token; http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidcIdpWebapp/src/main/resources/clienttrust.jks ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/resources/clienttrust.jks b/systests/federation/oidcIdpWebapp/src/main/resources/clienttrust.jks deleted file mode 100644 index c3ad459..0000000 Binary files a/systests/federation/oidcIdpWebapp/src/main/resources/clienttrust.jks and /dev/null differ http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidcIdpWebapp/src/main/resources/stsKeystoreB.properties ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/resources/stsKeystoreB.properties b/systests/federation/oidcIdpWebapp/src/main/resources/stsKeystoreB.properties deleted file mode 100644 index 16f4a3c..0000000 --- a/systests/federation/oidcIdpWebapp/src/main/resources/stsKeystoreB.properties +++ /dev/null @@ -1,6 +0,0 @@ -org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin -org.apache.ws.security.crypto.merlin.keystore.type=jks -org.apache.ws.security.crypto.merlin.keystore.password=storepass -org.apache.ws.security.crypto.merlin.keystore.alias=realmb -org.apache.ws.security.crypto.merlin.keystore.file=stsrealm_b.jks - http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/cxf-service.xml ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/cxf-service.xml b/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/cxf-service.xml index 4201a96..acc0a9a 100644 --- a/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/cxf-service.xml +++ b/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/cxf-service.xml @@ -77,7 +77,7 @@ - + @@ -96,22 +96,31 @@ - + + + + + + + + - + + - + + http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/views/oAuthAuthorizationData.jsp ---------------------------------------------------------------------- diff --git a/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/views/oAuthAuthorizationData.jsp b/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/views/oAuthAuthorizationData.jsp new file mode 100644 index 0000000..1a71624 --- /dev/null +++ b/systests/federation/oidcIdpWebapp/src/main/webapp/WEB-INF/views/oAuthAuthorizationData.jsp @@ -0,0 +1,133 @@ +<%@ page import="javax.servlet.http.HttpServletRequest" %> +<%@ page import="java.util.List" %> +<%@ page import="org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData" %> +<%@ page import="org.apache.cxf.rs.security.oauth2.common.OAuthPermission" %> + + +<% + OAuthAuthorizationData data = (OAuthAuthorizationData)request.getAttribute("data"); + List authorizedScopes = data.getAlreadyAuthorizedPermissionsAsStrings(); +%> + + + Third Party Authorization Form + + + +

Third Party Authorization Form

+ + + + +
+ +
+ + + <% + if (data.getState() != null) { + %> + + <% + } + %> + <% + if (data.getClientCodeChallenge() != null) { + %> + + <% + } + %> + <% + if (data.getNonce() != null) { + %> + + <% + } + %> + + + + <% + if (data.getRedirectUri() != null) { + %> + + <% + } + %> + + <% + if (data.getApplicationLogoUri() != null) { + %> + Application Logo + <% + } + %> + +

Would you like to grant <%= data.getApplicationName() %>
the following permissions:

+ + + <% + for (OAuthPermission perm : data.getAllPermissions()) { + %> + + + + <% + } + %> +
+ + disabled="disabled" + <% + } + %> + checked="checked" + name="<%= perm.getPermission()%>_status" + value="allow" + ><%= perm.getDescription() %> + <% + if (perm.isDefault()) { + %> + + <% + } + %> +
+

+ + +
+
+ + + http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/785104b7/systests/federation/pom.xml ---------------------------------------------------------------------- diff --git a/systests/federation/pom.xml b/systests/federation/pom.xml index 28e830b..7190b07 100644 --- a/systests/federation/pom.xml +++ b/systests/federation/pom.xml @@ -32,6 +32,7 @@ samlIdpWebapp + oidcIdpWebapp samlsso wsfed