Updated Branches:
  refs/heads/master fee25c8ad -> 39207f67c

adding router for central authentication and url mapping


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/465f3bc3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/465f3bc3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/465f3bc3

Branch: refs/heads/master
Commit: 465f3bc314c8449ec09547674e4a558f5f3e522f
Parents: 779f0cb
Author: Pradeep Fernando <[email protected]>
Authored: Wed Jan 15 18:59:07 2014 +0530
Committer: Pradeep Fernando <[email protected]>
Committed: Wed Jan 15 18:59:07 2014 +0530

----------------------------------------------------------------------
 .../console/config/console.json                 | 12 +++
 .../console/controllers/router.jag              | 91 ++++++++++++++++++++
 .../console/jaggery.conf                        | 13 ++-
 .../modules/security/security.manager.js        | 73 ++++++++++++++++
 .../modules/security/security.provider.js       | 51 +++++++++++
 .../modules/console/module.xml                  |  8 ++
 .../modules/console/scripts/server.js           | 20 +++++
 .../modules/distribution/src/assembly/bin.xml   |  4 +
 8 files changed, 271 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/465f3bc3/components/org.apache.stratos.manager.console/console/config/console.json
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/console/config/console.json 
b/components/org.apache.stratos.manager.console/console/config/console.json
index e91e850..589a8e6 100644
--- a/components/org.apache.stratos.manager.console/console/config/console.json
+++ b/components/org.apache.stratos.manager.console/console/config/console.json
@@ -9,6 +9,18 @@
         "tokenEndpoint":"https://localhost:9445/oauth2/token";
     },
 
