[Carbon-commits] [Carbon] svn commit r114519 - in branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main: java/org/wso2/carbon/gapp/registration/ui resources/web/gappregistration

dimuthul at wso2.com dimuthul at wso2.com
Thu Oct 20 02:12:48 EDT 2011


Author: dimuthul
Date: Wed Oct 19 23:12:47 2011
New Revision: 114519
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=114519

Log:
Adding OAuth to GAPP registration.



Modified:
   branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/java/org/wso2/carbon/gapp/registration/ui/GAppRegistrationUIConstants.java
   branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp
   branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp
   branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp

Modified: branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/java/org/wso2/carbon/gapp/registration/ui/GAppRegistrationUIConstants.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/java/org/wso2/carbon/gapp/registration/ui/GAppRegistrationUIConstants.java?rev=114519&r1=114518&r2=114519&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/java/org/wso2/carbon/gapp/registration/ui/GAppRegistrationUIConstants.java	(original)
+++ branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/java/org/wso2/carbon/gapp/registration/ui/GAppRegistrationUIConstants.java	Wed Oct 19 23:12:47 2011
@@ -2,5 +2,6 @@
 
 public class GAppRegistrationUIConstants {
     
-    public static final String AUTH_SESSION_ATTRIBUTE = "gapp.setup.authentication";
+    public static final String ALLOWED = "gapp.setup.ok";
+    
 }

Modified: branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp?rev=114519&r1=114518&r2=114519&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp	(original)
+++ branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp	Wed Oct 19 23:12:47 2011
@@ -15,6 +15,7 @@
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
+<%@page import="org.wso2.carbon.gapp.registration.ui.GAppRegistrationUIConstants"%>
 <html>
 <head>
 <%@page import="org.wso2.carbon.utils.ServerConstants"%>
@@ -28,27 +29,12 @@
 <%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
 
 <%@page import="org.wso2.carbon.ui.util.CharacterEncoder"%><script type="text/javascript" src="../userstore/extensions/js/vui.js"></script>
-<script type="text/javascript" src="../admin/js/main.js"></script>
+
 <%
     String domain = (String)session.getAttribute("domain");
     String callback = (String)session.getAttribute("callback"); 
-    boolean isSuccess = true;
-	try {
-        String subscription = (String)request.getParameter("usage-plan-name");
-        String firstName = (String)request.getParameter("admin-firstname");
-        String lastName = (String)request.getParameter("admin-lastname");
-        String email = (String)request.getParameter("admin-email");
-        String[] users = new String[0];
-    	String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
-        String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
-        ConfigurationContext configContext =
-                    (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
-        GoolgeAppsRegistrationClient client = new GoolgeAppsRegistrationClient();
-        client.registerTenantForGAppDomain(backendServerURL, configContext, domain, email, firstName, lastName, subscription);
-    } catch (Exception e) {
-        isSuccess = false;
-    }
-%>
+%>  
+<script type="text/javascript" src="../admin/js/main.js"></script>
 <link href="../admin/css/global.css" rel="stylesheet" type="text/css" media="all"/>
 <link href="../admin/css/main.css" rel="stylesheet" type="text/css" media="all"/>
 <link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
@@ -86,20 +72,56 @@
 </head>
 <body>
 <div id="dcontainer"></div>
-      <%if (isSuccess) {%>
-            <script type="text/javascript">
-                jQuery(document).ready(function() {
-                    CARBON.showInfoDialog("Stratos setup was successful! You are being redirected back to Google");
-                });
-            </script>
-      <%} else {%>
-            <script type="text/javascript">
-            jQuery(document).ready(function() {
-                CARBON.showErrorDialog("Stratos setup was unsuccessful! You are being redirected back to Google");
-            });
-            </script>  	
-      <%}%>
-
+<script type="text/javascript">
+    function forward() {
+        location.href = "<%=callback%>";
+    }
+</script>
+<%
+    Object isAllowed = session.getAttribute(GAppRegistrationUIConstants.ALLOWED);
+    boolean value = (Boolean)isAllowed;
+    if (!value) {
+		%>
+	<script type="text/javascript">
+        jQuery(document).ready(function() {
+            CARBON.showInfoDialog("Illegal access atempt!");
+        });
+    </script>	
+		<%	
+		return;
+    }
+    
+    boolean isSuccess = true;
+	try {
+        String subscription = (String)request.getParameter("usage-plan-name");
+        String firstName = (String)request.getParameter("admin-firstname");
+        String lastName = (String)request.getParameter("admin-lastname");
+        String email = (String)request.getParameter("admin-email");
+        String[] users = new String[0];
+    	String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+        String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+        ConfigurationContext configContext =
+                    (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);       
+        GoolgeAppsRegistrationClient client = new GoolgeAppsRegistrationClient();
+        client.registerTenantForGAppDomain(backendServerURL, configContext, domain, email, firstName, lastName, subscription);
+    } catch (Exception e) {
+        isSuccess = false;
+    }
+    
+    if (isSuccess) {%>
+    <script type="text/javascript">
+        jQuery(document).ready(function() {
+            CARBON.showInfoDialog("Stratos setup was successful! You are being redirected back to Google", forward, forward);
+        });
+        
+    </script>
+<%} else {%>
+    <script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showErrorDialog("Stratos setup was unsuccessful! You are being redirected back to Google", forward, forward);
+    });
+    </script>  	
+<%}%>
 <table id="main-table" border="0" cellspacing="0">
       <tr>
           <td id="header"><jsp:include page="../admin/layout/header.jsp" />
