001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.uif.view;
017
018import java.io.Serializable;
019import java.util.HashMap;
020import java.util.Map;
021
022/**
023 * Provides cache objects for KIM authorization during a single request
024 *
025 * @author Kuali Rice Team (rice.collab@kuali.org)
026 */
027public class RequestAuthorizationCache implements Serializable {
028    private static final long serialVersionUID = 4773874972787299349L;
029
030    private Map<String, Boolean> permissionResultCache;
031
032    public RequestAuthorizationCache() {
033        permissionResultCache = new HashMap<String, Boolean>();
034    }
035
036    /**
037     * Map that can be used to cache results of permission checks for a request
038     *
039     * @return
040     */
041    public Map<String, Boolean> getPermissionResultCache() {
042        return permissionResultCache;
043    }
044
045    public boolean hasPermissionResult(String resultKey) {
046        return permissionResultCache.containsKey(resultKey);
047    }
048
049    public Boolean getPermissionResult(String resultKey) {
050        Boolean result = null;
051
052        if (hasPermissionResult(resultKey)) {
053            result = Boolean.valueOf(permissionResultCache.get(resultKey));
054        }
055
056        return result;
057    }
058
059    public void addPermissionResult(String resultKey, boolean result) {
060        permissionResultCache.put(resultKey, Boolean.valueOf(result));
061    }
062}