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/08/13 11:57:06 UTC
cxf-fediz git commit: Updated Websphere sample application to fit the
system test requirementd. Added deployment project to build ear file for
websphere deployment.
Repository: cxf-fediz
Updated Branches:
refs/heads/master 92db813b3 -> 34d160e3b
Updated Websphere sample application to fit the system test requirementd. Added deployment project to build ear file for websphere deployment.
Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/34d160e3
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/34d160e3
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/34d160e3
Branch: refs/heads/master
Commit: 34d160e3bf74679ecf3cc9f976ed138430ad2a9f
Parents: 92db813
Author: cschmuelling@talend.com <cs...@talend.com>
Authored: Fri Aug 7 19:55:54 2015 +0200
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Thu Aug 13 10:56:57 2015 +0100
----------------------------------------------------------------------
examples/pom.xml | 10 ++
examples/websphereWebapp/pom.xml | 25 ++++-
.../cxf/fediz/example/FederationServlet.java | 97 +++++++++++---------
examples/websphereWebappEar/README.txt | 14 +++
examples/websphereWebappEar/pom.xml | 83 +++++++++++++++++
5 files changed, 184 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/34d160e3/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 9c353e8..0077c30 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -37,4 +37,14 @@
<module>spring2Webapp</module>
<module>springPreauthWebapp</module>
</modules>
+
+ <profiles>
+ <profile>
+ <id>websphere</id>
+ <modules>
+ <module>websphereWebapp</module>
+ <module>websphereWebappEar</module>
+ </modules>
+ </profile>
+ </profiles>
</project>
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/34d160e3/examples/websphereWebapp/pom.xml
----------------------------------------------------------------------
diff --git a/examples/websphereWebapp/pom.xml b/examples/websphereWebapp/pom.xml
index 9c71f01..c57c8b9 100644
--- a/examples/websphereWebapp/pom.xml
+++ b/examples/websphereWebapp/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.cxf.fediz</groupId>
<artifactId>examples</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<groupId>org.apache.cxf.fediz.examples</groupId>
@@ -54,10 +54,31 @@
<artifactId>commons-lang3</artifactId>
<version>${commons.lang.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>com.ibm.websphere</groupId>
+ <artifactId>com.ibm.websphere.security</artifactId>
+ <version>1.0.3</version>
+ <type>jar</type>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.ibm.ws.security</groupId>
+ <artifactId>com.ibm.ws.security.authentication.tai</artifactId>
+ <version>1.0.3</version>
+ <type>jar</type>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.ibm.ws.security</groupId>
+ <artifactId>com.ibm.ws.security.token</artifactId>
+ <version>1.0.2</version>
+ <type>jar</type>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
- <!-- Name of the generated WAR file -->
<finalName>fedizhelloworld</finalName>
</build>
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/34d160e3/examples/websphereWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
----------------------------------------------------------------------
diff --git a/examples/websphereWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java b/examples/websphereWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
index 13029d9..e7387b3 100644
--- a/examples/websphereWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
+++ b/examples/websphereWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
@@ -21,95 +21,106 @@ package org.apache.cxf.fediz.example;
import java.io.IOException;
import java.io.PrintWriter;
-import java.io.StringWriter;
import java.security.Principal;
import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import javax.security.auth.Subject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Element;
-import org.apache.commons.lang3.StringEscapeUtils;
+import com.ibm.websphere.security.WSSecurityException;
+import com.ibm.websphere.security.auth.WSSubject;
+
import org.apache.cxf.fediz.core.Claim;
import org.apache.cxf.fediz.core.ClaimCollection;
import org.apache.cxf.fediz.core.FedizPrincipal;
import org.apache.cxf.fediz.core.SecurityTokenThreadLocal;
-
+import org.apache.cxf.fediz.core.processor.FedizResponse;
public class FederationServlet extends HttpServlet {
/**
*
*/
+ private static final String SUBJECT_TOKEN_KEY = "_security.token";
+
private static final long serialVersionUID = -9019993850246851112L;
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+ IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
- out.println("<head><title>WS Federation Example</title></head>");
+ out.println("<head><title>WS Federation Systests Examples</title></head>");
out.println("<body>");
- out.println("<h1>Hello World</h1>");
- out.println("Request url: " + request.getRequestURL().toString() + "<p>");
-
+ out.println("<p>Request url: " + request.getRequestURL().toString() + "</p>");
- out.println("<br><b>User</b><p>");
+ out.print("<p>userPrincipal=");
Principal p = request.getUserPrincipal();
if (p != null) {
- out.println("Principal: " + p.getName() + "<p>");
+ out.print(p.getName());
}
+ out.println("</p>");
- out.println("<br><b>Roles</b><p>");
List<String> roleListToCheck = Arrays.asList("Admin", "Manager", "User", "Authenticated");
- for (String item: roleListToCheck) {
- out.println("Has role '" + item + "': " + ((request.isUserInRole(item)) ? "<b>yes</b>" : "no") + "<p>");
+ for (String item : roleListToCheck) {
+ out.println("<p>role:" + item + "=" + ((request.isUserInRole(item)) ? "true" : "false") + "</p>");
}
if (p instanceof FedizPrincipal) {
FedizPrincipal fp = (FedizPrincipal)p;
- out.println("<br><b>Claims</b><p>");
ClaimCollection claims = fp.getClaims();
- for (Claim c: claims) {
- out.println(c.getClaimType().toString() + ": " + c.getValue() + "<p>");
+ for (Claim c : claims) {
+ out.println("<p>" + c.getClaimType().toString() + "=" + c.getValue() + "</p>");
+ }
+
+ Element el = fp.getLoginToken();
+ if (el != null) {
+ out.println("loginToken=FOUND{FedizPrincipal}<p>");
}
- } else {
- out.println("<br>Principal is not instance of FedizPrincipal<p>");
- }
- Element el = SecurityTokenThreadLocal.getToken();
- if (el != null) {
- out.println("<br><b>Bootstrap token</b><p>");
- String token = null;
- try {
- TransformerFactory transFactory = TransformerFactory.newInstance();
- Transformer transformer = transFactory.newTransformer();
- StringWriter buffer = new StringWriter();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.transform(new DOMSource(el),
- new StreamResult(buffer));
- token = buffer.toString();
- out.println("<p>" + StringEscapeUtils.escapeXml11(token));
- } catch (Exception ex) {
- out.println("<p>Failed to transform cached element to string: " + ex.toString());
+ el = SecurityTokenThreadLocal.getToken();
+ if (el != null) {
+ out.println("loginToken=FOUND{SecurityTokenThreadLocal}<p>");
}
- } else {
- out.println("<p>Bootstrap token not cached in thread local storage");
+
}
- out.println("</body>");
+ try {
+ Subject subject = WSSubject.getCallerSubject();
+ if (subject != null) {
+ FedizResponse fedResponse = getCachedFederationResponse(subject);
+
+ ClaimCollection claims = new ClaimCollection(fedResponse.getClaims());
+ for (Claim c : claims) {
+ out.println("<p>" + c.getClaimType().toString() + "=" + c.getValue() + "</p>");
+ }
+ }
+ } catch (WSSecurityException e) {
+ out.println("<p>Exception=" + e.getMessage() + "</p>");
+ }
}
+ private FedizResponse getCachedFederationResponse(Subject subject) {
+ Iterator<?> i = subject.getPublicCredentials().iterator();
+ while (i.hasNext()) {
+ Object o = i.next();
+ if (o instanceof Hashtable) {
+ Map<?, ?> table = (Hashtable<?, ?>)o;
+ return (FedizResponse)table.get(SUBJECT_TOKEN_KEY);
+ }
+ }
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/34d160e3/examples/websphereWebappEar/README.txt
----------------------------------------------------------------------
diff --git a/examples/websphereWebappEar/README.txt b/examples/websphereWebappEar/README.txt
new file mode 100644
index 0000000..cbe86be
--- /dev/null
+++ b/examples/websphereWebappEar/README.txt
@@ -0,0 +1,14 @@
+Simple Web Application Demo
+===========================
+
+This demo shows how to build and deploy an SSO protected using Apache CXF Fediz
+web application.
+
+Running this sample consists of four steps:
+
+- Configure the Tomcat-IDP and Tomcat or Jetty-RP instances
+- Building the demo using Maven
+- Deploying the demo to the RP instance
+- Testing the demo
+
+Please review the README in the samples main directory before continuing.
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/34d160e3/examples/websphereWebappEar/pom.xml
----------------------------------------------------------------------
diff --git a/examples/websphereWebappEar/pom.xml b/examples/websphereWebappEar/pom.xml
new file mode 100644
index 0000000..891ac72
--- /dev/null
+++ b/examples/websphereWebappEar/pom.xml
@@ -0,0 +1,83 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.cxf.fediz</groupId>
+ <artifactId>examples</artifactId>
+ <version>1.2.1-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.cxf.fediz.examples</groupId>
+ <artifactId>websphereWebappEar</artifactId>
+ <name>Fediz Example: WebsphereWebappEar</name>
+ <packaging>ear</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.cxf.fediz.examples</groupId>
+ <artifactId>websphereWebapp</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-ear-plugin</artifactId>
+ <version>2.10.1</version>
+ <configuration>
+ <displayName>Fediz Hello World</displayName>
+ <description>Fediz Hello World demo application.</description>
+ <finalName>fedizhelloworld</finalName>
+ <modules>
+ <webModule>
+ <groupId>org.apache.cxf.fediz.examples</groupId>
+ <artifactId>websphereWebapp</artifactId>
+ <contextRoot>fedizhelloworld</contextRoot>
+ <uri>fedizhelloworld.war</uri>
+ </webModule>
+ </modules>
+ <security>
+ <security-role id="SecurityRole_1311175300750">
+ <role-name>User</role-name>
+ </security-role>
+ <security-role id="SecurityRole_1311175300751">
+ <role-name>Manager</role-name>
+ </security-role>
+ <security-role id="SecurityRole_1311175300752">
+ <role-name>Admin</role-name>
+ </security-role>
+ <security-role id="SecurityRole_1425914835358">
+ <role-name>Authenticated</role-name>
+ </security-role>
+ </security>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>