@@ -137,12 +159,6 @@
       <tr>
           <td id="footer"<jsp:include page="../admin/layout/footer.jsp" /></td>
       </tr>
-  </table>
-  <script type="text/javascript">
-    function forward() {
-        location.href = "<%=callback%>";
-    }
-   </script>
-    
+  </table>   
 </body>
 </html>
\ No newline at end of file

Modified: branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp?rev=114519&r1=114518&r2=114519&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp	(original)
+++ branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp	Wed Oct 19 23:12:47 2011
@@ -15,6 +15,13 @@
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
+<%@page import="com.google.step2.Step2.AxSchema"%>
+<%@page import="org.wso2.carbon.identity.relyingparty.stub.dto.ClaimDTO"%>
+<%@page import="com.google.gdata.data.appsforyourdomain.provisioning.UserEntry"%>
+<%@page import="com.google.gdata.client.appsforyourdomain.UserService"%>
+<%@page import="java.net.URL"%>
+<%@page import="com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer"%>
+<%@page import="com.google.gdata.client.authn.oauth.GoogleOAuthParameters"%>
 <%@page import="org.wso2.carbon.utils.CarbonUtils"%>
 <%@page import="org.wso2.carbon.gapp.registration.ui.GAppRegistrationUIConstants"%>
 <%@page import="org.wso2.carbon.identity.relyingparty.ui.openid.OpenIDConsumer"%>