+    "paths": {
+        "ASSET_EXT_PATH": "/assets",
+        "ASSET_DEFAULT_PATH": "/assets/default",
+        "ASSETS_EXT_PATH": "/assets",
+        "ASSETS_DEFAULT_PATH": "/assets/default",
+        "RXT_EXTENSION_PATH": "/config/ext/"
+    },
+
+    "urls": {
+        "MGT": "/mgt"
+    },
+
     "ssoConfiguration": {
         "enabled": true,
         "issuer": "console",

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/465f3bc3/components/org.apache.stratos.manager.console/console/controllers/router.jag
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/console/controllers/router.jag 
b/components/org.apache.stratos.manager.console/console/controllers/router.jag
new file mode 100644
index 0000000..feb4cfd
--- /dev/null
+++ 
b/components/org.apache.stratos.manager.console/console/controllers/router.jag
@@ -0,0 +1,91 @@
+<%
+
+(function(){
+    var config=require('/config/console.json');
+
+    var DEFAULT_ROUTER_NAME='/asset.jag';
+    var EXT_ROUTER_NAME='/pages/asset.jag';
+    var EXT_PATH=config.paths.ASSET_EXT_PATH;
+    var DEFAULT_PATH=config.paths.ASSET_DEFAULT_PATH;
+    var URL=config.urls.MGT;
+
+    var MSG_404='Asset not found';     //Eror 404 message
+
+    var 
securityModule=require('/modules/security/security.manager.js').securityManagementModule();
+
+    var sm=securityModule.cached();
+
+    //This will short circuit the handling of the requests
+    //var passed=sm.check(session);
+    var passed=true;
+
+    //Stop servicing the request if the check failed
+    if(!passed){
+        return;
+    }
+
+    /*
+     Checks the pattern array with the request uri
+     @pattern:     An array of patterns e.g./{context}/[ASSET_PATH]/{type}
+     @uriMatcher : A URIMatcher object
+     @return: true if the pattern matches,else false
+     */
+    function isMatchingPattern(patterns,uriMatcher){
+
+        for each(var pattern in patterns){
+
+            if(uriMatcher.match(pattern)){
+
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
+    var matcher=new URIMatcher(request.getRequestURI());
+
+
+    var patterns=[ '/{context}'+URL+'/{type}/{+suffix}',
+        '/{context}'+URL+'/{type}'];
+
+
+
+    if(isMatchingPattern(patterns,matcher)){
+
+        var params=matcher.elements();
+
+        var theme=params.theme;
+        var type=params.type;
+        var log = new Log("stratos.router");
+        log.info("type : "+ params.type);
+        log.info("context :"+ params.cotext);
+        var extLocation ='/'+type;
+        var path = extLocation; //Assume there is an extension
+        log.info(path);
+
+
+        //Check if an extension asset router exists
+        var fileTester=new File(path);
+
+        if(fileTester.isExists()){
+            request.getMappedPath = function() {
+                return path;
+            };
+            include(path);
+            return;
+        }
+
+        //Set the default path
+        path=DEFAULT_PATH+DEFAULT_ROUTER_NAME;
+
+        //Default
+        include(path);
+        return;
+    }
+
+    response.sendError(404,MSG_404);
+
+}());
+%>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/465f3bc3/components/org.apache.stratos.manager.console/console/jaggery.conf
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/console/jaggery.conf 
b/components/org.apache.stratos.manager.console/console/jaggery.conf
index c26875e..0c7ce62 100644
--- a/components/org.apache.stratos.manager.console/console/jaggery.conf
+++ b/components/org.apache.stratos.manager.console/console/jaggery.conf
@@ -1,3 +1,14 @@
 {
-    "initScripts": ["app.js"]
+    "initScripts": ["app.js"],
+    "logLevel": "info",
+    "urlMappings":[
+                {
+                    "url":"/mgt/*",
+                    "path":"/controllers/router.jag"
+                },
+                {
+                     "url":"/login",
+                     "path":"/controllers/login.jag"
+                }
+            ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/465f3bc3/components/org.apache.stratos.manager.console/console/modules/security/security.manager.js
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/console/modules/security/security.manager.js
 
b/components/org.apache.stratos.manager.console/console/modules/security/security.manager.js
new file mode 100644
index 0000000..59c975b
--- /dev/null
+++ 
b/components/org.apache.stratos.manager.console/console/modules/security/security.manager.js
@@ -0,0 +1,73 @@
+/*
+Description: The class is used to manage the security aspects of the app
+Created Date: 5/10/2013
+Filename: security.manager.js
+ */
+securityManagementModule=function(){
+
+    var APP_SECURITY_MANAGER='security.manager';
+    var 
provider=require('/modules/security/security.provider.js').securityModule();
+    var log=new Log('security.manager');
+
+    function SecurityManager(){
+        this.provider=provider;
+    }
+
+
+    /*
+    The function is used to perform a security check on a request
+    @cb: An optional callback function which will be invoked if a check fails
+    @return: True if the check passes,else false
+     */
+    SecurityManager.prototype.check=function(session,cb){
+
+        var passed=false;
+
+        //Checks whether the request can be handled
+        if(this.provider.isPermitted(session)){
+            log.debug('passed the security check.');
+
+            this.provider.onSecurityCheckPass();
+
+            passed=true;
+        }
+        else{
+            log.debug('failed the security check.');
+
+            //Check if a user has provided a call back
+            if(cb){
+                cb();
+            }
+            else{
+                this.provider.onSecurityCheckFail();
+            }
+
+        }
+
+        return passed;
+    }
+
+    /*
+    The function is used to obtain a cached copy of the
+    SecurityManager
+    @return: A cached copy of the Security Manager from the
+            application context
+     */
+    function cached(){
+       //var instance=application.get(APP_SECURITY_MANAGER);
+
+       //Checks if an instance exists
+       //if(!instance){
+           instance=new SecurityManager();
+       //}
+
+       return instance;
+    }
+
+    return {
+        SecurityManager:SecurityManager,
+        cached:cached
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/465f3bc3/components/org.apache.stratos.manager.console/console/modules/security/security.provider.js
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/console/modules/security/security.provider.js
 
b/components/org.apache.stratos.manager.console/console/modules/security/security.provider.js
new file mode 100644
index 0000000..b21b4ac
--- /dev/null
+++ 
b/components/org.apache.stratos.manager.console/console/modules/security/security.provider.js
@@ -0,0 +1,51 @@
+/*
+ Description:The class is used to secure pages by checking if a user is logged 
before
+             accessing a page
+ Created Date: 5/10/2013
+ Filename: url.security.provider.js
+ */
+
+var securityModule = function () {
+
+    var LOGGED_IN_USER = 'LOGGED_IN_USER';
+    var log=new Log('security.provider');
+
+    /*
+     The function checks if a user is present in the session
+     @return: True if the user is allowed to access the url,else false
+     */
+    function isPermitted(session) {
+
+        //Obtain the session and check if there is a user
+        var user = require('console').server.current(session);
+        if (user) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /*
+     The function is invoked when the the security check fails
+     and redirects the user to the login page
+     */
+    function onSecurityCheckFail() {
+        log.debug('security check failed redirecting...');
+        response.sendRedirect('/console/login');
+    }
+
+    /*
+     The function is invoked when the security check is passed
+     */
+    function onSecurityCheckPass() {
+        //Do nothing for now :)
+    }
+
+    return{
+
+        isPermitted: isPermitted,
+        onSecurityCheckFail: onSecurityCheckFail,
+        onSecurityCheckPass: onSecurityCheckPass
+
+    }
+};

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/465f3bc3/components/org.apache.stratos.manager.console/modules/console/module.xml
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/modules/console/module.xml 
b/components/org.apache.stratos.manager.console/modules/console/module.xml
new file mode 100644
index 0000000..b94fe3c
--- /dev/null
+++ b/components/org.apache.stratos.manager.console/modules/console/module.xml
@@ -0,0 +1,8 @@
+<module name="console" xmlns="http://wso2.org/projects/jaggery/module.xml";>
+   <script>
+       <name>[console]/server.js</name>
+       <path>scripts/server.js</path>
+   </script>
+</module>
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/465f3bc3/components/org.apache.stratos.manager.console/modules/console/scripts/server.js
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/modules/console/scripts/server.js
 
b/components/org.apache.stratos.manager.console/modules/console/scripts/server.js
new file mode 100644
index 0000000..6d68019
--- /dev/null
+++ 
b/components/org.apache.stratos.manager.console/modules/console/scripts/server.js
@@ -0,0 +1,20 @@
+var server = {};
+
+(function (server) {
+
+    var USER = 'server.user';
+
+    var log = new Log();
+    
+    /**
+     * Returns the currently logged in user
+    */
+    server.current = function (session, user) {
+        if (arguments.length > 1) {
+            session.put(USER, user);
+            return user;
+        }
+        return session.get(USER);
+    };
+    
+}(server));

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/465f3bc3/products/stratos-manager/modules/distribution/src/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/stratos-manager/modules/distribution/src/assembly/bin.xml 
b/products/stratos-manager/modules/distribution/src/assembly/bin.xml
index 59c96d7..4cc90bd 100755
--- a/products/stratos-manager/modules/distribution/src/assembly/bin.xml
+++ b/products/stratos-manager/modules/distribution/src/assembly/bin.xml
@@ -99,6 +99,10 @@
             
<directory>../../../../components/org.apache.stratos.manager.console/sso</directory>
             
<outputDirectory>${pom.artifactId}-${pom.version}/repository/deployment/server/jaggeryapps/sso</outputDirectory>
         </fileSet>
+         <fileSet>
+            
<directory>../../../../components/org.apache.stratos.manager.console/modules/console</directory>
+            
<outputDirectory>${pom.artifactId}-${pom.version}/modules/console</outputDirectory>
+        </fileSet>
         <fileSet>
             
<directory>target/wso2carbon-core-${carbon.kernel.version}</directory>
             <outputDirectory>${pom.artifactId}-${pom.version}</outputDirectory>

Reply via email to