Author: anil.saldhana(a)jboss.com
Date: 2011-06-13 15:09:04 -0400 (Mon, 13 Jun 2011)
New Revision: 988
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDAttributeMap.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDConstants.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDLifecycle.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDLifecycleEvent.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDManager.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDProtocolAdapter.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDRequest.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDAssociationException.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDConsumerException.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDDiscoveryException.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDGeneralException.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDLifeCycleException.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDMessageException.java
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDProtocolException.java
Log:
openid migration
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDAttributeMap.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDAttributeMap.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDAttributeMap.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -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.picketlink.social.openid.api;
+
+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:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDConstants.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDConstants.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDConstants.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -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.picketlink.social.openid.api;
+
+/**
+ * OpenID URL based Constants
+ * @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:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDLifecycle.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDLifecycle.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDLifecycle.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,56 @@
+/*
+ * 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.picketlink.social.openid.api;
+
+import org.picketlink.social.openid.api.exceptions.OpenIDLifeCycleException;
+
+
+/**
+ * Denotes the lifecycle methods the OpenIDManager
+ * calls back - Consumer Side
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 10, 2009
+ */
+public interface OpenIDLifecycle
+{
+ /**
+ * Handle an openid lifecycle event from
+ * the openid manager
+ * @param event
+ */
+ void handle(OpenIDLifecycleEvent event) throws OpenIDLifeCycleException;
+
+ /**
+ * Handle an array of lifecycle events from the OpenID Manager
+ * @param eventArr
+ * @throws OpenIDLifeCycleException
+ */
+ void handle(OpenIDLifecycleEvent[] eventArr) throws OpenIDLifeCycleException;
+
+ /**
+ * Provide the value for an attribute to
+ * the openid manager
+ * @param name
+ * @return
+ */
+ Object getAttributeValue(String name);
+}
\ No newline at end of file
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDLifecycleEvent.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDLifecycleEvent.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDLifecycleEvent.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,102 @@
+/*
+ * 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.picketlink.social.openid.api;
+
+/**
+ * Events in the lifecycle
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 10, 2009
+ */
+public class OpenIDLifecycleEvent
+{
+ public enum TYPE
+ {
+ SUCCESS("lifecycle"),
+ SESSION("session");
+ private String type;
+
+ TYPE(String type)
+ {
+ this.type = type;
+ }
+
+ public String type()
+ {
+ return type;
+ }
+ }
+
+ public enum OP
+ {
+ ADD,REMOVE;
+ }
+
+ private TYPE eventType;
+ private OP operation;
+ private String attributeName;
+ private Object attributeValue;
+
+ public OpenIDLifecycleEvent(TYPE type, OP operation, String attr, Object val)
+ {
+ this.eventType = type;
+ this.operation = operation;
+ this.attributeName = attr;
+ this.attributeValue = val;
+ }
+
+ /**
+ * Get the type of the event (session, lifecycle etc)
+ * @return
+ */
+ public TYPE getEventType()
+ {
+ return eventType;
+ }
+
+ /**
+ * Get the operation we are dealing with (add,remove)
+ * @return
+ */
+ public OP getOperation()
+ {
+ return this.operation;
+ }
+
+ /**
+ * Return the attribute name that needs
+ * to be dealt at the session level
+ * @return
+ */
+ public String getAttributeName()
+ {
+ return attributeName;
+ }
+
+ /**
+ * Get the attribute value
+ * @return
+ */
+ public Object getAttributeValue()
+ {
+ return attributeValue;
+ }
+}
\ No newline at end of file
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDManager.java
===================================================================
--- social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDManager.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDManager.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,433 @@
+/*
+ * 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.picketlink.social.openid.api;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.openid4java.association.AssociationException;
+import org.openid4java.consumer.ConsumerException;
+import org.openid4java.consumer.ConsumerManager;
+import org.openid4java.consumer.InMemoryConsumerAssociationStore;
+import org.openid4java.consumer.InMemoryNonceVerifier;
+import org.openid4java.consumer.VerificationResult;
+import org.openid4java.discovery.DiscoveryException;
+import org.openid4java.discovery.DiscoveryInformation;
+import org.openid4java.discovery.Identifier;
+import org.openid4java.message.AuthRequest;
+import org.openid4java.message.AuthSuccess;
+import org.openid4java.message.MessageException;
+import org.openid4java.message.ParameterList;
+import org.openid4java.message.ax.FetchRequest;
+import org.openid4java.message.sreg.SRegRequest;
+import org.picketlink.social.openid.api.OpenIDLifecycleEvent.OP;
+import org.picketlink.social.openid.api.OpenIDLifecycleEvent.TYPE;
+import org.picketlink.social.openid.api.exceptions.OpenIDAssociationException;
+import org.picketlink.social.openid.api.exceptions.OpenIDConsumerException;
+import org.picketlink.social.openid.api.exceptions.OpenIDDiscoveryException;
+import org.picketlink.social.openid.api.exceptions.OpenIDLifeCycleException;
+import org.picketlink.social.openid.api.exceptions.OpenIDMessageException;
+import org.picketlink.social.openid.api.exceptions.OpenIDProtocolException;
+
+/**
+ * OpenID Manager for consumers
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDManager
+{
+ public enum CONST
+ {
+ OPENID("openid"),
+ OPENID_CLAIMED("openid-claimed"),
+ OPENID_DISC("openid-discovered");
+
+ private String val;
+ CONST(String val)
+ {
+ this.val = val;
+ }
+ public String get()
+ {
+ return this.val;
+ }
+ }
+
+ 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);
+ }
+ }
+
+ /**
+ * Set the user string
+ * @param userString
+ */
+ public void setUserString(String userString)
+ {
+ this.userString = userString;
+ }
+
+ /**
+ * Get the OpenID Request
+ * @return
+ */
+ public OpenIDRequest getOpenIDRequest()
+ {
+ return this.request;
+ }
+
+ @SuppressWarnings("unchecked")
+ public OpenIDProviderList discoverProviders() throws OpenIDDiscoveryException,
OpenIDConsumerException
+ {
+ // perform discovery on the user-supplied identifier
+ List<DiscoveryInformation> discoveries;
+ try
+ {
+ discoveries = consumerManager.discover(userString);
+ }
+ catch (DiscoveryException e1)
+ {
+ throw new OpenIDDiscoveryException(e1);
+ }
+
+ return new OpenIDProviderList(discoveries);
+ }
+
+ /**
+ * Associate with a list of open id providers
+ * @param adapter Protocol adapter (such as http)
+ * @param listOfProviders (a list of providers from discovery)
+ * @return
+ * @throws OpenIDConsumerException
+ * @throws OpenIDLifeCycleException
+ */
+ public OpenIDProviderInformation associate(OpenIDProtocolAdapter adapter,
+ OpenIDProviderList listOfProviders)
+ throws OpenIDConsumerException, OpenIDLifeCycleException
+ {
+ OpenIDLifecycle lifeCycle = null;
+
+ if(adapter instanceof OpenIDLifecycle)
+ {
+ lifeCycle = (OpenIDLifecycle) adapter;
+ }
+ List<DiscoveryInformation> discoveries = listOfProviders.get();
+
+ 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
+ if(lifeCycle != null)
+ {
+ OpenIDLifecycleEvent ev =new OpenIDLifecycleEvent(TYPE.SESSION,
+ OP.ADD, CONST.OPENID_DISC.get(), discovered);
+ lifeCycle.handle(ev);
+ }
+ return new OpenIDProviderInformation(discovered);
+ }
+
+ /**
+ * Authenticate an user with the provider
+ * @param adapter protocol adapter
+ * @param providerInfo Information about a provider derived from discovery process
+ * @return
+ * @throws OpenIDDiscoveryException
+ * @throws OpenIDConsumerException
+ * @throws OpenIDMessageException
+ * @throws OpenIDProtocolException
+ */
+ @SuppressWarnings("unchecked")
+ public boolean authenticate(OpenIDProtocolAdapter adapter, OpenIDProviderInformation
providerInfo)
+ throws OpenIDDiscoveryException,
+ OpenIDConsumerException, OpenIDMessageException, OpenIDProtocolException
+ {
+ DiscoveryInformation discovered = providerInfo.get();
+
+ // 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 true;
+ }
+ 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;
+ }
+
+ /**
+ * Verify a previously authenticated user with the provider
+ * @param adapter protocol adapter
+ * @param parameterMap request parameters
+ * @param receivedURL url where the response will be received
+ * @return
+ * @throws OpenIDMessageException
+ * @throws OpenIDDiscoveryException
+ * @throws OpenIDAssociationException
+ * @throws OpenIDLifeCycleException
+ */
+ public boolean verify(OpenIDProtocolAdapter adapter, Map<String,String>
parameterMap,
+ String receivedURL) throws OpenIDMessageException,
+ OpenIDDiscoveryException, OpenIDAssociationException, OpenIDLifeCycleException
+ {
+ OpenIDLifecycle lifeCycle = null;
+
+ if(adapter instanceof OpenIDLifecycle)
+ {
+ lifeCycle = (OpenIDLifecycle) adapter;
+ }
+ ParameterList responselist = new ParameterList(parameterMap);
+
+ if(lifeCycle == null)
+ throw new IllegalStateException("Lifecycle not found");
+
+ DiscoveryInformation discovered =
+ (DiscoveryInformation) lifeCycle.getAttributeValue(CONST.OPENID_DISC.get());
+
+ // verify the response; ConsumerManager needs to be the same
+ // (static) instance used to place the authentication request
+ try
+ {
+ VerificationResult verification = this.consumerManager.verify(
+ receivedURL,
+ responselist, discovered);
+
+ // examine the verification result and extract the verified identifier
+ Identifier verified = verification.getVerifiedId();
+ if (verified != null)
+ {
+ AuthSuccess authSuccess =
+ (AuthSuccess) verification.getAuthResponse();
+
+ //Create an lifecycle event array
+ OpenIDLifecycleEvent[] eventArr = new OpenIDLifecycleEvent[]
+ {
+ /**Store the id**/
+ new OpenIDLifecycleEvent(TYPE.SESSION,
+ OP.ADD, CONST.OPENID.get(), authSuccess.getIdentity()),
+
+ /** Store the claimed **/
+ new OpenIDLifecycleEvent(TYPE.SESSION,
+ OP.ADD, CONST.OPENID_CLAIMED.get(), authSuccess.getClaimed()),
+
+ /** Indicate success **/
+ new OpenIDLifecycleEvent(TYPE.SUCCESS,
+ null, null, null)
+ };
+ lifeCycle.handle(eventArr);
+ return true;
+ }
+ }
+ catch (MessageException e)
+ {
+ throw new OpenIDMessageException(e);
+ }
+ catch (DiscoveryException e)
+ {
+ throw new OpenIDDiscoveryException(e);
+ }
+ catch (AssociationException e)
+ {
+ throw new OpenIDAssociationException(e);
+ }
+
+ return false;
+ }
+
+ /**
+ * Log an user out from an openid provider
+ * @param adapter protocol adapter
+ * @throws OpenIDLifeCycleException
+ */
+ public void logout(OpenIDProtocolAdapter adapter) throws OpenIDLifeCycleException
+ {
+ OpenIDLifecycle lifeCycle = null;
+
+ if(adapter instanceof OpenIDLifecycle)
+ {
+ lifeCycle = (OpenIDLifecycle) adapter;
+ }
+ if(lifeCycle != null)
+ {
+ lifeCycle.handle(new OpenIDLifecycleEvent(TYPE.SESSION, OP.REMOVE,
CONST.OPENID.get(), null));
+ lifeCycle.handle(new OpenIDLifecycleEvent(TYPE.SESSION, OP.REMOVE,
CONST.OPENID_CLAIMED.get(), null));
+ }
+ }
+
+ /**
+ * Information about a provider from the
+ * discovery process
+ */
+ public static class OpenIDProviderInformation
+ {
+ private DiscoveryInformation discovered;
+
+ OpenIDProviderInformation(DiscoveryInformation di)
+ {
+ this.discovered = di;
+ }
+
+ DiscoveryInformation get()
+ {
+ return this.discovered;
+ }
+ }
+
+ /**
+ * List of OpenID providers
+ */
+ public static class OpenIDProviderList
+ {
+ private List<DiscoveryInformation> providers = null;
+
+ OpenIDProviderList(List<DiscoveryInformation> providers)
+ {
+ this.providers = providers;
+ }
+
+ void addProvider( DiscoveryInformation provider )
+ {
+ this.providers.add( provider );
+ }
+
+ List<DiscoveryInformation> get()
+ {
+ return Collections.unmodifiableList(providers);
+ }
+
+ public int size()
+ {
+ return this.providers != null ? providers.size() : 0;
+ }
+ }
+}
\ No newline at end of file
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDProtocolAdapter.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDProtocolAdapter.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDProtocolAdapter.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,60 @@
+/*
+ * 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.picketlink.social.openid.api;
+
+import java.util.Map;
+
+import org.picketlink.social.openid.api.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;
+}
\ No newline at end of file
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDRequest.java
===================================================================
--- social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDRequest.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/OpenIDRequest.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,69 @@
+/*
+ * 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.picketlink.social.openid.api;
+
+/**
+ * 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;
+ }
+
+ /**
+ * Get the username (openid url)
+ * @return
+ */
+ public String getURL()
+ {
+ return this.url;
+ }
+
+ /**
+ * Set the username in the form of url
+ * @param url
+ * @return
+ */
+ public OpenIDRequest setURL(String url)
+ {
+ this.url = url;
+ return this;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+
builder.append("[OpenIDRequest:").append(this.url).append("]");
+ return builder.toString();
+ }
+}
\ No newline at end of file
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDAssociationException.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDAssociationException.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDAssociationException.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -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.picketlink.social.openid.api.exceptions;
+
+/**
+ * Exception indicating openid association problems
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 10, 2009
+ */
+public class OpenIDAssociationException extends OpenIDGeneralException
+{
+ private static final long serialVersionUID = 1L;
+
+ public OpenIDAssociationException()
+ {
+ super();
+ }
+
+ public OpenIDAssociationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public OpenIDAssociationException(String msg)
+ {
+ super(msg);
+ }
+
+ public OpenIDAssociationException(Throwable cause)
+ {
+ super(cause);
+ }
+}
\ No newline at end of file
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDConsumerException.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDConsumerException.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDConsumerException.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,53 @@
+/*
+ * 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.picketlink.social.openid.api.exceptions;
+
+
+/**
+ * OpenID Exception at the consumer
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDConsumerException extends OpenIDGeneralException
+{
+ 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:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDDiscoveryException.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDDiscoveryException.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDDiscoveryException.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,53 @@
+/*
+ * 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.picketlink.social.openid.api.exceptions;
+
+
+/**
+ * Discovery of OpenID Provider Exception
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDDiscoveryException extends OpenIDGeneralException
+{
+ 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:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDGeneralException.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDGeneralException.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDGeneralException.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -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.picketlink.social.openid.api.exceptions;
+
+import java.security.GeneralSecurityException;
+
+/**
+ * Base class for all OpenID exceptions
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 10, 2009
+ */
+public class OpenIDGeneralException extends GeneralSecurityException
+{
+ private static final long serialVersionUID = 1L;
+
+ public OpenIDGeneralException()
+ {
+ super();
+ }
+
+ public OpenIDGeneralException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public OpenIDGeneralException(String msg)
+ {
+ super(msg);
+ }
+
+ public OpenIDGeneralException(Throwable cause)
+ {
+ super(cause);
+ }
+}
\ No newline at end of file
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDLifeCycleException.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDLifeCycleException.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDLifeCycleException.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -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.picketlink.social.openid.api.exceptions;
+
+/**
+ * Exception indicating issues during lifecycle handling
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 10, 2009
+ */
+public class OpenIDLifeCycleException extends OpenIDGeneralException
+{
+ private static final long serialVersionUID = 1L;
+
+ public OpenIDLifeCycleException()
+ {
+ super();
+ }
+
+ public OpenIDLifeCycleException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public OpenIDLifeCycleException(String msg)
+ {
+ super(msg);
+ }
+
+ public OpenIDLifeCycleException(Throwable cause)
+ {
+ super(cause);
+ }
+}
\ No newline at end of file
Added:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDMessageException.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDMessageException.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDMessageException.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,53 @@
+/*
+ * 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.picketlink.social.openid.api.exceptions;
+
+
+/**
+ * OpenID exception for message transit
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDMessageException extends OpenIDGeneralException
+{
+ 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:
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDProtocolException.java
===================================================================
---
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDProtocolException.java
(rev 0)
+++
social/trunk/openid/src/main/java/org/picketlink/social/openid/api/exceptions/OpenIDProtocolException.java 2011-06-13
19:09:04 UTC (rev 988)
@@ -0,0 +1,53 @@
+/*
+ * 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.picketlink.social.openid.api.exceptions;
+
+
+/**
+ * Exception indicating a protocol exception
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jul 6, 2009
+ */
+public class OpenIDProtocolException extends OpenIDGeneralException
+{
+ 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);
+ }
+}