KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > event > CheckAdminOrOwnerRoleInterceptor


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.core.event;
6
7 import javax.faces.context.ExternalContext;
8 import javax.faces.context.FacesContext;
9 import org.exoplatform.commons.exception.ExoMessageException;
10 import org.exoplatform.container.SessionContainer;
11 import org.exoplatform.portal.session.RequestInfo;
12 /**
13  * Jun 3, 2004
14  * @author: Tuan Nguyen
15  * @email: tuan08@users.sourceforge.net
16  * @version: $ID$
17  **/

18 public class CheckAdminOrOwnerRoleInterceptor extends ActionInterceptor {
19     
20     public void preExecute(ExoActionEvent event) throws Exception JavaDoc {
21     ExternalContext econtext = FacesContext.getCurrentInstance().getExternalContext() ;
22     RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class) ;
23     if(rinfo.getPortalOwner().equals(econtext.getRemoteUser())) {
24       return ;
25     }
26     if (econtext.isUserInRole("admin") ) {
27       return ;
28     }
29     Object JavaDoc[] args = {event.getAction()} ;
30     throw new ExoMessageException("CheckAdminOrOwnerRoleInterceptor.msg.owner-or-admin-require", args) ;
31     }
32     
33     final public void postExecute(ExoActionEvent event) throws Exception JavaDoc {
34         
35     }
36 }
Popular Tags