@@ -26,14 +33,52 @@
 <%
   try {
       
+      session.setAttribute(GAppRegistrationUIConstants.ALLOWED, new Boolean("false"));
+      
+      // is authenticated
       String webContextRoot = CarbonUtils.getServerConfiguration().getFirstProperty("WebContextRoot");
       String adminConsoleURL = CarbonUIUtil.getAdminConsoleURL(webContextRoot);
       String recievingURL = adminConsoleURL + "gappregistration/openidaccept_ajaxprocessor.jsp";
       OpenIDDTO openID = OpenIDConsumer.getInstance().validateOpenIDAuthentication(request, recievingURL);
-      session.setAttribute(GAppRegistrationUIConstants.AUTH_SESSION_ATTRIBUTE, new Boolean("true"));
+      ClaimDTO[] claims = openID.getClaims();
+      String emailId = null;
+      for(ClaimDTO claim : claims) {
+          if(claim.getClaimUri().equals(AxSchema.EMAIL.getUri())) {
+              emailId = claim.getClaimValue();
+          }
+      }
+      
+      if (emailId != null) {
+		    //is authorized
+		    GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
+		    oauthParameters.setOAuthConsumerKey("537510003441.apps.googleusercontent.com");
+		    oauthParameters.setOAuthConsumerSecret("cmE2UTFogPRkx4kLO8qvaDWF");
+		    OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();       
+		    
+		    String username =  emailId.substring(0, emailId.indexOf("@"));
+		    String domain = (String)session.getAttribute("domain");
+		    
+		    URL feedUrl = new URL("https://apps-apis.google.com/a/feeds/" + domain + "/user/2.0/" + 
+		                                                                                 username + 
+		                                                                  "?xoauth_requestor_id=" + 
+		                                                                                 emailId);
+		
+		    UserService service = new UserService("ProvisiongApiClient");
+		    service.setOAuthCredentials(oauthParameters, signer);
+		    service.useSsl();
+		    UserEntry entry = service.getEntry(feedUrl, UserEntry.class);
+		    if (entry.getLogin().getAdmin()) {
+		        session.setAttribute(GAppRegistrationUIConstants.ALLOWED, new Boolean("true"));    
+		    } else {
+		        throw new Exception("You are not the admin of this google apps domain. To setup stratos you must be an Admin");
+		    }
+      } else {
+          throw new IllegalStateException("Invalid state");
+      }
+      
       response.sendRedirect("setup_ajaxprocessor.jsp");
   } catch (Exception e) {
-	  CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request);
-      return;
+	  CarbonUIMessage.sendCarbonUIMessage("Unable to authorize you to setup Stratos domain." + e.getMessage(), CarbonUIMessage.ERROR, request);
+	  response.sendRedirect("setup_ajaxprocessor.jsp");
   }
 %>
\ No newline at end of file

Modified: branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp?rev=114519&r1=114518&r2=114519&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp	(original)
+++ branches/carbon/3.2.0/components/stratos/org.wso2.carbon.gapp.registration.ui/1.5.2/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp	Wed Oct 19 23:12:47 2011
@@ -15,6 +15,11 @@
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
+<%@page import="com.google.gdata.data.appsforyourdomain.provisioning.UserEntry"%>
+<%@page import="com.google.gdata.client.appsforyourdomain.UserService"%>
+<%@page import="java.net.URL"%>
+<%@page import="com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer"%>
+<%@page import="com.google.gdata.client.authn.oauth.GoogleOAuthParameters"%>
 <html>
 <head>
 <%@page import="org.wso2.carbon.identity.relyingparty.ui.openid.OpenIDConsumer"%>
@@ -29,54 +34,31 @@
 <%@page import="org.wso2.carbon.ui.CarbonUIMessage" %>
 <%@page import="org.wso2.carbon.ui.CarbonUIUtil" %>
 <%@page import="org.wso2.carbon.gapp.registration.ui.GoolgeAppsRegistrationClient" %>
-<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@page import="com.google.step2.Step2.AxSchema"%>
 
 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
 <%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
 
-<script type="text/javascript" src="../admin/js/main.js"></script>
 <%
-//validateEmpty(fldname) 
-    String domain = request.getParameter("domain");
-    String callback = request.getParameter("callback");
-    JSONArray packagesString = null;
+
+	String domain = request.getParameter("domain");
+	String callback = request.getParameter("callback");
 	PackageInfo[] packageInfo = new PackageInfo[0];
 	
-    if (domain !=null && domain.trim().length()> 0) { 
-        session.setAttribute("domain", domain.trim());
-    } else {
-        domain = (String)session.getAttribute("domain");
-    }
-    
-    if(callback !=null && callback.trim().length()> 0) {
-        session.setAttribute("callback", callback);
-    } else {
-        callback = (String) session.getAttribute("callback");
-    }
-    
-	try {
-		Object isGAppAuthenticated = session.getAttribute(GAppRegistrationUIConstants.AUTH_SESSION_ATTRIBUTE);
-		if (isGAppAuthenticated == null) {
-	    	OpenIDAuthenticationRequest openIDAuthRequest = new OpenIDAuthenticationRequest(request, response);
-	    	openIDAuthRequest.setOpenIDUrl(domain.trim());
-	    	String returnUrl = OpenIDConsumer.getInstance().getAdminConsoleURL(request) +
-                "gappregistration/openidaccept_ajaxprocessor.jsp";
-        	openIDAuthRequest.setReturnUrl(returnUrl);
-        	String forwardTo = OpenIDConsumer.getInstance().doOpenIDAuthentication(openIDAuthRequest);
-        	response.sendRedirect(forwardTo);
-		}
-		String serverURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
-    	ConfigurationContext configContext =
-            (ConfigurationContext) config.getServletContext().getAttribute(
-                    CarbonConstants.CONFIGURATION_CONTEXT);
-    	GoolgeAppsRegistrationClient client = new GoolgeAppsRegistrationClient();
-        packageInfo = client.getPackageInfo(serverURL, configContext);
-        packagesString = client.buildPackageInfoJSONArray(packageInfo);       
-	} catch (Exception e) {
-	    CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request);
-        return;
-    }
+	if (domain !=null && domain.trim().length()> 0) { 
+	    session.setAttribute("domain", domain.trim());
+	} else {
+	    domain = (String)session.getAttribute("domain");
+	}
+	
+	if(callback !=null && callback.trim().length()> 0) {
+	    session.setAttribute("callback", callback);
+	} else {
+	    callback = (String) session.getAttribute("callback");
+	}
 %>
