From: <mb...@re...> - 2004-11-22 18:57:08
|
Author: mbooth Date: 2004-11-22 19:48:25 +0100 (Mon, 22 Nov 2004) New Revision: 119 Added: ccm-ldn-util/trunk/src/com/arsdigita/london/util/ApplicationAdminAuthListener.java Log: Bring in ApplicationAdminAuthListener from former 1.4 branch Added: ccm-ldn-util/trunk/src/com/arsdigita/london/util/ApplicationAdminAuthListener.java =================================================================== --- ccm-ldn-util/trunk/src/com/arsdigita/london/util/ApplicationAdminAuthListener.java 2004-11-22 17:10:35 UTC (rev 118) +++ ccm-ldn-util/trunk/src/com/arsdigita/london/util/ApplicationAdminAuthListener.java 2004-11-22 18:48:25 UTC (rev 119) @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2001, 2002 Red Hat Inc. All Rights Reserved. + * + * The contents of this file are subject to the CCM Public + * License (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.redhat.com/licenses/ccmpl.html + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + */ + +package com.arsdigita.london.util; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.RequestEvent; +import com.arsdigita.bebop.event.RequestListener; + +import com.arsdigita.dispatcher.AccessDeniedException; +import com.arsdigita.dispatcher.DispatcherHelper; + + +import com.arsdigita.web.Application; +import com.arsdigita.kernel.Kernel; +import com.arsdigita.kernel.Party; +import com.arsdigita.kernel.permissions.PermissionDescriptor; +import com.arsdigita.kernel.permissions.PermissionService; +import com.arsdigita.kernel.permissions.PrivilegeDescriptor; + + +import com.arsdigita.ui.login.UserAuthenticationListener; + +import java.io.IOException; +import org.apache.log4j.Logger; + +/** + * A RequestListener that can check to see if a user + * has or doesn't have a given privilege on the current + * ApplicationInstance. + * + * The user is redirected to ACCESS_DENIED if their is + * insufficient permission. + * + * @param privilegeName a String that represents the privlege name for the + * privilege a user must have to see the page. + * + */ +public class ApplicationAdminAuthListener + extends UserAuthenticationListener + implements RequestListener { + + private static final Logger s_log = Logger.getLogger + (ApplicationAdminAuthListener.class); + + public ApplicationAdminAuthListener() { + super(); + } + + + /** + * Checks whether the user is logged in. If not, redirects the client + * to the login page. + */ + public void pageRequested(RequestEvent event) { + super.pageRequested(event); + + PageState state = event.getPageState(); + + /* Get the current party */ + Party party = Kernel.getContext().getParty(); + + /* Get the current package */ + Application app = (Application)Kernel.getContext().getResource(); + + PermissionDescriptor permDescriptor = + new PermissionDescriptor(PrivilegeDescriptor.ADMIN, + app, + party); + + if (!PermissionService.checkPermission(permDescriptor)) { + throw new AccessDeniedException("not an administrator for this application"); + } + } +} |