Java tutorial
/** * PureInfo Quake * @(#)Guarder.java 1.0 Oct 31, 2005 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.config.workflow.function; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import com.pureinfo.ark.auth.model.IUser; import com.pureinfo.ark.auth2.Auth2Helper; import com.pureinfo.ark.auth2.domain.IAuth2Mgr; import com.pureinfo.ark.content.model.ArkContent; import com.pureinfo.ark.interaction.view.ViewGuarderImplBase; import com.pureinfo.dolphin.script.function.handler.FunctionHandlerUtil; import com.pureinfo.force.exception.PureException; import com.pureinfo.srm.contract.model.Contract; import com.pureinfo.srm.project.model.OutlayUnit; /** * <P> * Created on Oct 31, 2005 9:42:43 AM <BR> * Last modified on Oct 31, 2005 * </P> * * @author Daniel.Wang * @version 1.0, Oct 31, 2005 * @since Quake 1.0 */ public class ProjectGuarder extends ViewGuarderImplBase { private final static Logger logger = Logger.getLogger(ProjectGuarder.class.getName()); /** minimum number of arguments */ public final static int MIN_ARGS_NUM = 2; /** argument index: object */ private final static int ARG_OBJECT = 0; /** argument index: action */ private final static int ARG_ACTION = 1; /** * @see com.pureinfo.ark.interaction.view.ViewGuarderImplBase#checkPass(com.pureinfo.ark.content.model.ArkContent, * com.pureinfo.ark.auth.model.IUser, java.lang.Object[]) */ protected boolean checkPass(ArkContent _content, IUser _user, Object[] _args) throws PureException { //1. to validate the arguments number FunctionHandlerUtil.validateArgsNum(_args, MIN_ARGS_NUM); //2. to find the resource ArkContent resource = _content; String sObject = (String) _args[ARG_OBJECT]; if (sObject != null && (sObject = sObject.trim()).length() > 0) { sObject = sObject.toLowerCase(); if ("outlayunit".equals(sObject)) { resource = new OutlayUnit(); ((OutlayUnit) resource).setProjectId(_content.getId()); } else if ("contract".equals(sObject)) { resource = new Contract(); ((Contract) resource).setProjectId(_content.getId()); } } if (logger.isDebugEnabled()) { logger.debug("resource:" + resource.toString() + ", actions=" + _args[ARG_ACTION]); } //3. to validate the authorization for user IAuth2Mgr authMgr = Auth2Helper.getManager(); String[] actions = StringUtils.split((String) _args[ARG_ACTION], "|"); for (int i = 0; i < actions.length; i++) { int nActionIndex = authMgr.indexOfAction(actions[i], true); if (authMgr.hasRight(_user, resource, nActionIndex, false)) return true; } //else return false; } }