+<script type="text/javascript" src="../admin/js/main.js"></script>
 
 <link href="../dialog/css/dialog.css" rel="stylesheet" type="text/css" media="all"/>
 <link href="../admin/css/global.css" rel="stylesheet" type="text/css" media="all"/>
@@ -112,8 +94,7 @@
     <script type="text/javascript" src="../admin/js/cookies.js"></script>
     <script src="../yui/build/yahoo-dom-event/yahoo-dom-event.js" type="text/javascript"></script>
     <script src="../admin/js/widgets.js" type="text/javascript"></script> 
-    
-<script type="text/javascript">
+    <script type="text/javascript">
 function validateGAppSetupInfo() {
     var error = validateEmpty('admin-email');
     if (error) {
@@ -152,6 +133,54 @@
 </head>
 <body>
 <div id="dcontainer"></div>
+
+<%    
+	try {
+		Object isAllowed = session.getAttribute(GAppRegistrationUIConstants.ALLOWED);
+		//is authenticated
+		if (isAllowed == null) {
+	    	OpenIDAuthenticationRequest openIDAuthRequest = new OpenIDAuthenticationRequest(request, response);
+	    	openIDAuthRequest.setOpenIDUrl(domain.trim());
+	    	String returnUrl = OpenIDConsumer.getInstance().getAdminConsoleURL(request) +
+                "gappregistration/openidaccept_ajaxprocessor.jsp";
+        	openIDAuthRequest.setReturnUrl(returnUrl);
+        	openIDAuthRequest.addRequiredClaims(AxSchema.EMAIL.getUri());
+        	openIDAuthRequest.setRequestClaimsFromIdP(true);
+        	String forwardTo = OpenIDConsumer.getInstance().doOpenIDAuthentication(openIDAuthRequest);
+        	response.sendRedirect(forwardTo);
+		} else {
+		    boolean value = (Boolean)isAllowed;
+		    if (!value) {
+		     	%>
+		     	<script type="text/javascript">
+			        jQuery(document).ready(function() {
+			            CARBON.showInfoDialog("<%=CarbonUIMessage.ID%>");
+			        });
+                </script>	
+		     	<%
+		     	response.sendRedirect(callback);
+		    }
+		}
+		
+			
+		String serverURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+    	ConfigurationContext configContext =
+            (ConfigurationContext) config.getServletContext().getAttribute(
+                    CarbonConstants.CONFIGURATION_CONTEXT);
+    	GoolgeAppsRegistrationClient client = new GoolgeAppsRegistrationClient();
+        packageInfo = client.getPackageInfo(serverURL, configContext);     
+	} catch (Exception e) {
+	    %>
+     	<script type="text/javascript">
+	        jQuery(document).ready(function() {
+	            CARBON.showInfoDialog("Unable to setup Stratos due to internal error. Please try again in a while.");
+	        });
+        </script>	
+     	<%
+     	response.sendRedirect(callback);
+    }
+%>
+
 <table id="main-table" border="0" cellspacing="0">
 	      <tr>
 	          <td id="header"><jsp:include page="../admin/layout/header.jsp" />


More information about the Carbon-commits mailing list