groovity.portal.controller.grvt Maven / Gradle / Ivy
/*******************************************************************************
* © 2018 Disney | ABC Television Group
*
* Licensed under the Apache License, Version 2.0 (the "Apache License")
* with the following modification; you may not use this file except in
* compliance with the Apache License and the following modification to it:
* Section 6. Trademarks. is deleted and replaced with:
*
* 6. Trademarks. This License does not grant permission to use the trade
* names, trademarks, service marks, or product names of the Licensor
* and its affiliates, except as required to comply with Section 4(c) of
* the License and to reproduce the content of the NOTICE file.
*
* You may obtain a copy of the Apache License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Apache License with the above modification is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the Apache License for the specific
* language governing permissions and limitations under the Apache License.
*******************************************************************************/
static conf=[
PORTAL_AUTH_REALM:'Portal'
]
static web = [
path: "/{pageLookup : .*}",
output:"text/html",
charset:"UTF-8",
methods:['GET','POST']
]
static args=[
pageLookup:null,
pageRoleAction:null,
mode:null,
userName:null,
fullName:null,
nickName:null,
digest:null
]
static portal = [
title:'Portal',
roles:["anon","auth"]
];
@Field portalLib = load('/groovity/portal/lib/portal');
load '/data/factory'
//define common binding variables for providing feedback from form processing
formError = null;
formMessage = null;
//lookup portal page metadata from sitemap
portalPageConfig = null;
def isBootstrapped = portalLib.isBootstrapped();
if(!isBootstrapped && userName && request.method=='POST'){
//process bootstrap form
try{
def newPerson = factory('person').putAll([userName:userName,fullName:fullName,nickName:nickName,digest:digest])
newPerson.bootstrap()
formMessage = "Superuser '${userName}' created, please login to make further changes"
isBootstrapped = true;
}
catch(Exception e){
formError = e;
log(error:"Error in form processing",thrown:e);
}
}
if(isBootstrapped){
def lookup1 = "/${pageLookup}";
def lookup2 = "/${pageLookup}/";
def lookup3 = "/${pageLookup}${pageLookup?'/':''}index";
portalPageConfig = portalLib.sitemap.find{ it.path==lookup1 || it.path==lookup2 || it.path==lookup3 }
}
if(!portalPageConfig){
portalPageConfig = portalLib.sitemap.find{ it.scriptPath=='/groovity/portal/controller' }
}
def rolePath = portalPageConfig.path ?: "/${pageLookup}";
hasAdminRole = request.userPrincipal?.hasRole(request.session, rolePath, ['admin']);
if(request.method=='POST'){
//process page role form submission
if(hasAdminRole && request.method=="POST" && pageRoleAction){
if(pageRoleAction=='update'){
def pageRoles = request.parameterMap.keySet().findAll{ it.startsWith('pageRole_') }.collect { it.substring(9) }
request.session.getAttribute('pageRoles').put(rolePath,pageRoles)
}
else if(pageRoleAction=='reset'){
request.session.getAttribute('pageRoles').remove(rolePath)
}
}
}
roles = request.session?.getAttribute('pageRoles')?.get(rolePath)
if(roles==null){
if(request.userPrincipal){
roles = request.userPrincipal.getRoles(request.session, rolePath, portalPageConfig.roles)
}
else if(portalPageConfig.roles.contains('anon')){
roles = ['anon']
}
else{
roles = []
}
}
if(portalPageConfig.scriptPath != '/groovity/portal/controller'){
if(portalPageConfig.roles){
if(roles.isEmpty()){
response.sendError(403,'You lack permission to see this page')
return;
}
}
run(portalPageConfig.scriptPath)
}
else if(pageLookup && isBootstrapped){
response.sendError(404,"No page found at ${pageLookup}")
}
else{
return <~
Portal
noun | \ˈˈpȯr-təl\
Door, Entrance
Bootstrap
Please create a local superuser account, which you will then use to configure other accounts and roles.
Welcome
Please login
~>
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy