Author: anil.saldhana(a)jboss.com
Date: 2009-07-08 12:43:47 -0400 (Wed, 08 Jul 2009)
New Revision: 633
Added:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/servlets/OpenIDYadisServlet.java
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPOpenIDContext.java
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPOpenIDProvider.java
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPProtocolAdaptor.java
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/InMemoryProtocolAdapter.java
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/LocalProviderOpenIDUnitTestCase.java
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/YadisMetadataUnitTestCase.java
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/server/
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/server/EmbeddedWebServerBase.java
identity-federation/trunk/jboss-identity-bindings/src/test/resources/openid/
identity-federation/trunk/jboss-identity-bindings/src/test/resources/openid/localhost-yadis.xml
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDAttributeMap.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDConstants.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDManager.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDProtocolAdapter.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDRequest.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDConsumerException.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDDiscoveryException.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDMessageException.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDProtocolException.java
Modified:
identity-federation/trunk/jboss-identity-bindings/pom.xml
identity-federation/trunk/jboss-identity-fed-api/pom.xml
identity-federation/trunk/jboss-identity-fed-core/pom.xml
identity-federation/trunk/parent/pom.xml
Log:
JBID-131: openid
Modified: identity-federation/trunk/jboss-identity-bindings/pom.xml
===================================================================
--- identity-federation/trunk/jboss-identity-bindings/pom.xml 2009-07-06 17:49:24 UTC (rev
632)
+++ identity-federation/trunk/jboss-identity-bindings/pom.xml 2009-07-08 16:43:47 UTC (rev
633)
@@ -60,6 +60,22 @@
<optional>true</optional>
</dependency>
<dependency>
+ <groupId>nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>3.0.1</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>catalina</artifactId>
<version>6.0.18</version>
@@ -72,6 +88,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>apache-xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.9.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>apache-tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>5.5.12</version>
@@ -108,6 +130,16 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Added:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/servlets/OpenIDYadisServlet.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/servlets/OpenIDYadisServlet.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/servlets/OpenIDYadisServlet.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.bindings.servlets;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Servlet used for Yadis Discovery in OpenID
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 7, 2009
+ */
+public class OpenIDYadisServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ private String yadisResourceFile = "/WEB-INF/openid-yadis.xml";
+ private String yadisURL = null;
+
+ private boolean supportHTTP_HEAD = false; //By default, we support GET
+
+ private InputStream yadisResourceInputStream = null;
+
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+ ServletContext context = config.getServletContext();
+
+ String yadisResourceFileStr =
config.getInitParameter("yadisResourceFile");
+ if(yadisResourceFileStr != null && yadisResourceFileStr.length() > 0)
+ yadisResourceFile = yadisResourceFileStr;
+ log("yadisResourceFile Location="+ yadisResourceFile);
+
+ yadisURL = config.getInitParameter("yadisResourceURL");
+
+ if(yadisURL == null || yadisURL.length() == 0)
+ {
+ yadisResourceInputStream = context.getResourceAsStream(yadisResourceFile);
+ if(yadisResourceInputStream == null)
+ throw new RuntimeException("yadisResourceFile is missing");
+ }
+
+ String supportHead = config.getInitParameter("support_HTTP_HEAD");
+ if(supportHead != null && supportHead.length() > 0)
+ supportHTTP_HEAD = Boolean.parseBoolean(supportHead);
+ }
+
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ if(this.supportHTTP_HEAD)
+ {
+ log("GET not supported as HTTP HEAD has been configured");
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ return;
+ }
+ else
+ {
+ if(yadisResourceInputStream == null)
+ {
+ log("ERROR::yadisResourceInputStream is null");
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ byte[] barr = new byte[1024];
+ for (int i = 0; i < barr.length; i++)
+ {
+ int b = yadisResourceInputStream.read( );
+ if (b == -1) break;
+ barr[i] = (byte) b;
+ }
+
+ resp.setContentType("application/xrds+xml");
+ resp.setStatus(HttpServletResponse.SC_OK);
+ OutputStream os = resp.getOutputStream();
+ os.write(barr);
+ os.flush();
+ os.close();
+ }
+ }
+
+ @Override
+ protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ if(this.supportHTTP_HEAD)
+ {
+ resp.addHeader("X-XRDS-Location", yadisURL);
+ }
+ resp.setStatus(HttpServletResponse.SC_OK);
+ return;
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPOpenIDContext.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPOpenIDContext.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPOpenIDContext.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.bindings.web.openid;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * HTTP Context for OpenID
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class HTTPOpenIDContext
+{
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+ private ServletContext servletContext;
+
+ private String returnURL;
+
+ public HttpServletRequest getRequest()
+ {
+ return request;
+ }
+
+ public HttpServletResponse getResponse()
+ {
+ return response;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return servletContext;
+ }
+
+ public String getReturnURL()
+ {
+ return returnURL;
+ }
+
+ //Setters
+
+ public HTTPOpenIDContext setRequest(HttpServletRequest req)
+ {
+ this.request = req;
+ return this;
+ }
+
+ public HTTPOpenIDContext setResponse(HttpServletResponse resp)
+ {
+ this.response = resp;
+ return this;
+ }
+
+ public HTTPOpenIDContext setServletContext(ServletContext sctx)
+ {
+ this.servletContext = sctx;
+ return this;
+ }
+
+ public HTTPOpenIDContext setReturnURL(String url)
+ {
+ this.returnURL = url;
+ return this;
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPOpenIDProvider.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPOpenIDProvider.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPOpenIDProvider.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.bindings.web.openid;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.openid4java.message.AuthSuccess;
+import org.openid4java.message.DirectError;
+import org.openid4java.message.Message;
+import org.openid4java.message.ParameterList;
+import org.openid4java.server.InMemoryServerAssociationStore;
+import org.openid4java.server.ServerManager;
+
+/**
+ * Common code at an OpenID Provider
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 7, 2009
+ */
+public class HTTPOpenIDProvider
+{
+ public String process(HttpServletRequest request, HttpServletResponse response)
+ throws IOException
+ {
+ HttpSession session = request.getSession();
+
+ ServerManager manager=new ServerManager();
+ manager.setSharedAssociations(new InMemoryServerAssociationStore());
+ manager.setPrivateAssociations(new InMemoryServerAssociationStore());
+ manager.setOPEndpointUrl(request.getScheme() + "://"
+ + request.getServerName() + ":"
+ + request.getServerPort() + "/simple-openid/provider.jsp");
+
+ ParameterList requestp;
+
+ if ("complete".equals(request.getParameter("_action"))) //
Completing the authz and authn process by redirecting here
+ {
+ requestp=(ParameterList) session.getAttribute("parameterlist"); // On
a redirect from the OP authn & authz sequence
+ }
+ else
+ {
+ requestp = new ParameterList(request.getParameterMap());
+ }
+
+ String mode = requestp.hasParameter("openid.mode") ?
+ requestp.getParameterValue("openid.mode") : null;
+
+ Message responsem;
+ String responseText;
+
+ if ("associate".equals(mode))
+ {
+ // --- process an association request ---
+ responsem = manager.associationResponse(requestp);
+ responseText = responsem.keyValueFormEncoding();
+ }
+ else if ("checkid_setup".equals(mode)
+ || "checkid_immediate".equals(mode))
+ {
+ // interact with the user and obtain data needed to continue
+ //List userData = userInteraction(requestp);
+ String userSelectedId = null;
+ String userSelectedClaimedId = null;
+ Boolean authenticatedAndApproved = Boolean.FALSE;
+
+ if ((session.getAttribute("authenticatedAndApproved") == null)
||
+
(((Boolean)session.getAttribute("authenticatedAndApproved")) == Boolean.FALSE)
)
+ {
+ session.setAttribute("parameterlist", requestp);
+ response.sendRedirect("provider_authorization.jsp");
+ }
+ else
+ {
+ userSelectedId = (String)
session.getAttribute("openid.claimed_id");
+ userSelectedClaimedId = (String)
session.getAttribute("openid.identity");
+ authenticatedAndApproved = (Boolean)
session.getAttribute("authenticatedAndApproved");
+ // Remove the parameterlist so this provider can accept requests from
elsewhere
+ session.removeAttribute("parameterlist");
+ session.setAttribute("authenticatedAndApproved",
Boolean.FALSE); // Makes you authorize each and every time
+ }
+
+ // --- process an authentication request ---
+ responsem = manager.authResponse(requestp,
+ userSelectedId,
+ userSelectedClaimedId,
+ authenticatedAndApproved.booleanValue());
+
+ // caller will need to decide which of the following to use:
+ // - GET HTTP-redirect to the return_to URL
+ // - HTML FORM Redirection
+ //responseText = response.wwwFormEncoding();
+ if (responsem instanceof AuthSuccess)
+ {
+ response.sendRedirect(((AuthSuccess)
responsem).getDestinationUrl(true));
+ return "";
+ }
+ else
+ {
+
responseText="<pre>"+responsem.keyValueFormEncoding()+"</pre>";
+ }
+ }
+ else if ("check_authentication".equals(mode))
+ {
+ // --- processing a verification request ---
+ responsem = manager.verify(requestp);
+ responseText = responsem.keyValueFormEncoding();
+ }
+ else
+ {
+ // --- error response ---
+ responsem = DirectError.createDirectError("Unknown request");
+ responseText = responsem.keyValueFormEncoding();
+ }
+
+
+
+ return responseText != null ? responseText.trim() : null;
+ }
+
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPProtocolAdaptor.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPProtocolAdaptor.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/web/openid/HTTPProtocolAdaptor.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,146 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.bindings.web.openid;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.identity.federation.api.openid.OpenIDAttributeMap;
+import org.jboss.identity.federation.api.openid.OpenIDProtocolAdapter;
+import org.jboss.identity.federation.api.openid.exceptions.OpenIDProtocolException;
+
+/**
+ * Protocol adapter for HTTP
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class HTTPProtocolAdaptor implements OpenIDProtocolAdapter
+{
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+ private ServletContext servletContext;
+ private String returnURL;
+
+ public HTTPProtocolAdaptor(HTTPOpenIDContext octx)
+ {
+ if(octx == null)
+ throw new IllegalArgumentException("http openid context is null");
+ this.request = octx.getRequest();
+ this.response = octx.getResponse();
+ this.servletContext = octx.getServletContext();
+ this.returnURL = octx.getReturnURL();
+ }
+
+ public OpenIDAttributeMap getAttributeMap()
+ {
+ OpenIDAttributeMap map = new OpenIDAttributeMap();
+ if ("1".equals(request.getParameter("nickname")))
+ {
+ map.put("nickname", "1");
+ }
+ if ("1".equals(request.getParameter("email")))
+ {
+ map.put("email", "1");
+ }
+ if ("1".equals(request.getParameter("fullname")))
+ {
+ map.put("fullname", "1");
+ }
+ if ("1".equals(request.getParameter("dob")))
+ {
+ map.put("dob", "1");
+ }
+ if ("1".equals(request.getParameter("gender")))
+ {
+ map.put("gender", "1");
+ }
+ if ("1".equals(request.getParameter("postcode")))
+ {
+ map.put("postcode", "1");
+ }
+ if ("1".equals(request.getParameter("country")))
+ {
+ map.put("country", "1");
+ }
+ if ("1".equals(request.getParameter("language")))
+ {
+ map.put("language", "1");
+ }
+ if ("1".equals(request.getParameter("timezone")))
+ {
+ map.put("timezone", "1");
+ }
+
+ return map;
+ }
+
+ public String getReturnURL()
+ {
+ return this.returnURL;
+ }
+
+ public void registerSessionAttribute(String attribute, Object value)
+ {
+ request.getSession().setAttribute(attribute, value);
+ }
+
+ public void sendToProvider(int version, String destinationURL,
+ Map<String, String> paramMap) throws OpenIDProtocolException
+ {
+ if(version == 1)
+ {
+ try
+ {
+ response.sendRedirect(destinationURL);
+ return;
+ }
+ catch (IOException e)
+ {
+ throw new OpenIDProtocolException(e);
+ }
+ }
+
+ //Version != 1
+ RequestDispatcher dispatcher = servletContext
+ .getRequestDispatcher("/formredirection.jsp");
+ request.setAttribute("parameterMap", request.getParameterMap());
+ request.setAttribute("message", paramMap);
+ try
+ {
+ dispatcher.forward(request, response);
+ }
+ catch (ServletException e)
+ {
+ throw new OpenIDProtocolException(e);
+ }
+ catch (IOException e)
+ {
+ throw new OpenIDProtocolException(e);
+ }
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/InMemoryProtocolAdapter.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/InMemoryProtocolAdapter.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/InMemoryProtocolAdapter.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.bindings.openid;
+
+import java.util.Map;
+
+import org.jboss.identity.federation.api.openid.OpenIDAttributeMap;
+import org.jboss.identity.federation.api.openid.OpenIDProtocolAdapter;
+import org.jboss.identity.federation.api.openid.exceptions.OpenIDProtocolException;
+
+/**
+ * Adapter that is in memory or the same VM
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 7, 2009
+ */
+public class InMemoryProtocolAdapter implements OpenIDProtocolAdapter
+{
+ public OpenIDAttributeMap getAttributeMap()
+ {
+ return new OpenIDAttributeMap();
+ }
+
+ public String getReturnURL()
+ {
+ return "http://localhost/";
+ }
+
+ public void registerSessionAttribute(String attribute, Object value)
+ {
+ }
+
+ public void sendToProvider(int version, String destinationURL, Map<String,
String> paramMap)
+ throws OpenIDProtocolException
+ {
+ System.out.println("Version="+ version);
+ System.out.println("destinationURL="+ destinationURL);
+ System.out.println("paramMap="+ paramMap);
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/LocalProviderOpenIDUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/LocalProviderOpenIDUnitTestCase.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/LocalProviderOpenIDUnitTestCase.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,189 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.bindings.openid;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.identity.federation.api.openid.OpenIDManager;
+import org.jboss.identity.federation.api.openid.OpenIDRequest;
+import org.jboss.test.identity.federation.bindings.server.EmbeddedWebServerBase;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.openid4java.message.AuthSuccess;
+import org.openid4java.message.DirectError;
+import org.openid4java.message.Message;
+import org.openid4java.message.ParameterList;
+import org.openid4java.server.InMemoryServerAssociationStore;
+import org.openid4java.server.ServerManager;
+
+/**
+ * Test the OpenID functionality within the VM
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 7, 2009
+ */
+public class LocalProviderOpenIDUnitTestCase extends EmbeddedWebServerBase
+{
+ protected void establishUserApps()
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream is = tcl.getResourceAsStream("openid/localhost-yadis.xml");
+
+ assertNotNull("Yadis descriptor not null", is);
+
+ Context context = new Context(server,"/",Context.SESSIONS);
+ context.addServlet(new ServletHolder(new YadisServlet(is)), "/*");
+
+ context.addServlet(new ServletHolder(new ProviderServlet()),
"/provider/");
+ }
+
+ public void testOpenIDAuth() throws Exception
+ {
+ //String username = "http://jbosstest.myopenid.com";
+ String username = "http://localhost:11080";
+ InMemoryProtocolAdapter ad = new InMemoryProtocolAdapter();
+ OpenIDRequest openIDRequest = new OpenIDRequest(username);
+ OpenIDManager idm = new OpenIDManager(openIDRequest);
+ List<?> providers = idm.discoverProviders();
+ assertNotNull("List of providers is not null", providers);
+
+ idm.authenticate(ad, providers);
+ }
+
+ //A provider servlet that always returns true
+ private class ProviderServlet extends HttpServlet
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ doGet(req, resp);
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ ParameterList requestP = new ParameterList(req.getParameterMap());
+
+ ServerManager manager = new ServerManager();
+ manager.setSharedAssociations(new InMemoryServerAssociationStore());
+ manager.setPrivateAssociations(new InMemoryServerAssociationStore());
+ manager.setOPEndpointUrl("http://localhost:11080/provider/");
+
+ String userSelectedId = "http://test.localhost:11080";
+ String userSelectedClaimedId = userSelectedId;
+ boolean authenticatedAndApproved = true;
+
+ String responseText = "";
+
+ String mode = requestP.hasParameter("openid.mode") ?
+ requestP.getParameterValue("openid.mode") : null;
+
+ Message responsem ;
+ if ("associate".equals(mode))
+ {
+ // --- process an association request ---
+ responsem = manager.associationResponse(requestP);
+ responseText = responsem.keyValueFormEncoding().trim();
+ }
+ else if ("checkid_setup".equals(mode)
+ || "checkid_immediate".equals(mode))
+ {
+ responsem = manager.authResponse(requestP,
+ userSelectedId,
+ userSelectedClaimedId,
+ authenticatedAndApproved );
+
+ if (responsem instanceof AuthSuccess)
+ {
+ resp.sendRedirect(((AuthSuccess) responsem).getDestinationUrl(true));
+ return;
+ }
+ else
+ {
+
responseText="<pre>"+responsem.keyValueFormEncoding().trim()+"</pre>";
+ }
+ }
+ else if ("check_authentication".equals(mode))
+ {
+ // --- processing a verification request ---
+ responsem = manager.verify(requestP);
+ responseText = responsem.keyValueFormEncoding().trim();
+ }
+ else
+ {
+ // --- error response ---
+ responsem = DirectError.createDirectError("Unknown request");
+ responseText = responsem.keyValueFormEncoding().trim();
+ }
+
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.getWriter().print(responseText);
+ }
+ }
+
+ //A Yadis servlet that just reads the XML from the Inputstream and passes it back
+ private class YadisServlet extends HttpServlet
+ {
+ private static final long serialVersionUID = 1L;
+
+ private InputStream yadisDescriptor;
+
+ public YadisServlet(InputStream yadisDescriptor)
+ {
+ if(yadisDescriptor == null)
+ throw new RuntimeException("input stream null");
+ this.yadisDescriptor = yadisDescriptor;
+ }
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse resp)
+ throws ServletException, IOException
+ {
+ if("HEAD".equals(request.getMethod()))
+ {
+ resp.setStatus(HttpServletResponse.SC_OK);
+ return;
+ }
+ //Asking for Yadis discovery
+ byte[] barr = new byte[1024];
+ for (int i = 0; i < barr.length; i++)
+ {
+ int b = yadisDescriptor.read();
+ if (b == -1) break;
+ barr[i] = (byte) b;
+ }
+ resp.setContentType("application/xrds+xml");
+ resp.setStatus(HttpServletResponse.SC_OK);
+
+ String ycontent = new String(barr);
+ ycontent = ycontent.replace("\n"," ").trim();
+ resp.getWriter().print(ycontent);
+ }
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/YadisMetadataUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/YadisMetadataUnitTestCase.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/openid/YadisMetadataUnitTestCase.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.bindings.openid;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.identity.federation.api.openid.OpenIDManager;
+import org.jboss.identity.federation.api.openid.OpenIDRequest;
+import org.jboss.identity.federation.bindings.servlets.OpenIDYadisServlet;
+import org.jboss.test.identity.federation.bindings.server.EmbeddedWebServerBase;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+
+/**
+ * Unit test the OpenID Yadis Servlet
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 7, 2009
+ */
+public class YadisMetadataUnitTestCase extends EmbeddedWebServerBase
+{
+ protected void establishUserApps()
+ {
+ Context context = new Context(server,"/",Context.SESSIONS);
+ ServletHolder servletHolder = new ServletHolder(new OpenIDYadisServlet());
+ servletHolder.setInitParameter("support_HTTP_HEAD", "true");
+ servletHolder.setInitParameter("yadisResourceURL",
"http://localhost:11080/yadis");
+
+ context.addServlet(servletHolder, "/*");
+
+ context.addServlet(new ServletHolder( new TestYadisResourceServlet()),
"/yadis");
+ }
+
+ public void testYadisDiscovery() throws Exception
+ {
+ //String username = "http://jbosstest.myopenid.com";
+ String username = "http://localhost:11080";
+
+ OpenIDRequest openIDRequest = new OpenIDRequest(username);
+ OpenIDManager idm = new OpenIDManager(openIDRequest);
+
+ List<?> providers = idm.discoverProviders();
+ assertNotNull("Providers list is not null", providers);
+ assertEquals("1 provider", 1, providers.size());
+ }
+
+ /**
+ * Servlet that just outputs an Yadis resource
+ */
+ private class TestYadisResourceServlet extends HttpServlet
+ {
+ private static final long serialVersionUID = 1L;
+
+ String yadis = "<xrds:XRDS "+
+ " xmlns:xrds=\'xri://$xrds\' " +
+ "
xmlns:openid=\'http://openid.net/xmlns/1.0\'"
+
+ " xmlns=\'xri://$xrd*($v*2.0)\'>" +
+ "<XRD>" +
+ " <Service priority=\'0\'>" +
+ "
<
Type>http://openid.net/signon/1.0</Type>" +
+ " <URI>http://localhost/provider.jsp</URI>"
+
+ " </Service>"+
+ "</XRD>" +
+ "</xrds:XRDS>";
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ resp.setContentType("application/xrds+xml");
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.getWriter().print(yadis);
+ }
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/server/EmbeddedWebServerBase.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/server/EmbeddedWebServerBase.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/server/EmbeddedWebServerBase.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.bindings.server;
+
+import junit.framework.TestCase;
+
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.bio.SocketConnector;
+
+/**
+ * Base class for embedded web server based tests
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 8, 2009
+ */
+public abstract class EmbeddedWebServerBase extends TestCase
+{
+ protected Server server = null;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ //Start the Jetty embedded container
+ server = new Server();
+
+ server.setConnectors(getConnectors());
+
+ this.establishUserApps();
+
+ server.start();
+ }
+
+ public void tearDown() throws Exception
+ {
+ if(server != null)
+ {
+ server.stop();
+ server.destroy();
+ server = null;
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Return the connectors that need to be configured
+ * on the server. Subclasses can create as many connectors
+ * as they want
+ * @return
+ */
+ protected Connector[] getConnectors()
+ {
+ Connector connector=new SocketConnector();
+ connector.setPort(11080);
+ return new Connector[]{connector};
+ }
+
+ /**
+ * Establish the user applications - context, servlets etc
+ */
+ protected abstract void establishUserApps();
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/resources/openid/localhost-yadis.xml
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/resources/openid/localhost-yadis.xml
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/resources/openid/localhost-yadis.xml 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,10 @@
+<xrds:XRDS xmlns:xrds="xri://$xrds"
+
xmlns:openid="http://openid.net/xmlns/1.0"
+ xmlns="xri://$xrd*($v*2.0)">
+ <XRD>
+ <Service priority="0">
+ <
Type>http://openid.net/signon/1.0</Type>
+ <URI>http://localhost:11080/provider/</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>
\ No newline at end of file
Modified: identity-federation/trunk/jboss-identity-fed-api/pom.xml
===================================================================
--- identity-federation/trunk/jboss-identity-fed-api/pom.xml 2009-07-06 17:49:24 UTC (rev
632)
+++ identity-federation/trunk/jboss-identity-fed-api/pom.xml 2009-07-08 16:43:47 UTC (rev
633)
@@ -63,6 +63,15 @@
<version>2.1.1</version>
</dependency>
<dependency>
+ <groupId>org.openid4java</groupId>
+ <artifactId>openid4java</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0</version>
@@ -84,6 +93,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>apache-xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.9.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDAttributeMap.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDAttributeMap.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDAttributeMap.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid;
+
+import java.util.HashMap;
+
+/**
+ * Attribute Map to be retrieved from the OpenID Provider
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDAttributeMap extends HashMap<String, String>
+{
+ private static final long serialVersionUID = 1L;
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDConstants.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDConstants.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDConstants.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid;
+
+/**
+ * OpenIDConstants
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 7, 2009
+ */
+public enum OpenIDConstants
+{
+
EMAIL("http://schema.openid.net/contact/email"),
+
FULLNAME("http://schema.openid.net/contact/fullname"),
+
DOB("http://schema.openid.net/contact/dob"),
+
GENDER("http://schema.openid.net/contact/gender"),
+
POSTCODE("http://schema.openid.net/contact/postcode"),
+
COUNTRY("http://schema.openid.net/contact/country"),
+
LANGUAGE("http://schema.openid.net/contact/language"),
+
TIMEZONE("http://schema.openid.net/contact/timezone");
+
+ private String constantURL;
+
+ private OpenIDConstants(String url)
+ {
+ this.constantURL = url;
+ }
+
+ public String url()
+ {
+ return this.constantURL;
+ }
+}
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDManager.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDManager.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDManager.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,201 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid;
+
+import java.util.List;
+
+import org.jboss.identity.federation.api.openid.exceptions.OpenIDConsumerException;
+import org.jboss.identity.federation.api.openid.exceptions.OpenIDDiscoveryException;
+import org.jboss.identity.federation.api.openid.exceptions.OpenIDMessageException;
+import org.jboss.identity.federation.api.openid.exceptions.OpenIDProtocolException;
+import org.openid4java.consumer.ConsumerException;
+import org.openid4java.consumer.ConsumerManager;
+import org.openid4java.consumer.InMemoryConsumerAssociationStore;
+import org.openid4java.consumer.InMemoryNonceVerifier;
+import org.openid4java.discovery.DiscoveryException;
+import org.openid4java.discovery.DiscoveryInformation;
+import org.openid4java.message.AuthRequest;
+import org.openid4java.message.MessageException;
+import org.openid4java.message.ax.FetchRequest;
+import org.openid4java.message.sreg.SRegRequest;
+
+/**
+ * OpenID Manager
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDManager
+{
+ private OpenIDRequest request = null;
+
+ private ConsumerManager consumerManager = null;
+
+ private String userString = null;
+
+ public OpenIDManager(OpenIDRequest theReq)
+ {
+ this.request = theReq;
+ try
+ {
+ consumerManager = new ConsumerManager();
+ consumerManager.setAssociations(new InMemoryConsumerAssociationStore());
+ consumerManager.setNonceVerifier(new InMemoryNonceVerifier(5000));
+ userString = request.getURL();
+ }
+ catch(ConsumerException ce)
+ {
+ throw new RuntimeException(ce);
+ }
+ }
+
+ public List<?> discoverProviders() throws OpenIDDiscoveryException,
OpenIDConsumerException
+ {
+ // perform discovery on the user-supplied identifier
+ List<?> discoveries;
+ try
+ {
+ discoveries = consumerManager.discover(userString);
+ }
+ catch (DiscoveryException e1)
+ {
+ throw new OpenIDDiscoveryException(e1);
+ }
+
+ return discoveries;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean authenticate(OpenIDProtocolAdapter adapter, List<?> discoveries)
+ throws OpenIDDiscoveryException,
+ OpenIDConsumerException, OpenIDMessageException, OpenIDProtocolException
+ {
+
+ if(discoveries.size() == 0)
+ throw new OpenIDConsumerException("No open id endpoints discovered");
+
+ // attempt to associate with the OpenID provider
+ // and retrieve one service endpoint for authentication
+ DiscoveryInformation discovered = consumerManager.associate(discoveries);
+
+ // store the discovery information in the user's session for later use
+ // leave out for stateless operation / if there is no session
+ adapter.registerSessionAttribute("openid-dsc", discovered);
+
+ // obtain a AuthRequest message to be sent to the OpenID provider
+ try
+ {
+ AuthRequest authReq = consumerManager.authenticate(discovered,
+ adapter.getReturnURL());
+
+ // Attribute Exchange example: fetching the 'email' attribute
+ FetchRequest fetch = FetchRequest.createFetchRequest();
+ SRegRequest sregReq = SRegRequest.createFetchRequest();
+
+ OpenIDAttributeMap amap = adapter.getAttributeMap();
+
+ if ("1".equals(amap.get("nickname")))
+ {
+ // fetch.addAttribute("nickname",
+ // "http://schema.openid.net/contact/nickname", false);
+ sregReq.addAttribute("nickname", false);
+ }
+
+ if ("1".equals(amap.get("email")))
+ {
+ fetch.addAttribute("email",OpenIDConstants.EMAIL.url(), false);
+ sregReq.addAttribute("email", false);
+ }
+
+ if ("1".equals(amap.get("fullname")))
+ {
+ fetch.addAttribute("fullname",OpenIDConstants.FULLNAME.url(),
false);
+ sregReq.addAttribute("fullname", false);
+ }
+ if ("1".equals(amap.get("dob")))
+ {
+ fetch.addAttribute("dob",OpenIDConstants.DOB.url(), true);
+ sregReq.addAttribute("dob", false);
+ }
+
+ if ("1".equals(amap.get("gender")))
+ {
+ fetch.addAttribute("gender",OpenIDConstants.GENDER.url(), false);
+ sregReq.addAttribute("gender", false);
+ }
+
+ if ("1".equals(amap.get("postcode")))
+ {
+ fetch.addAttribute("postcode",OpenIDConstants.POSTCODE.url(),
false);
+ sregReq.addAttribute("postcode", false);
+ }
+
+ if ("1".equals(amap.get("country")))
+ {
+ fetch.addAttribute("country",OpenIDConstants.COUNTRY.url(),
false);
+ sregReq.addAttribute("country", false);
+ }
+
+ if ("1".equals(amap.get("language")))
+ {
+ fetch.addAttribute("language",
OpenIDConstants.LANGUAGE.url(),false);
+ sregReq.addAttribute("language", false);
+ }
+
+ if ("1".equals(amap.get("timezone")))
+ {
+ fetch.addAttribute("timezone", OpenIDConstants.TIMEZONE.url(),
false);
+ sregReq.addAttribute("timezone", false);
+ }
+
+
+ // attach the extension to the authentication request
+ if (!sregReq.getAttributes().isEmpty())
+ {
+ authReq.addExtension(sregReq);
+ }
+
+ if (!discovered.isVersion2())
+ {
+ // Option 1: GET HTTP-redirect to the OpenID Provider endpoint
+ // The only method supported in OpenID 1.x
+ // redirect-URL usually limited ~2048 bytes
+ adapter.sendToProvider(1, authReq.getDestinationUrl(true), null);
+ return false;
+ }
+ else
+ {
+ // Option 2: HTML FORM Redirection (Allows payloads >2048 bytes)
+ adapter.sendToProvider(2, authReq.getDestinationUrl(false),
+ authReq.getParameterMap());
+ }
+ }
+ catch (MessageException e)
+ {
+ throw new OpenIDMessageException(e);
+ }
+ catch (ConsumerException e)
+ {
+ throw new OpenIDConsumerException(e);
+ }
+ return false;
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDProtocolAdapter.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDProtocolAdapter.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDProtocolAdapter.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid;
+
+import java.util.Map;
+
+import org.jboss.identity.federation.api.openid.exceptions.OpenIDProtocolException;
+
+/**
+ * Callback adapter sent to the OpenIDManager
+ * that implements the protocol behavior
+ * such as HTTP
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public interface OpenIDProtocolAdapter
+{
+ /**
+ * Map of attributes to be retrieved from the provider
+ * @return
+ */
+ OpenIDAttributeMap getAttributeMap();
+
+ /**
+ * Provide the return url for the OpenIDManager where the
+ * Relying Party can handle responses from the OpenID Provider
+ * @return
+ */
+ String getReturnURL();
+
+ /**
+ * Send the request to the OpenID Provider
+ * @param version OpenID version 1 is via HTTP Redirect
+ * and by HTTP Post for version 2
+ * @param destinationURL Final Destination URL
+ * @param paramMap Map of parameters
+ */
+ void sendToProvider(int version, String destinationURL,
+ Map<String,String> paramMap) throws OpenIDProtocolException;
+
+ /**
+ * The OpenIDManager sends attributes for registration in
+ * user session such as HttpSession
+ * @param attribute
+ * @param value
+ */
+ void registerSessionAttribute(String attribute, Object value);
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDRequest.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDRequest.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/OpenIDRequest.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid;
+
+/**
+ * Represents an OpenID request
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDRequest
+{
+ private String url;
+
+ public OpenIDRequest()
+ {
+ }
+
+ public OpenIDRequest(String url)
+ {
+ this.url = url;
+ }
+
+ public String getURL()
+ {
+ return this.url;
+ }
+
+ public OpenIDRequest serURL(String url)
+ {
+ this.url = url;
+ return this;
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDConsumerException.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDConsumerException.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDConsumerException.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid.exceptions;
+
+import java.security.GeneralSecurityException;
+
+/**
+ * OpenID Exception at the consumer
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDConsumerException extends GeneralSecurityException
+{
+ private static final long serialVersionUID = 1L;
+
+ public OpenIDConsumerException()
+ {
+ super();
+ }
+
+ public OpenIDConsumerException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public OpenIDConsumerException(String msg)
+ {
+ super(msg);
+ }
+
+ public OpenIDConsumerException(Throwable cause)
+ {
+ super(cause);
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDDiscoveryException.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDDiscoveryException.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDDiscoveryException.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid.exceptions;
+
+import java.security.GeneralSecurityException;
+
+/**
+ * Discovery of OpenID Provider Exception
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDDiscoveryException extends GeneralSecurityException
+{
+ private static final long serialVersionUID = 1L;
+
+ public OpenIDDiscoveryException()
+ {
+ super();
+ }
+
+ public OpenIDDiscoveryException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public OpenIDDiscoveryException(String msg)
+ {
+ super(msg);
+ }
+
+ public OpenIDDiscoveryException(Throwable cause)
+ {
+ super(cause);
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDMessageException.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDMessageException.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDMessageException.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid.exceptions;
+
+import java.security.GeneralSecurityException;
+
+/**
+ * OpenID exception for message transit
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDMessageException extends GeneralSecurityException
+{
+ private static final long serialVersionUID = 1L;
+
+ public OpenIDMessageException()
+ {
+ super();
+ }
+
+ public OpenIDMessageException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public OpenIDMessageException(String msg)
+ {
+ super(msg);
+ }
+
+ public OpenIDMessageException(Throwable cause)
+ {
+ super(cause);
+ }
+}
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDProtocolException.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDProtocolException.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/openid/exceptions/OpenIDProtocolException.java 2009-07-08
16:43:47 UTC (rev 633)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.api.openid.exceptions;
+
+import java.security.GeneralSecurityException;
+
+/**
+ * Exception indicating a protocol exception
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDProtocolException extends GeneralSecurityException
+{
+ private static final long serialVersionUID = 1L;
+
+ public OpenIDProtocolException()
+ {
+ super();
+ }
+
+ public OpenIDProtocolException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public OpenIDProtocolException(String msg)
+ {
+ super(msg);
+ }
+
+ public OpenIDProtocolException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Modified: identity-federation/trunk/jboss-identity-fed-core/pom.xml
===================================================================
--- identity-federation/trunk/jboss-identity-fed-core/pom.xml 2009-07-06 17:49:24 UTC (rev
632)
+++ identity-federation/trunk/jboss-identity-fed-core/pom.xml 2009-07-08 16:43:47 UTC (rev
633)
@@ -53,6 +53,10 @@
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
+ <groupId>org.openid4java</groupId>
+ <artifactId>openid4java</artifactId>
+ </dependency>
+ <dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0</version>
Modified: identity-federation/trunk/parent/pom.xml
===================================================================
--- identity-federation/trunk/parent/pom.xml 2009-07-06 17:49:24 UTC (rev 632)
+++ identity-federation/trunk/parent/pom.xml 2009-07-08 16:43:47 UTC (rev 633)
@@ -136,6 +136,29 @@
<artifactId>jbossxacml</artifactId>
<version>2.0.3.SP2</version>
</dependency>
+ <dependency>
+ <groupId>org.openid4java</groupId>
+ <artifactId>openid4java</artifactId>
+ <version>0.9.5</version>
+ </dependency>
+ <dependency>
+ <groupId>nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <version>1.9.12</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>6.1.18</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>6.1.18</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>