8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3371be256ea01dd6e09b2d28c64b495c3d43e32bMark de Reeper *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
3371be256ea01dd6e09b2d28c64b495c3d43e32bMark de Reeper *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
3371be256ea01dd6e09b2d28c64b495c3d43e32bMark de Reeper *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
3371be256ea01dd6e09b2d28c64b495c3d43e32bMark de Reeper *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
3371be256ea01dd6e09b2d28c64b495c3d43e32bMark de Reeper *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: CacheBlock.java,v 1.4 2008/06/25 05:41:23 qcheng Exp $
3371be256ea01dd6e09b2d28c64b495c3d43e32bMark de Reeper *
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper * Portions Copyrighted 2016 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.iplanet.am.sdk.common;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.util.SystemProperties;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class represents the value part stored in the AMCacheManager's cache.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Each CacheBlock object would represent a Directory entry. It caches the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attributes corresponding to that entry. It also keeps track of red other
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * details such as the Organization DN for the entry.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <p>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Also, this cache block can be used to serve as dummy block representing a
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * non-existent directory entry (negative caching). This prevents making
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * un-necessary directory calls for non-existent directory entries.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <p>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Since the attributes that can be retrieved depends on the principal
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * performing the operation (ACI's set), the result set would vary. The
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attributes that are returned are the ones that are readable by the principal.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Each cache block keeps account of these differences in result sets by storing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * all the attributes readable (and writable) on a per principal basis. This
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * information is stored in a PrincipalAccess object. In order to avoid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * duplicate copy of the values, the all attribute values are not cached per
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * principal. A single copy of the attributes is stored in the CacheBlock
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * object. Also this copy of attributes stored in the cache block keeps track of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * non-existent directory attributes (invalid attributes). This would also
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * prevent un-necessary directory calls for non-existent entry attributes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The attribute copy is dirtied by removing the entries which get modified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class CacheBlock extends CacheBlockBase {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // CONSTANTS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ENTRY_EXPIRATION_ENABLED_KEY =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.iplanet.am.sdk.cache.entry.expire.enabled";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ENTRY_USER_EXPIRE_TIME_KEY =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.iplanet.am.sdk.cache.entry.user.expire.time";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ENTRY_DEFAULT_EXPIRE_TIME_KEY =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.iplanet.am.sdk.cache.entry.default.expire.time";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static boolean ENTRY_EXPIRATION_ENABLED_FLAG = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static long ENTRY_USER_EXPIRE_TIME;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static long ENTRY_DEFAULT_EXPIRE_TIME;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper private static final Debug DEBUG = Debug.getInstance("amProfile_ldap");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static {
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper ENTRY_EXPIRATION_ENABLED_FLAG = SystemProperties.getAsBoolean(ENTRY_EXPIRATION_ENABLED_KEY, false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ENTRY_EXPIRATION_ENABLED_FLAG) {
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper // Read the expiration times for user and non user entries, convert to milliseconds
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper ENTRY_USER_EXPIRE_TIME = SystemProperties.getAsInt(ENTRY_USER_EXPIRE_TIME_KEY, 15) * 60000;
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper ENTRY_DEFAULT_EXPIRE_TIME = SystemProperties.getAsInt(ENTRY_DEFAULT_EXPIRE_TIME_KEY, 30) * 60000;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean isEntryExpirationEnabled() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ENTRY_EXPIRATION_ENABLED_FLAG;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public long getUserEntryExpirationTime() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ENTRY_USER_EXPIRE_TIME;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public long getDefaultEntryExpirationTime() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ENTRY_DEFAULT_EXPIRE_TIME;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper public Debug getDebug() {
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper return DEBUG;
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper }
fdd3077db2228482076ca7f288c80761f311ea0eMark de Reeper
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public CacheBlock(String entryDN, boolean validEntry) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster super(entryDN, validEntry);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public CacheBlock(String entryDN, String orgDN, boolean validEntry) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster super(entryDN, orgDN, validEntry);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}