001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 */ 026package org.opends.server.admin.std.meta; 027 028 029 030import java.util.Collection; 031import java.util.SortedSet; 032import org.opends.server.admin.AdministratorAction; 033import org.opends.server.admin.AliasDefaultBehaviorProvider; 034import org.opends.server.admin.client.AuthorizationException; 035import org.opends.server.admin.client.CommunicationException; 036import org.opends.server.admin.client.ConcurrentModificationException; 037import org.opends.server.admin.client.ManagedObject; 038import org.opends.server.admin.client.MissingMandatoryPropertiesException; 039import org.opends.server.admin.client.OperationRejectedException; 040import org.opends.server.admin.DNPropertyDefinition; 041import org.opends.server.admin.ManagedObjectAlreadyExistsException; 042import org.opends.server.admin.ManagedObjectDefinition; 043import org.opends.server.admin.PropertyOption; 044import org.opends.server.admin.PropertyProvider; 045import org.opends.server.admin.server.ConfigurationChangeListener; 046import org.opends.server.admin.server.ServerManagedObject; 047import org.opends.server.admin.std.client.RootDNUserCfgClient; 048import org.opends.server.admin.std.server.RootDNUserCfg; 049import org.opends.server.admin.Tag; 050import org.opends.server.admin.TopCfgDefn; 051import org.opends.server.types.DN; 052 053 054 055/** 056 * An interface for querying the Root DN User managed object 057 * definition meta information. 058 * <p> 059 * A Root DN User are administrative users who can granted special 060 * privileges that are not available to non-root users (for example, 061 * the ability to bind to the server in lockdown mode). 062 */ 063public final class RootDNUserCfgDefn extends ManagedObjectDefinition<RootDNUserCfgClient, RootDNUserCfg> { 064 065 // The singleton configuration definition instance. 066 private static final RootDNUserCfgDefn INSTANCE = new RootDNUserCfgDefn(); 067 068 069 070 // The "alternate-bind-dn" property definition. 071 private static final DNPropertyDefinition PD_ALTERNATE_BIND_DN; 072 073 074 075 // Build the "alternate-bind-dn" property definition. 076 static { 077 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "alternate-bind-dn"); 078 builder.setOption(PropertyOption.MULTI_VALUED); 079 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "alternate-bind-dn")); 080 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "alternate-bind-dn")); 081 PD_ALTERNATE_BIND_DN = builder.getInstance(); 082 INSTANCE.registerPropertyDefinition(PD_ALTERNATE_BIND_DN); 083 } 084 085 086 087 // Register the tags associated with this managed object definition. 088 static { 089 INSTANCE.registerTag(Tag.valueOf("core-server")); 090 } 091 092 093 094 /** 095 * Get the Root DN User configuration definition singleton. 096 * 097 * @return Returns the Root DN User configuration definition 098 * singleton. 099 */ 100 public static RootDNUserCfgDefn getInstance() { 101 return INSTANCE; 102 } 103 104 105 106 /** 107 * Private constructor. 108 */ 109 private RootDNUserCfgDefn() { 110 super("root-dn-user", TopCfgDefn.getInstance()); 111 } 112 113 114 115 /** 116 * {@inheritDoc} 117 */ 118 public RootDNUserCfgClient createClientConfiguration( 119 ManagedObject<? extends RootDNUserCfgClient> impl) { 120 return new RootDNUserCfgClientImpl(impl); 121 } 122 123 124 125 /** 126 * {@inheritDoc} 127 */ 128 public RootDNUserCfg createServerConfiguration( 129 ServerManagedObject<? extends RootDNUserCfg> impl) { 130 return new RootDNUserCfgServerImpl(impl); 131 } 132 133 134 135 /** 136 * {@inheritDoc} 137 */ 138 public Class<RootDNUserCfg> getServerConfigurationClass() { 139 return RootDNUserCfg.class; 140 } 141 142 143 144 /** 145 * Get the "alternate-bind-dn" property definition. 146 * <p> 147 * Specifies one or more alternate DNs that can be used to bind to 148 * the server as this root user. 149 * 150 * @return Returns the "alternate-bind-dn" property definition. 151 */ 152 public DNPropertyDefinition getAlternateBindDNPropertyDefinition() { 153 return PD_ALTERNATE_BIND_DN; 154 } 155 156 157 158 /** 159 * Managed object client implementation. 160 */ 161 private static class RootDNUserCfgClientImpl implements 162 RootDNUserCfgClient { 163 164 // Private implementation. 165 private ManagedObject<? extends RootDNUserCfgClient> impl; 166 167 168 169 // Private constructor. 170 private RootDNUserCfgClientImpl( 171 ManagedObject<? extends RootDNUserCfgClient> impl) { 172 this.impl = impl; 173 } 174 175 176 177 /** 178 * {@inheritDoc} 179 */ 180 public SortedSet<DN> getAlternateBindDN() { 181 return impl.getPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition()); 182 } 183 184 185 186 /** 187 * {@inheritDoc} 188 */ 189 public void setAlternateBindDN(Collection<DN> values) { 190 impl.setPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition(), values); 191 } 192 193 194 195 /** 196 * {@inheritDoc} 197 */ 198 public ManagedObjectDefinition<? extends RootDNUserCfgClient, ? extends RootDNUserCfg> definition() { 199 return INSTANCE; 200 } 201 202 203 204 /** 205 * {@inheritDoc} 206 */ 207 public PropertyProvider properties() { 208 return impl; 209 } 210 211 212 213 /** 214 * {@inheritDoc} 215 */ 216 public void commit() throws ManagedObjectAlreadyExistsException, 217 MissingMandatoryPropertiesException, ConcurrentModificationException, 218 OperationRejectedException, AuthorizationException, 219 CommunicationException { 220 impl.commit(); 221 } 222 223 224 225 /** {@inheritDoc} */ 226 public String toString() { 227 return impl.toString(); 228 } 229 } 230 231 232 233 /** 234 * Managed object server implementation. 235 */ 236 private static class RootDNUserCfgServerImpl implements 237 RootDNUserCfg { 238 239 // Private implementation. 240 private ServerManagedObject<? extends RootDNUserCfg> impl; 241 242 // The value of the "alternate-bind-dn" property. 243 private final SortedSet<DN> pAlternateBindDN; 244 245 246 247 // Private constructor. 248 private RootDNUserCfgServerImpl(ServerManagedObject<? extends RootDNUserCfg> impl) { 249 this.impl = impl; 250 this.pAlternateBindDN = impl.getPropertyValues(INSTANCE.getAlternateBindDNPropertyDefinition()); 251 } 252 253 254 255 /** 256 * {@inheritDoc} 257 */ 258 public void addChangeListener( 259 ConfigurationChangeListener<RootDNUserCfg> listener) { 260 impl.registerChangeListener(listener); 261 } 262 263 264 265 /** 266 * {@inheritDoc} 267 */ 268 public void removeChangeListener( 269 ConfigurationChangeListener<RootDNUserCfg> listener) { 270 impl.deregisterChangeListener(listener); 271 } 272 273 274 275 /** 276 * {@inheritDoc} 277 */ 278 public SortedSet<DN> getAlternateBindDN() { 279 return pAlternateBindDN; 280 } 281 282 283 284 /** 285 * {@inheritDoc} 286 */ 287 public Class<? extends RootDNUserCfg> configurationClass() { 288 return RootDNUserCfg.class; 289 } 290 291 292 293 /** 294 * {@inheritDoc} 295 */ 296 public DN dn() { 297 return impl.getDN(); 298 } 299 300 301 302 /** {@inheritDoc} */ 303 public String toString() { 304 return impl.toString(); 305 } 306 } 307}