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);
}
Aggregations