1 46 47 package org.mr.kernel.security.authorization; 48 49 import org.mr.MantaAgent; 50 import org.mr.kernel.security.SecurityConfigurationPaths; 51 import org.mr.kernel.security.SecurityConstants; 52 import org.apache.commons.logging.Log; 53 import org.apache.commons.logging.LogFactory; 54 55 import java.util.Map ; 56 import java.util.HashMap ; 57 58 69 public class MantaWhiteListCache extends MantaCache implements SecurityConfigurationPaths, SecurityConstants { 70 private Map _cache; 72 private Log _logger; 73 74 78 public MantaWhiteListCache(){ 79 _cache = new HashMap (); 80 _timeToLive = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getLongProperty(ACL + "." + WHITE_LIST_CACHE_TTL, DEFAULT_WHITE_LIST_CACHE_TIME_TO_LIVE); 81 } 82 83 89 public void add(ACLKeyEntry keyEntry, AuthorizationValue authorizationValue){ 90 if (!(keyEntry instanceof WhiteListKeyEntry)) 91 return; 92 WhiteListKeyEntry whiteListEntry = (WhiteListKeyEntry) keyEntry; 93 if (getLogger().isDebugEnabled()) 94 getLogger().debug("[add] Adding: key = [" + whiteListEntry + "], value = [" + authorizationValue + "] to the white list cache."); 95 _cache.put(whiteListEntry, authorizationValue); 96 } 97 98 105 public AuthorizationValue isAuthorized(ACLKeyEntry keyEntry){ 106 if (!(keyEntry instanceof WhiteListKeyEntry)) 107 return null; 108 WhiteListKeyEntry whiteListEntry = (WhiteListKeyEntry) keyEntry; 109 if (_cache.containsKey(whiteListEntry)){ 110 AuthorizationValue value = (AuthorizationValue) _cache.get(whiteListEntry); 111 if (value.isValid(_timeToLive)){ 112 if (getLogger().isDebugEnabled()) 113 getLogger().debug("[isAuthorized] AuthorizationValue for key = [" + whiteListEntry + "] found and has valid TTL."); 114 return value; 115 } 116 } 117 return null; 118 } 119 120 126 public boolean contains(ACLKeyEntry keyEntry){ 127 if (!(keyEntry instanceof WhiteListKeyEntry)) 128 return false; 129 WhiteListKeyEntry whiteListEntry = (WhiteListKeyEntry) keyEntry; 130 return _cache.containsKey(whiteListEntry); 131 } 132 133 138 public Log getLogger(){ 139 if (_logger == null){ 140 _logger = LogFactory.getLog(getClass().getName()); 141 } 142 return _logger; 143 } 144 } 145 | Popular Tags |