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 ForgeRock AS. 016 */ 017package org.opends.server.admin.client; 018 019 020 021import java.util.Collection; 022 023import org.forgerock.i18n.LocalizableMessage; 024import org.opends.server.admin.ManagedObjectPath; 025 026 027 028/** 029 * An interface for performing client-side constraint validation. 030 * <p> 031 * Constraints are evaluated immediately before the client performs a 032 * write operation. If one or more constraints fails, the write 033 * operation is refused and fails with an 034 * {@link OperationRejectedException}. 035 * <p> 036 * A client constraint handler must override at least one of the 037 * provided methods. 038 * 039 * @see org.opends.server.admin.Constraint 040 */ 041public abstract class ClientConstraintHandler { 042 043 /** 044 * Creates a new client constraint handler. 045 */ 046 protected ClientConstraintHandler() { 047 // No implementation required. 048 } 049 050 051 052 /** 053 * Determines whether or not the newly created managed object which 054 * is about to be added to the server configuration satisfies this 055 * constraint. 056 * <p> 057 * If the constraint is not satisfied, the implementation must 058 * return <code>false</code> and add a message describing why the 059 * constraint was not satisfied. 060 * <p> 061 * The default implementation is to return <code>true</code>. 062 * 063 * @param context 064 * The management context. 065 * @param managedObject 066 * The new managed object. 067 * @param unacceptableReasons 068 * A list of messages to which error messages should be 069 * added. 070 * @return Returns <code>true</code> if this constraint is 071 * satisfied, or <code>false</code> if it is not. 072 * @throws AuthorizationException 073 * If an authorization failure prevented this constraint 074 * from being evaluated. 075 * @throws CommunicationException 076 * If a communications problem prevented this constraint 077 * from being evaluated. 078 */ 079 public boolean isAddAcceptable(ManagementContext context, 080 ManagedObject<?> managedObject, Collection<LocalizableMessage> unacceptableReasons) 081 throws AuthorizationException, CommunicationException { 082 return true; 083 } 084 085 086 087 /** 088 * Determines whether or not the changes to an existing managed 089 * object which are about to be committed to the server 090 * configuration satisfies this constraint. 091 * <p> 092 * If the constraint is not satisfied, the implementation must 093 * return <code>false</code> and add a message describing why the 094 * constraint was not satisfied. 095 * <p> 096 * The default implementation is to return <code>true</code>. 097 * 098 * @param context 099 * The management context. 100 * @param managedObject 101 * The modified managed object. 102 * @param unacceptableReasons 103 * A list of messages to which error messages should be 104 * added. 105 * @return Returns <code>true</code> if this modify is satisfied, 106 * or <code>false</code> if it is not. 107 * @throws AuthorizationException 108 * If an authorization failure prevented this constraint 109 * from being evaluated. 110 * @throws CommunicationException 111 * If a communications problem prevented this constraint 112 * from being evaluated. 113 */ 114 public boolean isModifyAcceptable(ManagementContext context, 115 ManagedObject<?> managedObject, Collection<LocalizableMessage> unacceptableReasons) 116 throws AuthorizationException, CommunicationException { 117 return true; 118 } 119 120 121 122 /** 123 * Determines whether or not the existing managed object which is 124 * about to be deleted from the server configuration satisfies this 125 * constraint. 126 * <p> 127 * If the constraint is not satisfied, the implementation must 128 * return <code>false</code> and add a message describing why the 129 * constraint was not satisfied. 130 * <p> 131 * The default implementation is to return <code>true</code>. 132 * 133 * @param context 134 * The management context. 135 * @param path 136 * The path of the managed object which is about to be 137 * deleted. 138 * @param unacceptableReasons 139 * A list of messages to which error messages should be 140 * added. 141 * @return Returns <code>true</code> if this constraint is 142 * satisfied, or <code>false</code> if it is not. 143 * @throws AuthorizationException 144 * If an authorization failure prevented this constraint 145 * from being evaluated. 146 * @throws CommunicationException 147 * If a communications problem prevented this constraint 148 * from being evaluated. 149 */ 150 public boolean isDeleteAcceptable(ManagementContext context, 151 ManagedObjectPath<?, ?> path, Collection<LocalizableMessage> unacceptableReasons) 152 throws AuthorizationException, CommunicationException { 153 return true; 154 } 155}