Author: prabath
Date: Mon Dec 17 10:21:09 2007
New Revision: 11289

Log:

added support for OpenID Infocard submit

Added:
   
branches/solutions/identity/openid-poc/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIdInfoCardSubmitAction.java

Added: 
branches/solutions/identity/openid-poc/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIdInfoCardSubmitAction.java
==============================================================================
--- (empty file)
+++ 
branches/solutions/identity/openid-poc/modules/user-ui/src/main/java/org/wso2/solutions/identity/user/ui/action/OpenIdInfoCardSubmitAction.java
     Mon Dec 17 10:21:09 2007
@@ -0,0 +1,161 @@
+package org.wso2.solutions.identity.user.ui.action;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.struts2.StrutsStatics;
+import org.openid4java.OpenIDException;
+import org.openid4java.consumer.ConsumerManager;
+import org.openid4java.consumer.VerificationResult;
+import org.openid4java.discovery.DiscoveryInformation;
+import org.openid4java.discovery.Identifier;
+import org.openid4java.infocard.InfocardException;
+import org.openid4java.infocard.OpenIDToken;
+import org.openid4java.message.AuthSuccess;
+import org.openid4java.message.Message;
+import org.openid4java.message.MessageException;
+import org.openid4java.message.MessageExtension;
+import org.openid4java.message.ParameterList;
+import org.openid4java.message.ax.AxMessage;
+import org.openid4java.message.ax.FetchResponse;
+import org.wso2.solutions.identity.IdentityConstants;
+import org.wso2.solutions.identity.admin.RegisteredInfoCardInfoAdmin;
+import org.wso2.solutions.identity.admin.ReportAdmin;
+import org.wso2.solutions.identity.persistence.dataobject.ActionDO;
+import 
org.wso2.solutions.identity.persistence.dataobject.RegisteredInfoCardInfoDO;
+import org.wso2.solutions.identity.relyingparty.TokenVerifierConstants;
+import org.wso2.solutions.identity.user.ui.UIConstants;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionSupport;
+
+public class OpenIdInfoCardSubmitAction extends ActionSupport {
+
+       private static final long serialVersionUID = 264026108621800214L;
+
+       private static final String LOGGEDIN = "loggedin";
+
+       private ConsumerManager consumerManager = null;
+
+       // attribute typeUri -> "nice label / alias"
+       private static HashMap<String, String> attributes = new HashMap<String, 
String>();
+
+       static {
+               attributes.put("http://axschema.org/contact/email";, "Email");
+               attributes.put("http://axschema.org/namePerson/first";, 
"FirstName");
+               attributes.put("http://axschema.org/namePerson/last";, 
"LastName");
+               attributes.put("http://axschema.org/contact/phone/default";, 
"Phone");
+               attributes.put("http://axschema.org/contact/postalAddress/home";,
+                               "Address");
+               attributes.put("http://axschema.org/contact/city/home";, "City");
+               attributes
+                               
.put("http://axschema.org/contact/postalCode/home";, "ZipCode");
+               attributes.put("http://axschema.org/contact/country/home";, 
"Country");
+               attributes.put("http://axschema.org/contact/web/blog";, "Blog");
+       }
+
+       public String execute() throws Exception {
+               ActionContext context = ActionContext.getContext();
+               HttpServletRequest request = (HttpServletRequest) context
+                               .get(StrutsStatics.HTTP_REQUEST);
+
+               HttpSession session = request.getSession();
+               String xmlToken = request.getParameter("xmlToken");
+
+               if (xmlToken != null) {
+                       
+                       consumerManager = new ConsumerManager();
+                       
+                       // received an xmlToken from an identity selector
+                       ParameterList openidResp = 
extractFromInfocardPost(request);
+                       processOpenIDResp(request, session, openidResp);
+               }
+
+               return SUCCESS;
+       }
+
+       private ParameterList extractFromInfocardPost(HttpServletRequest 
request)
+                       throws InfocardException {
+
+               String xmlToken = request.getParameter("xmlToken");
+
+               request.getSession().setAttribute("openidAssertion", xmlToken);
+
+               OpenIDToken token = OpenIDToken.createFromXmlToken(xmlToken);
+
+               return token.getOpenIDParams();
+       }
+
+       private void processOpenIDResp(HttpServletRequest request,
+                       HttpSession session, ParameterList openidResp)
+                       throws OpenIDException {
+
+               // retrieve the previously stored discovery information
+               DiscoveryInformation discovered = (DiscoveryInformation) session
+                               .getAttribute("discovered");
+
+               StringBuffer receivingURL = new 
StringBuffer("https://localhost:12443/OpenIdInfoCardLogin.action";);//request.getRequestURL();
+               String queryString = request.getQueryString();
+
+               if (queryString != null && queryString.length() > 0)
+                       
receivingURL.append("?").append(request.getQueryString());
+
+               // verify the response
+               VerificationResult verification = 
consumerManager.verify(receivingURL
+                               .toString(), openidResp, discovered);
+
+               verification.getVerifiedId();
+
+               Message authResponse = verification.getAuthResponse();
+
+               if (authResponse instanceof AuthSuccess) {
+
+                       Identifier verified = verification.getVerifiedId();
+                       String identifier = null;
+
+                       if (verified != null) {
+                               identifier = verified.getIdentifier();
+                       }
+
+                       AuthSuccess authSuccess = (AuthSuccess) authResponse;
+
+                       FetchResponse fetchResp = null;
+
+/*                     Map<String, String> attributes = new 
LinkedHashMap<String, String>();
+
+                       MessageExtension ext = authSuccess
+                                       .getExtension(AxMessage.OPENID_NS_AX);
+
+                       if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)
+                                       && ext instanceof FetchResponse) {
+                               fetchResp = (FetchResponse) ext;
+
+                               // extract the rest of the optional attributes
+                               List aliases = fetchResp.getAttributeAliases();
+                               Map types = fetchResp.getAttributeTypes();
+                               String alias;
+                               List values;
+                               for (Object a : aliases) {
+                                       alias = (String) a;
+                                       values = 
fetchResp.getAttributeValues(alias);
+                                       
attributes.put(attributes.get(types.get(alias)), values
+                                                       .size() > 0 ? (String) 
values.get(0) : null);
+                               }
+                       }
+
+                       session.setAttribute(LOGGEDIN, "");
+
+                       session.setAttribute("attributes", attributes);
+                       session.setAttribute("identifier", identifier);
+                       session.setAttribute("message", fetchResp);*/
+
+               }
+
+       }
+
+}

_______________________________________________
Identity-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/identity-dev

Reply via email to