Search in sources :

Example 1 with RowData

use of jp.ossc.nimbus.recset.RowData in project nimbus by nimbus-org.

the class BlockadeInterceptorService method invokeFilter.

/**
 * コードマスタの閉塞マスタ及び特権ユーザマスタをチェックして、閉塞状態の場合は例外をthrowする。
 * <p>
 * サービスが開始されていない場合は、何もせずに次のインターセプタを呼び出す。<br>
 *
 * @param context 呼び出しのコンテキスト情報
 * @param chain 次のインターセプタを呼び出すためのチェーン
 * @return 呼び出し結果の戻り値
 * @exception Throwable 呼び出し先で例外が発生した場合、またはこのインターセプタで任意の例外が発生した場合。但し、
 *                本来呼び出される処理がthrowしないRuntimeException以外の例外をthrowしても
 *                、呼び出し元には伝播されない。
 */
public Object invokeFilter(ServletFilterInvocationContext context, InterceptorChain chain) throws Throwable {
    if (getState() != STARTED) {
        return chain.invokeNext(context);
    }
    final HttpServletRequest request = (HttpServletRequest) context.getServletRequest();
    String reqPath = request.getServletPath();
    if (request.getPathInfo() != null) {
        reqPath = reqPath + request.getPathInfo();
    }
    Map codeMasters = null;
    if (codeMasterFinder != null) {
        codeMasters = codeMasterFinder.getCodeMasters();
    } else {
        codeMasters = (Map) threadContext.get(ThreadContextKey.CODEMASTER);
    }
    if (codeMasters == null) {
        throw new BlockadeProcessException("CodeMaster is null.");
    }
    Object blockadeCodeMaster = codeMasters.get(blockadeCodeMasterKey);
    if (blockadeCodeMaster == null) {
        throw new BlockadeProcessException("BlockadeCodeMaster is null. key=" + blockadeCodeMasterKey);
    }
    Object specialUserCodeMaster = null;
    if (specialUserCodeMasterKey != null) {
        specialUserCodeMaster = codeMasters.get(specialUserCodeMasterKey);
    }
    boolean isSpecialUser = false;
    String userKey = null;
    if (specialUserCodeMaster != null) {
        Object requestObject = request.getAttribute(requestObjectAttributeName);
        if (requestObject == null) {
            throw new BlockadeProcessException("RequestObject is null.");
        }
        if (specialUserCodeMaster instanceof RecordList) {
            RecordList list = (RecordList) specialUserCodeMaster;
            Record primaryKey = list.createRecord();
            applySpecialUserMapping(requestObject, primaryKey);
            userKey = primaryKey.toString();
            isSpecialUser = list.searchByPrimaryKey(primaryKey) != null;
        } else if (specialUserCodeMaster instanceof RecordSet) {
            RecordSet recset = (RecordSet) specialUserCodeMaster;
            RowData primaryKey = recset.createNewRecord();
            applySpecialUserMapping(requestObject, primaryKey);
            userKey = primaryKey.getKey();
            isSpecialUser = recset.get(primaryKey) != null;
        } else {
            throw new BlockadeProcessException("Unsupported type of SpecialUserCodeMaster. type=" + specialUserCodeMaster.getClass());
        }
    }
    if (pathPatternMap == null) {
        initPathPatternMap(blockadeCodeMaster);
    }
    Map blockadeFilterMap = null;
    if (blockadeMapping != null) {
        Object requestObject = request.getAttribute(requestObjectAttributeName);
        if (requestObject == null) {
            throw new BlockadeProcessException("RequestObject is null.");
        }
        blockadeFilterMap = new HashMap();
        Iterator entries = blockadeMapping.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            try {
                blockadeFilterMap.put(entry.getValue(), propertyAccess.get(requestObject, (String) entry.getKey()));
            } catch (IllegalArgumentException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e);
            } catch (NoSuchPropertyException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e);
            } catch (InvocationTargetException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e.getTargetException());
            }
        }
    }
    if (blockadeCodeMaster instanceof List) {
        List list = (List) blockadeCodeMaster;
        for (int i = 0, imax = list.size(); i < imax; i++) {
            Object blockade = list.get(i);
            if (blockadeFilterMap != null) {
                if (!isMatchBlockadeMapping(blockadeFilterMap, blockade)) {
                    continue;
                }
            }
            checkBlockade(reqPath, blockade, isSpecialUser, userKey);
        }
    } else if (blockadeCodeMaster instanceof RecordSet) {
        RecordSet recset = (RecordSet) blockadeCodeMaster;
        for (int i = 0, imax = recset.size(); i < imax; i++) {
            Object blockade = recset.get(i);
            if (blockadeFilterMap != null) {
                if (!isMatchBlockadeMapping(blockadeFilterMap, blockade)) {
                    continue;
                }
            }
            checkBlockade(reqPath, blockade, isSpecialUser, userKey);
        }
    } else {
        throw new BlockadeProcessException("Unsupported type of BlockadeCodeMaster. type=" + blockadeCodeMaster.getClass());
    }
    return chain.invokeNext(context);
}
Also used : HashMap(java.util.HashMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) RowData(jp.ossc.nimbus.recset.RowData) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) Iterator(java.util.Iterator) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) Record(jp.ossc.nimbus.beans.dataset.Record) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) List(java.util.List) RecordSet(jp.ossc.nimbus.recset.RecordSet) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchPropertyException (jp.ossc.nimbus.beans.NoSuchPropertyException)1 Record (jp.ossc.nimbus.beans.dataset.Record)1 RecordList (jp.ossc.nimbus.beans.dataset.RecordList)1 RecordSet (jp.ossc.nimbus.recset.RecordSet)1 RowData (jp.ossc.nimbus.recset.RowData)1