You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2013/06/28 21:26:55 UTC
[11/51] [partial] initial commit to apache incubator. Here just
commit WSO2 Stratos code base as it is. After that will start re-factor code
to apache
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/java/org/wso2/carbon/gapp/registration/ui/GoolgeAppsRegistrationClient.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/java/org/wso2/carbon/gapp/registration/ui/GoolgeAppsRegistrationClient.java b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/java/org/wso2/carbon/gapp/registration/ui/GoolgeAppsRegistrationClient.java
new file mode 100644
index 0000000..6cfe333
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/java/org/wso2/carbon/gapp/registration/ui/GoolgeAppsRegistrationClient.java
@@ -0,0 +1,227 @@
+package org.wso2.carbon.gapp.registration.ui;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Calendar;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.neethi.Policy;
+import org.apache.rampart.RampartMessageData;
+import org.apache.rampart.policy.model.CryptoConfig;
+import org.apache.rampart.policy.model.RampartConfig;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.wso2.carbon.base.ServerConfiguration;
+import org.wso2.carbon.stratos.common.config.CloudServiceConfig;
+import org.wso2.carbon.stratos.common.config.CloudServiceConfigParser;
+import org.wso2.carbon.stratos.common.constants.StratosConstants;
+import org.wso2.carbon.stratos.common.packages.stub.PackageInfo;
+import org.wso2.carbon.stratos.common.packages.stub.PackageInfoServiceStub;
+import org.wso2.carbon.tenant.register.gapp.stub.GAppTenantRegistrationServiceStub;
+import org.wso2.carbon.tenant.register.gapp.stub.xsd.TenantInfoBean;
+import org.wso2.carbon.utils.CarbonUtils;
+
+public class GoolgeAppsRegistrationClient {
+
+ private static final Log log = LogFactory.getLog(GoolgeAppsRegistrationClient.class);
+
+
+ private static final String GAPP_PROPERTIES_FILE = "gapp.setup.properties";
+ private static Properties consumerKeys = new Properties();
+
+ public GoolgeAppsRegistrationClient() {
+
+ }
+
+ public void registerTenantForGAppDomain(String backendServerURL,
+ ConfigurationContext configContext,
+ String domain,
+ String email,
+ String adminFirstName,
+ String adminLastName,
+ String usagePlan) throws Exception {
+ try {
+ Map<String, CloudServiceConfig> cloudServiceConfigs = CloudServiceConfigParser.
+ loadCloudServicesConfiguration().
+ getCloudServiceConfigs();
+ String managerHomepageURL =
+ cloudServiceConfigs.get(StratosConstants.CLOUD_MANAGER_SERVICE).
+ getLink();
+ String serviceURL = managerHomepageURL + "/services/GAppTenantRegistrationService";
+ GAppTenantRegistrationServiceStub stub = new GAppTenantRegistrationServiceStub(configContext, serviceURL);
+ ServiceClient client = stub._getServiceClient();
+ // Engage rampart as we are going to sign requests to Relying Party Service
+ client.engageModule("rampart");
+ // Get a RampartConfig with default crypto information
+ Policy rampartConfig = getDefaultRampartConfig();
+ Policy signOnly = getSignOnlyPolicy();
+ Policy mergedPolicy = signOnly.merge(rampartConfig);
+ Options option = client.getOptions();
+ option.setProperty(RampartMessageData.KEY_RAMPART_POLICY, mergedPolicy);
+ option.setManageSession(true);
+
+ String username = email.substring(0, email.indexOf("@"));
+ TenantInfoBean bean = new TenantInfoBean();
+ bean.setEmail(email);
+ bean.setFirstname(adminFirstName);
+ bean.setLastname(adminLastName);
+ bean.setTenantDomain(domain);
+ bean.setAdmin(username);
+ bean.setUsagePlan(usagePlan);
+ bean.setCreatedDate(Calendar.getInstance());
+ stub.registerGoogleAppsTenant(bean);
+ } catch (Exception e) {
+ String msg = "Failed to create domain because " + e.getMessage();
+ log.error(msg, e);
+ throw new Exception(msg);
+ }
+
+ }
+
+ public JSONArray buildPackageInfoJSONArray(PackageInfo[] packages) throws Exception {
+ JSONArray packageInfo = new JSONArray();
+ try {
+ for (PackageInfo pak : packages) {
+ JSONObject obj = new JSONObject();
+ obj.put("name", pak.getName());
+ obj.put("users", pak.getUsersLimit());
+ packageInfo.put(obj);
+ }
+ return packageInfo;
+ } catch (JSONException e) {
+ String msg = "Failed to build JSON list " + e.getMessage();
+ log.error(msg, e);
+ throw new Exception(msg);
+ }
+ }
+
+ public PackageInfo[] getPackageInfo(String backendServerURL,
+ ConfigurationContext configContext) throws Exception {
+ String packageServiceEpr = backendServerURL + "PackageInfoService";
+ PackageInfoServiceStub packageStub = null;
+ PackageInfo[] packageInfo = new PackageInfo[0];
+ try {
+ packageStub = new PackageInfoServiceStub(configContext, packageServiceEpr);
+ PackageInfo[] packages = packageStub.getPackageInfos();
+ int i = 0;
+ packageInfo = new PackageInfo[packages.length];
+ for (PackageInfo pack : packages ) {
+ packageInfo[i] = new PackageInfo();
+ packageInfo[i].setName(pack.getName());
+ packageInfo[i].setUsersLimit(pack.getUsersLimit());
+ i++;
+ }
+ return packageInfo;
+ } catch (Exception e) {
+ String msg = "Failed to retrieve package list " + e.getMessage();
+ log.error(msg, e);
+ throw new Exception(msg);
+ }
+ }
+
+ private Policy getSignOnlyPolicy() {
+ URL url = null;
+ InputStream inStream;
+ try {
+ inStream = null;
+ if ((url = this.getClass().getClassLoader().getResource("signonly-policy.xml")) != null) {
+ inStream = url.openStream();
+ } else {
+ throw new Exception("The file is not present in bundle");
+ }
+ Policy policy = org.apache.neethi.PolicyEngine.getPolicy(inStream);
+ return policy;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException("Error while creating policy");
+ }
+ }
+
+ public boolean isRegisteredAsGoogleAppDomain(ConfigurationContext configContext,
+ String domain) throws Exception {
+
+ Map<String, CloudServiceConfig> cloudServiceConfigs = CloudServiceConfigParser.
+ loadCloudServicesConfiguration().
+ getCloudServiceConfigs();
+ String managerHomepageURL =
+ cloudServiceConfigs.get(StratosConstants.CLOUD_MANAGER_SERVICE).
+ getLink();
+ String serviceURL = managerHomepageURL + "/services/GAppTenantRegistrationService";
+
+ GAppTenantRegistrationServiceStub stub = new GAppTenantRegistrationServiceStub(configContext, serviceURL);
+ ServiceClient client = stub._getServiceClient();
+ // Engage rampart as we are going to sign requests to Relying Party Service
+ client.engageModule("rampart");
+ // Get a RampartConfig with default crypto information
+ Policy rampartConfig = getDefaultRampartConfig();
+ Policy signOnly = getSignOnlyPolicy();
+ Policy mergedPolicy = signOnly.merge(rampartConfig);
+ Options option = client.getOptions();
+ option.setProperty(RampartMessageData.KEY_RAMPART_POLICY, mergedPolicy);
+ option.setManageSession(true);
+
+ return stub.isRegisteredAsGoogleAppDomain(domain);
+ }
+
+ public static String getGoogleAppSetupPropery(String name) throws Exception {
+ try {
+ if (consumerKeys.size() == 0) {
+ String carbonHome = CarbonUtils.getCarbonHome();
+ if (carbonHome != null) {
+ File gappSetupProperties =
+ new File(CarbonUtils.getCarbonConfigDirPath(),
+ GAPP_PROPERTIES_FILE);
+
+ FileInputStream in = new FileInputStream(gappSetupProperties);
+ consumerKeys.load(in);
+ }
+ }
+ return (String)consumerKeys.get(name);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ throw new Exception(e.getMessage(), e);
+ }
+ }
+
+ private Policy getDefaultRampartConfig() {
+ //Extract the primary keystore information from server configuration
+ ServerConfiguration serverConfig = ServerConfiguration.getInstance();
+ String keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location");
+ String keyStoreType = serverConfig.getFirstProperty("Security.KeyStore.Type");
+ String keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password");
+ String privateKeyAlias = serverConfig.getFirstProperty("Security.KeyStore.KeyAlias");
+ String privateKeyPassword = serverConfig.getFirstProperty("Security.KeyStore.KeyPassword");
+
+ //Populate Rampart Configuration
+ RampartConfig rampartConfig = new RampartConfig();
+ rampartConfig.setUser(privateKeyAlias);
+ rampartConfig.setPwCbClass("org.wso2.carbon.gapp.registration.ui.InMemoryPasswordcallbackHandler");
+
+ //Set the private key alias and private key password in the password callback handler
+ InMemoryPasswordcallbackHandler.addUser(privateKeyAlias, privateKeyPassword);
+
+ CryptoConfig sigCrypto = new CryptoConfig();
+ Properties props = new Properties();
+ sigCrypto.setProvider("org.apache.ws.security.components.crypto.Merlin");
+ props.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", keyStoreType);
+ props.setProperty("org.apache.ws.security.crypto.merlin.file", keyStore);
+ props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", keyStorePassword);
+ sigCrypto.setProp(props);
+
+ rampartConfig.setSigCryptoConfig(sigCrypto);
+ Policy policy = new Policy();
+ policy.addAssertion(rampartConfig);
+
+ return policy;
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/java/org/wso2/carbon/gapp/registration/ui/InMemoryPasswordcallbackHandler.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/java/org/wso2/carbon/gapp/registration/ui/InMemoryPasswordcallbackHandler.java b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/java/org/wso2/carbon/gapp/registration/ui/InMemoryPasswordcallbackHandler.java
new file mode 100644
index 0000000..082d816
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/java/org/wso2/carbon/gapp/registration/ui/InMemoryPasswordcallbackHandler.java
@@ -0,0 +1,39 @@
+package org.wso2.carbon.gapp.registration.ui;
+
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.apache.ws.security.WSPasswordCallback;
+
+public class InMemoryPasswordcallbackHandler implements CallbackHandler {
+
+ private static Map<String, String> keystorePassword = new HashMap<String, String>();
+
+ public void handle(Callback[] callbacks)
+ throws IOException, UnsupportedCallbackException {
+
+ for (int i = 0; i < callbacks.length; i++) {
+
+ if (callbacks[i] instanceof WSPasswordCallback) {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
+ String id = pc.getIdentifier();
+ if (keystorePassword.get(id) != null) {
+ pc.setPassword(keystorePassword.get(id));
+ } else {
+ throw new UnsupportedCallbackException(callbacks[i], "no password found for " + id);
+ }
+ }
+
+ }
+ }
+
+ public static void addUser(String username, String password) {
+ keystorePassword.put(username, password);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/META-INF/component.xml b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/META-INF/component.xml
new file mode 100644
index 0000000..4436375
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/META-INF/component.xml
@@ -0,0 +1,27 @@
+<!--
+ ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ ~
+ ~ WSO2 Inc. licenses this file to you under the Apache License,
+ ~ Version 2.0 (the "License"); you may not use this file except
+ ~ in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<component xmlns="http://products.wso2.org/carbon">
+ <framework-configuration>
+ <bypass>
+ <authentication>
+ <link>/setup_ajaxprocessor.jsp</link>
+ <link>/done_ajaxprocessor.jsp</link>
+ </authentication>
+ </bypass>
+ </framework-configuration>
+</component>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/gapp/registration/ui/i18n/Resources.properties
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/gapp/registration/ui/i18n/Resources.properties b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/gapp/registration/ui/i18n/Resources.properties
new file mode 100644
index 0000000..ec80581
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/gapp/registration/ui/i18n/Resources.properties
@@ -0,0 +1,8 @@
+select.usage.plan.for.tenant=Select a usage plan for tenant
+help=help
+admin.firstname=First Name
+admin.lastname=Last Name
+admin.address=Address
+admin.email=Email
+select.usage.plan.for.tenant=Select a usage plan for tenant
+help=help
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/signonly-policy.xml
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/signonly-policy.xml b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/signonly-policy.xml
new file mode 100644
index 0000000..2b24b29
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/signonly-policy.xml
@@ -0,0 +1,102 @@
+<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SigOnly">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <wsp:Policy>
+ <sp:InitiatorToken>
+ <wsp:Policy>
+ <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
+ <wsp:Policy>
+ <sp:RequireThumbprintReference />
+ <sp:WssX509V3Token10 />
+ </wsp:Policy>
+ </sp:X509Token>
+ </wsp:Policy>
+ </sp:InitiatorToken>
+ <sp:RecipientToken>
+ <wsp:Policy>
+ <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
+ <wsp:Policy>
+ <sp:RequireThumbprintReference />
+ <sp:WssX509V3Token10 />
+ </wsp:Policy>
+ </sp:X509Token>
+ </wsp:Policy>
+ </sp:RecipientToken>
+ <sp:AlgorithmSuite>
+ <wsp:Policy>
+ <sp:Basic256 />
+ </wsp:Policy>
+ </sp:AlgorithmSuite>
+ <sp:Layout>
+ <wsp:Policy>
+ <sp:Strict />
+ </wsp:Policy>
+ </sp:Layout>
+ <sp:IncludeTimestamp />
+ <sp:OnlySignEntireHeadersAndBody />
+ </wsp:Policy>
+ </sp:AsymmetricBinding>
+ <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <sp:Policy>
+ <sp:MustSupportRefKeyIdentifier />
+ <sp:MustSupportRefIssuerSerial />
+ </sp:Policy>
+ </sp:Wss10>
+ <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <sp:Body />
+ </sp:SignedParts>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
+<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SigOnly">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <wsp:Policy>
+ <sp:InitiatorToken>
+ <wsp:Policy>
+ <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
+ <wsp:Policy>
+ <sp:RequireThumbprintReference />
+ <sp:WssX509V3Token10 />
+ </wsp:Policy>
+ </sp:X509Token>
+ </wsp:Policy>
+ </sp:InitiatorToken>
+ <sp:RecipientToken>
+ <wsp:Policy>
+ <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
+ <wsp:Policy>
+ <sp:RequireThumbprintReference />
+ <sp:WssX509V3Token10 />
+ </wsp:Policy>
+ </sp:X509Token>
+ </wsp:Policy>
+ </sp:RecipientToken>
+ <sp:AlgorithmSuite>
+ <wsp:Policy>
+ <sp:Basic256 />
+ </wsp:Policy>
+ </sp:AlgorithmSuite>
+ <sp:Layout>
+ <wsp:Policy>
+ <sp:Strict />
+ </wsp:Policy>
+ </sp:Layout>
+ <sp:IncludeTimestamp />
+ <sp:OnlySignEntireHeadersAndBody />
+ </wsp:Policy>
+ </sp:AsymmetricBinding>
+ <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <sp:Policy>
+ <sp:MustSupportRefKeyIdentifier />
+ <sp:MustSupportRefIssuerSerial />
+ </sp:Policy>
+ </sp:Wss10>
+ <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <sp:Body />
+ </sp:SignedParts>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp
new file mode 100644
index 0000000..0295fc7
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/done_ajaxprocessor.jsp
@@ -0,0 +1,165 @@
+<!--
+ ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ ~
+ ~ WSO2 Inc. licenses this file to you under the Apache License,
+ ~ Version 2.0 (the "License"); you may not use this file except
+ ~ in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<%@page import="org.wso2.carbon.gapp.registration.ui.GAppRegistrationUIConstants"%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+<%@page import="org.wso2.carbon.utils.ServerConstants"%>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@page import="org.wso2.carbon.CarbonConstants" %>
+<%@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.util.CharacterEncoder"%><script type="text/javascript" src="../userstore/extensions/js/vui.js"></script>
+
+<%
+ String domain = (String)session.getAttribute("domain");
+ String callback = (String)session.getAttribute("callback");
+%>
+<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"/>
+
+
+ <link href="../dialog/css/jqueryui/jqueryui-themeroller.css" rel="stylesheet" type="text/css" media="all"/>
+ <link href="../dialog/css/dialog.css" rel="stylesheet" type="text/css" media="all"/>
+ <link rel="icon" href="../admin/images/favicon.ico" type="image/x-icon"/>
+ <link rel="shortcut icon" href="../admin/images/favicon.ico" type="image/x-icon"/>
+
+ <script type="text/javascript" src="../admin/js/jquery.js"></script>
+ <script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+ <script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+ <script type="text/javascript" src="../dialog/js/dialog.js"></script>
+
+ <script type="text/javascript" src="../admin/js/main.js"></script>
+ <script type="text/javascript" src="../admin/js/WSRequest.js"></script>
+ <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>
+<!--[if gte IE 8]>
+<link href="../dialog/css/dialog-ie8.css" rel="stylesheet" type="text/css" media="all"/>
+<![endif]-->
+<!--[if gte IE 7]>
+<link href="../dialog/css/dialog-ie8.css" rel="stylesheet" type="text/css" media="all"/>
+<![endif]-->
+<style type="text/css">
+ .header-links{
+ display:none !important;
+ }
+ body, span, td, div{
+ font-size:12px;
+ }
+</style>
+</head>
+<body>
+<div id="dcontainer"></div>
+<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" />
+ </td>
+ </tr>
+ <tr>
+
+
+ <td id="middle-content">
+ <table id="content-table" border="0" cellspacing="0">
+
+ <tr>
+ <td id="body">
+ <fmt:bundle basename="org.wso2.carbon.gapp.registration.ui.i18n.Resources">
+
+ <script type="text/javascript">
+
+
+ </script>
+ <div id="middle">
+ <div id="workArea">
+ <%if (isSuccess) {%>
+ <p>Setting up Stratos was successful. You are being redirected back to <%=callback%></p>
+ <% } else { %>
+ <p>Setting up Stratos was unsuccessful. You are being redirected back to <%=callback%></p>
+ <% } %>
+ </div>
+ </div>
+ </fmt:bundle>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td id="footer"<jsp:include page="../admin/layout/footer.jsp" /></td>
+ </tr>
+ </table>
+</body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp
new file mode 100644
index 0000000..aed6ece
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/openidaccept_ajaxprocessor.jsp
@@ -0,0 +1,93 @@
+<!--
+ ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ ~
+ ~ WSO2 Inc. licenses this file to you under the Apache License,
+ ~ Version 2.0 (the "License"); you may not use this file except
+ ~ in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<%@page import="org.wso2.carbon.gapp.registration.ui.GoolgeAppsRegistrationClient"%>
+<%@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"%>
+<%@page import="org.wso2.carbon.identity.relyingparty.ui.client.RelyingPartyServiceClient"%>
+<%@page import="org.wso2.carbon.identity.relyingparty.ui.openid.OpenIDAuthenticationRequest"%>
+<%@ page import="org.wso2.carbon.identity.relyingparty.stub.dto.OpenIDDTO" %>
+<%@page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%
+ 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);
+ 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
+ String serviceName = (String)session.getAttribute("service");
+
+ GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
+ oauthParameters.setOAuthConsumerKey(
+ GoolgeAppsRegistrationClient.
+ getGoogleAppSetupPropery(serviceName + ".consumer.key"));
+ oauthParameters.setOAuthConsumerSecret(
+ GoolgeAppsRegistrationClient.
+ getGoogleAppSetupPropery(serviceName + ".consumer.key.secret"));
+ 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("Failed to setup stratos. " + e.getMessage(), CarbonUIMessage.ERROR, request);
+ response.sendRedirect("setup_ajaxprocessor.jsp");
+ }
+%>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp
new file mode 100644
index 0000000..bf5a1f6
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.gapp.registration.ui/2.1.0/src/main/resources/web/gappregistration/setup_ajaxprocessor.jsp
@@ -0,0 +1,320 @@
+<!--
+ ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ ~
+ ~ WSO2 Inc. licenses this file to you under the Apache License,
+ ~ Version 2.0 (the "License"); you may not use this file except
+ ~ in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<%@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"%>
+<%@page import="org.wso2.carbon.identity.relyingparty.ui.openid.OpenIDAuthenticationRequest"%>
+<%@page import="org.wso2.carbon.gapp.registration.ui.GAppRegistrationUIConstants"%>
+<%@page import="org.wso2.carbon.stratos.common.packages.stub.PackageInfo"%>
+<%@page import="org.json.JSONArray"%>
+<%@page import="org.wso2.carbon.common.util.CommonUtil"%>
+<%@page import="org.wso2.carbon.utils.ServerConstants"%>
+<%@page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@page import="org.wso2.carbon.CarbonConstants" %>
+<%@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="com.google.step2.Step2.AxSchema"%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<%
+ String domain = request.getParameter("domain");
+ String callback = request.getParameter("callback");
+ String service = request.getParameter("service");
+
+ PackageInfo[] packageInfo = new PackageInfo[0];
+
+ if (service != null && service.trim().length() > 0) {
+ session.setAttribute(GAppRegistrationUIConstants.ALLOWED, null);
+ session.setAttribute("service", service.trim());
+ } else {
+ service = (String) session.getAttribute("service");
+ }
+
+ if (domain != null && domain.trim().length() > 0) {
+ session.setAttribute(GAppRegistrationUIConstants.ALLOWED, null);
+ session.setAttribute("domain", domain.trim());
+ } else {
+ domain = (String) session.getAttribute("domain");
+ }
+
+ if (callback != null && callback.trim().length() > 0) {
+ session.setAttribute(GAppRegistrationUIConstants.ALLOWED, null);
+ 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"/>
+<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"/>
+<!--[if gte IE 8]>
+<link href="../dialog/css/dialog-ie8.css" rel="stylesheet" type="text/css" media="all"/>
+<![endif]-->
+<!--[if gte IE 7]>
+<link href="../dialog/css/dialog-ie8.css" rel="stylesheet" type="text/css" media="all"/>
+<![endif]-->
+<style type="text/css">
+ .header-links{
+ display:none !important;
+ }
+ body, span, td, div{
+ font-size:12px;
+ }
+</style>
+
+ <link href="../dialog/css/jqueryui/jqueryui-themeroller.css" rel="stylesheet" type="text/css" media="all"/>
+ <link href="../dialog/css/dialog.css" rel="stylesheet" type="text/css" media="all"/>
+ <link rel="icon" href="../admin/images/favicon.ico" type="image/x-icon"/>
+ <link rel="shortcut icon" href="../admin/images/favicon.ico" type="image/x-icon"/>
+
+ <script type="text/javascript" src="../admin/js/jquery.js"></script>
+ <script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+ <script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+ <script type="text/javascript" src="../dialog/js/dialog.js"></script>
+
+ <script type="text/javascript" src="../admin/js/main.js"></script>
+ <script type="text/javascript" src="../admin/js/WSRequest.js"></script>
+ <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">
+function validateGAppSetupInfo() {
+ var error = validateEmpty('admin-email');
+ if (error) {
+ CARBON.showWarningDialog("Email address cannot be empty.");
+ return false;
+ }
+
+ var fld = document.getElementById('admin-email');
+ var value = fld.value;
+ if (value.indexOf("@") > -1 ) {
+ var emaildomain = value.substring(value.indexOf("@")+1, value.length);
+ if (emaildomain == "<%=domain%>") {
+ //do nothing
+ } else {
+ CARBON.showWarningDialog("Admin's email address must be in the same domain.");
+ return false;
+ }
+ } else {
+ CARBON.showWarningDialog("Invalid email address.");
+ return false;
+ }
+
+ var error = validateEmpty('admin-firstname');
+ if (error) {
+ CARBON.showWarningDialog("First name cannot be empty.");
+ return false;
+ }
+ var error = validateEmpty('admin-lastname');
+ if (error) {
+ CARBON.showWarningDialog("Last name cannot be empty.");
+ return false;
+ }
+ document.gappsetupForm.submit();
+};
+</script>
+</head>
+<body>
+<div id="dcontainer"></div>
+<script type="text/javascript">
+ function forward() {
+ location.href = "<%=callback%>";
+ }
+</script>
+<%
+ try {
+ Object isAllowed = session.getAttribute(GAppRegistrationUIConstants.ALLOWED);
+ if (isAllowed == null) {
+ //this is the first call
+ ConfigurationContext configContext =
+ (ConfigurationContext) config.getServletContext()
+ .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+ GoolgeAppsRegistrationClient client = new GoolgeAppsRegistrationClient();
+
+ if (domain == null) {
+ throw new Exception("Cannot proceed since domain is invalid");
+ }
+
+ boolean isRegistered =
+ client.isRegisteredAsGoogleAppDomain(configContext, domain);
+ if (isRegistered) {
+%>
+ <script type="text/javascript">
+ jQuery(document).ready(function() {
+ CARBON.showInfoDialog("Strato domain has been setup for the domain " + <%=domain%>, forward, forward);
+ });
+ </script>
+ <%
+ return;
+ }
+
+ 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) {
+ CarbonUIMessage carbonMessage =
+ (CarbonUIMessage) session.getAttribute(CarbonUIMessage.ID);
+ %>
+ <script type="text/javascript">
+ jQuery(document).ready(function() {
+ CARBON.showErrorDialog("<%=carbonMessage.getMessage()%>", forward, forward);
+ });
+ </script>
+ <%
+ return;
+ }
+ }
+
+ 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.showErrorDialog("Unable to setup Stratos. <%=e.getMessage()%> ", forward, forward);
+ });
+ </script>
+ <%
+ return;
+ }
+ %>
+
+<table id="main-table" border="0" cellspacing="0">
+ <tr>
+ <td id="header"><jsp:include page="../admin/layout/header.jsp" />
+ </td>
+ </tr>
+ <tr>
+
+
+ <td id="middle-content">
+ <table id="content-table" border="0" cellspacing="0">
+
+ <tr>
+ <td id="body">
+
+
+ <fmt:bundle basename="org.wso2.carbon.gapp.registration.ui.i18n.Resources">
+ <div id="middle">
+ <h2>Setting up the Stratos Domain for your Google Apps Domain</h2>
+ <div id="workArea">
+ <form method="post" name="gappsetupForm" action="done_ajaxprocessor.jsp">
+ <div class="toggle_container">
+ <table class="normal-nopadding" cellspacing="0" >
+ <tbody>
+ <tr>
+ <td><fmt:message key="admin.email"/><span
+ class="required">*</span></td>
+ <td><input type="text" name="admin-email"
+ id="admin-email" style="width:400px"/></td>
+ </tr>
+ <tr>
+ <td><fmt:message key="admin.firstname"/><span
+ class="required">*</span></td>
+ <td><input type="text" name="admin-firstname"
+ id="admin-firstname" style="width:400px"/></td>
+ </tr>
+ <tr>
+ <td><fmt:message key="admin.lastname"/><span
+ class="required">*</span></td>
+ <td colspan="2"><input type="text" name="admin-lastname"
+ id="admin-lastname" style="width:400px"/></td>
+ </tr>
+ <tr>
+ <td>
+ <fmt:message key="select.usage.plan.for.tenant"/><span class="required">*</span>
+ </td>
+ <td><p>
+ <select name="usage-plan-name" id="usage-plan-name">
+ <%
+ for (int i = 0; i < packageInfo.length; i++) {
+ %>
+ <%
+ if (i == 0) {
+ %>
+ <option value="<%=packageInfo[i].getName()%>" selected="selected"><%=packageInfo[i].getName()%></option>
+ <%
+ } else {
+ %>
+ <option value="<%=packageInfo[i].getName()%>"><%=packageInfo[i].getName()%></option>
+ <%
+ }
+ }
+ %>
+ </select>
+ <a href=<%=CommonUtil.getStratosConfig().getUsagePlanURL()%>
+ target=<%=CommonUtil.getStratosConfig().getUsagePlanURL()%>>
+ <b>More info</b>
+ </a>
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td class="buttonRow" colspan="2"><input type="button" class="button" value="OK" onclick="validateGAppSetupInfo();"/></td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </form>
+ </div>
+ </div>
+ </fmt:bundle>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td id="footer"><jsp:include page="../admin/layout/footer.jsp" /></td>
+ </tr>
+ </table>
+
+
+</body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/pom.xml
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/pom.xml b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/pom.xml
new file mode 100644
index 0000000..6ba9a06
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>stratos-components</artifactId>
+ <version>2.1.0</version>
+<relativePath>../../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.wso2.carbon.google.analytics.ui</artifactId>
+ <packaging>bundle</packaging>
+ <name>WSO2 Stratos-Google Analytics UI</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.ui</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.stratos.common</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Private-Package>org.wso2.carbon.google.analytics.ui.internal
+ </Private-Package>
+ <Export-Package>
+ org.wso2.carbon.google.analytics.ui.*; version=1.0.0,
+ </Export-Package>
+ <Import-Package>
+ javax.servlet;version="${imp.pkg.version.javax.servlet}",
+ javax.xml.namespace; version="0.0.0",
+ *;resolution:=optional
+ </Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ <Carbon-Component>UIBundle</Carbon-Component>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/java/org/wso2/carbon/google/analytics/ui/internal/GoogleAnalyticsUIServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/java/org/wso2/carbon/google/analytics/ui/internal/GoogleAnalyticsUIServiceComponent.java b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/java/org/wso2/carbon/google/analytics/ui/internal/GoogleAnalyticsUIServiceComponent.java
new file mode 100644
index 0000000..27ef59f
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/java/org/wso2/carbon/google/analytics/ui/internal/GoogleAnalyticsUIServiceComponent.java
@@ -0,0 +1,68 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.wso2.carbon.google.analytics.ui.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+
+import javax.servlet.ServletContext;
+
+/**
+ * @scr.component name="org.wso2.carbon.google.analyzer.ui" immediate="true"
+ * @scr.reference name="servlet.context.service"
+ * interface="javax.servlet.ServletContext"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setServletContextService"
+ * unbind="unsetServletContextService"
+ */
+
+/**
+ * org.wso2.carbon.google.analytics.ui bundle has implemented for giving google-analytics support
+ * for stratos.
+ */
+
+public class GoogleAnalyticsUIServiceComponent {
+
+ private static final Log log = LogFactory.getLog(GoogleAnalyticsUIServiceComponent.class);
+
+ private static ServletContext servletCtx = null;
+
+ protected void activate(ComponentContext context) {
+ try {
+ log.debug("Google Analytics UI Component bundle is activated");
+ } catch (Exception e) {
+ log.debug("Failed to activate Google Analytics UI Component bundle");
+ }
+ }
+
+ protected void deactivate(ComponentContext context) {
+ log.debug("Google Analytics UI Component bundle is deactivated");
+ }
+
+ protected void setServletContextService(ServletContext servletContext) {
+ this.servletCtx = servletContext;
+
+ }
+
+ protected void unsetServletContextService(ServletContext servletContext) {
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/java/org/wso2/carbon/google/analytics/ui/servlets/GoogleAnalyticsServlet.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/java/org/wso2/carbon/google/analytics/ui/servlets/GoogleAnalyticsServlet.java b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/java/org/wso2/carbon/google/analytics/ui/servlets/GoogleAnalyticsServlet.java
new file mode 100644
index 0000000..c3e6711
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/java/org/wso2/carbon/google/analytics/ui/servlets/GoogleAnalyticsServlet.java
@@ -0,0 +1,90 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.wso2.carbon.google.analytics.ui.servlets;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.stratos.common.util.CommonUtil;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * GoogleAnalyticsServlet use for sending a request to a remote URL in where a js snippet which
+ * is required to process google analytics is hosted.Then this servlet get back the content of
+ * that js snippet and set it as the response.Then by using a javascript,this servlet response will
+ * be embedded into another html/jsp page and make use of the js snippet content from that html/jsp
+ * page.
+ */
+public class GoogleAnalyticsServlet extends HttpServlet {
+ private static final Log log = LogFactory.getLog(GoogleAnalyticsServlet.class);
+ private static String GOOGLE_ANALYTICS_URL = "GoogleAnalyticsURL";
+ private static String googleAnalyticsURL = "googleAnalyticUrl";
+
+ public void init(ServletConfig servletConfig) throws ServletException {
+ super.init(servletConfig);
+
+ }
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ String url = null;
+ try {
+ //Read Google analytic url from stratos.xml
+ url = CommonUtil.loadStratosConfiguration().getGoogleAnalyticsURL();
+ if (url != null && !(url.equals(""))) {
+ //Create a new connection to above read google analytic url and read content of url.
+ URL googleAnalyticUrl = new URL(url);
+ URLConnection connection = googleAnalyticUrl.openConnection();
+ //Set the input stream of created URL connection to a reader
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ connection.getInputStream()));
+ String inputLine;
+ //Set servlet response as 'text/javascript'
+ response.setContentType("text/javascript");
+ PrintWriter out = response.getWriter();
+ //Read the input stream which has fetched to buffered reader,line by line and then
+ //write those content into the servlet response.
+ while ((inputLine = in.readLine()) != null) {
+ out.write(inputLine);
+ }
+ in.close();
+ out.flush();
+ out.close();
+ }
+ } catch (Exception e) {
+ String msg = "Failed to get content from the url." + url + e.getMessage();
+ log.error(msg, e);
+ response.setStatus(500);
+ }
+
+
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/resources/META-INF/component.xml b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/resources/META-INF/component.xml
new file mode 100644
index 0000000..bafedb9
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/resources/META-INF/component.xml
@@ -0,0 +1,43 @@
+<!--
+ ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ ~
+ ~ WSO2 Inc. licenses this file to you under the Apache License,
+ ~ Version 2.0 (the "License"); you may not use this file except
+ ~ in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<component xmlns="http://products.wso2.org/carbon">
+ <servlets>
+ <servlet id="googleAnalyticsServlet">
+ <servlet-name>googleAnalyticsServlet</servlet-name>
+ <url-pattern>/google-analytics</url-pattern>
+ <display-name>Google Analytics Servlet</display-name>
+ <servlet-class>org.wso2.carbon.google.analytics.ui.servlets.GoogleAnalyticsServlet
+ </servlet-class>
+ </servlet>
+ </servlets>
+ <framework-configuration>
+ <bypass>
+ <authentication>
+ <link>/google-analytics</link>
+ </authentication>
+ <tiles>
+ <link>/google-analytics</link>
+ </tiles>
+ <httpUrls>
+ <link>/google-analytics</link>
+ </httpUrls>
+ </bypass>
+ </framework-configuration>
+
+
+</component>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/resources/web.googleanalytics/js/googleAnalyticsProcessor.js
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/resources/web.googleanalytics/js/googleAnalyticsProcessor.js b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/resources/web.googleanalytics/js/googleAnalyticsProcessor.js
new file mode 100644
index 0000000..44803eb
--- /dev/null
+++ b/components/stratos/org.wso2.carbon.google.analytics.ui/2.1.0/src/main/resources/web.googleanalytics/js/googleAnalyticsProcessor.js
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Following jquery function sends an AJAX request to the googleAnalyticsServlet and get back the
+ * response from the servlet and append it into html/jsp file 'body' section,once the html/jsp
+ * file is ready
+ */
+$('document').ready(function() {
+ $.ajax({
+ type: "GET",
+ url: "/google-analytics",
+ data: null,
+ success: function(response) {
+ if (response != "googleAnalyticUrl") {
+ $("body").append(response);
+ }
+ }
+ });
+});