001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2016 ForgeRock AS. 016 */ 017package org.forgerock.opendj.config.client; 018 019import java.util.Collection; 020 021import org.forgerock.i18n.LocalizableMessage; 022import org.forgerock.opendj.config.ManagedObjectPath; 023import org.forgerock.opendj.ldap.LdapException; 024 025/** 026 * An interface for performing client-side constraint validation. 027 * <p> 028 * Constraints are evaluated immediately before the client performs a write 029 * operation. If one or more constraints fails, the write operation is refused 030 * and fails with an {@link OperationRejectedException}. 031 * <p> 032 * A client constraint handler must override at least one of the provided 033 * methods. 034 * 035 * @see org.forgerock.opendj.config.Constraint 036 */ 037public abstract class ClientConstraintHandler { 038 039 /** Creates a new client constraint handler. */ 040 protected ClientConstraintHandler() { 041 // No implementation required. 042 } 043 044 /** 045 * Determines whether the newly created managed object which is about 046 * to be added to the server configuration satisfies this constraint. 047 * <p> 048 * If the constraint is not satisfied, the implementation must return 049 * <code>false</code> and add a message describing why the constraint was 050 * not satisfied. 051 * <p> 052 * The default implementation is to return <code>true</code>. 053 * 054 * @param context 055 * The management context. 056 * @param managedObject 057 * The new managed object. 058 * @param unacceptableReasons 059 * A list of messages to which error messages should be added. 060 * @return Returns <code>true</code> if this constraint is satisfied, or 061 * <code>false</code> if it is not. 062 * @throws LdapException 063 * If an error occurs. 064 */ 065 public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, 066 Collection<LocalizableMessage> unacceptableReasons) throws LdapException { 067 return true; 068 } 069 070 /** 071 * Determines whether the changes to an existing managed object which 072 * are about to be committed to the server configuration satisfies this 073 * constraint. 074 * <p> 075 * If the constraint is not satisfied, the implementation must return 076 * <code>false</code> and add a message describing why the constraint was 077 * not satisfied. 078 * <p> 079 * The default implementation is to return <code>true</code>. 080 * 081 * @param context 082 * The management context. 083 * @param managedObject 084 * The modified managed object. 085 * @param unacceptableReasons 086 * A list of messages to which error messages should be added. 087 * @return Returns <code>true</code> if this modify is satisfied, or 088 * <code>false</code> if it is not. 089 * @throws LdapException 090 * If an error occurs. 091 */ 092 public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, 093 Collection<LocalizableMessage> unacceptableReasons) throws LdapException { 094 return true; 095 } 096 097 /** 098 * Determines whether the existing managed object which is about to 099 * be deleted from the server configuration satisfies this constraint. 100 * <p> 101 * If the constraint is not satisfied, the implementation must return 102 * <code>false</code> and add a message describing why the constraint was 103 * not satisfied. 104 * <p> 105 * The default implementation is to return <code>true</code>. 106 * 107 * @param context 108 * The management context. 109 * @param path 110 * The path of the managed object which is about to be deleted. 111 * @param unacceptableReasons 112 * A list of messages to which error messages should be added. 113 * @return Returns <code>true</code> if this constraint is satisfied, or 114 * <code>false</code> if it is not. 115 * @throws LdapException 116 * If an error occurs. 117 */ 118 public boolean isDeleteAcceptable(ManagementContext context, ManagedObjectPath<?, ?> path, 119 Collection<LocalizableMessage> unacceptableReasons) throws LdapException { 120 return true; 121 } 122}