| <% |
| /* |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF 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. |
| * |
| */ |
| |
| (function(){ |
| var carbon = require('carbon'); |
| var conf = carbon.server.loadConfig('carbon.xml'); |
| var offset = conf.*::['Ports'].*::['Offset'].text(); |
| var hostName = conf.*::['HostName'].text().toString(); |
| |
| if (hostName === null || hostName === '') { |
| hostName = 'localhost'; |
| } |
| |
| var httpPort = 9763 + parseInt(offset, 10); |
| var httpsPort = 9443 + parseInt(offset, 10); |
| |
| var process = require('process'); |
| process.setProperty('server.host', hostName); |
| process.setProperty('http.port', httpPort.toString()); |
| process.setProperty('https.port', httpsPort.toString()); |
| |
| var config=require('/config/console.js').config(); |
| var log = new Log("controller.router"); |
| var acl = require('/util/acl.jag'); |
| |
| var MSG_404='Asset not found'; //Eror 404 message |
| |
| var securityModule=require('/modules/security/security.manager.js').securityManagementModule(); |
| var file = require('/modules/file.js'); |
| |
| var sm=securityModule.cached(); |
| // |
| var matcher=new URIMatcher(request.getRequestURI()); |
| |
| // we stream css and other theme related resources found under themes directory. |
| if (matcher.match('/{context}/themes/{+file}')) { |
| elements = matcher.elements(); |
| file.send('/themes/' + elements.file); |
| return; |
| } |
| |
| //This will short circuit the handling of the requests |
| var passed=sm.check(session); |
| var tenantDomain = session.get("TENANT_DOMAIN"); |
| var roleArray = session.get("ROLE_ARRAY"); |
| |
| // comment out the above and uncomment below code bits for testing. It removes authentication/authorization |
| // of the app. |
| |
| //var passed=true; |
| //var tenantDomain = "carbon.super"; |
| //var roleArray = ["admin","Internal/Everyone"]; |
| |
| //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 patterns=['/{context}','/{context}/','/{context}/{+suffix}']; |
| if(isMatchingPattern(patterns,matcher)){ |
| |
| var params=matcher.elements(); |
| |
| var context=params.context; |
| var suffix=params.suffix; |
| var includePath ='/'; |
| if(!suffix){ |
| includePath += 'index.jag'; // index page rendering for /console |
| }else{ |
| includePath += suffix; |
| } |
| //check if the file path exists |
| var fileTester=new File(includePath); |
| |
| if(fileTester.isExists()){ |
| request.getMappedPath = function() { |
| return includePath; // setting path for caramel framework |
| }; |
| var permissionObject = acl.authorizationUtil.getPermissionObj(tenantDomain,roleArray); |
| request.permissions = permissionObject; |
| print(includePath); |
| include(includePath); |
| return; |
| } |
| |
| |
| /*var defaultPath='/default_page.jag'; |
| //Set the default path |
| request.getMappedPath = function() { |
| return defaultPath; // setting path for caramel framework |
| }; |
| include(defaultPath); |
| return; */ |
| } |
| |
| response.sendError(404,MSG_404); |
| |
| }()); |
| %> |