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 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2012-2015 ForgeRock AS 026 * Portions Copyright 2013-2014 Manuel Gaupp 027 */ 028package org.opends.server.schema; 029 030import static org.opends.server.schema.SchemaConstants.*; 031 032import java.util.List; 033 034import org.forgerock.i18n.LocalizableMessage; 035import org.forgerock.opendj.config.server.ConfigChangeResult; 036import org.forgerock.opendj.config.server.ConfigException; 037import org.forgerock.opendj.ldap.schema.Schema; 038import org.forgerock.opendj.ldap.schema.SchemaOptions; 039import org.forgerock.opendj.ldap.schema.Syntax; 040import org.forgerock.util.Option; 041import org.opends.server.admin.server.ConfigurationChangeListener; 042import org.opends.server.admin.std.server.CertificateAttributeSyntaxCfg; 043import org.opends.server.api.AttributeSyntax; 044import org.opends.server.core.ServerContext; 045 046 047/** 048 * This class implements the certificate attribute syntax. It is restricted to 049 * accept only X.509 certificates. 050 */ 051public class CertificateSyntax 052 extends AttributeSyntax<CertificateAttributeSyntaxCfg> 053 implements ConfigurationChangeListener<CertificateAttributeSyntaxCfg> 054{ 055 056 /** The current configuration. */ 057 private volatile CertificateAttributeSyntaxCfg config; 058 059 private ServerContext serverContext; 060 061 /** 062 * Creates a new instance of this syntax. Note that the only thing that 063 * should be done here is to invoke the default constructor for the 064 * superclass. All initialization should be performed in the 065 * <CODE>initializeSyntax</CODE> method. 066 */ 067 public CertificateSyntax() 068 { 069 super(); 070 } 071 072 /** {@inheritDoc} */ 073 @Override 074 public void initializeSyntax(CertificateAttributeSyntaxCfg configuration, ServerContext serverContext) 075 throws ConfigException 076 { 077 this.config = configuration; 078 this.serverContext = serverContext; 079 updateNewSchema(); 080 config.addCertificateChangeListener(this); 081 } 082 083 /** Update the option in new schema if it changes from current value. */ 084 private void updateNewSchema() 085 { 086 Option<Boolean> option = SchemaOptions.ALLOW_MALFORMED_CERTIFICATES; 087 if (config.isStrictFormat() == serverContext.getSchemaNG().getOption(option)) 088 { 089 SchemaUpdater schemaUpdater = serverContext.getSchemaUpdater(); 090 schemaUpdater.updateSchema( 091 schemaUpdater.getSchemaBuilder().setOption(option, !config.isStrictFormat()).toSchema()); 092 } 093 } 094 095 /** {@inheritDoc} */ 096 @Override 097 public Syntax getSDKSyntax(Schema schema) 098 { 099 return schema.getSyntax(SchemaConstants.SYNTAX_CERTIFICATE_OID); 100 } 101 102 /** {@inheritDoc} */ 103 @Override 104 public boolean isConfigurationChangeAcceptable( 105 CertificateAttributeSyntaxCfg configuration, 106 List<LocalizableMessage> unacceptableReasons) 107 { 108 // The configuration is always acceptable. 109 return true; 110 } 111 112 /** {@inheritDoc} */ 113 @Override 114 public ConfigChangeResult applyConfigurationChange( 115 CertificateAttributeSyntaxCfg configuration) 116 { 117 this.config = configuration; 118 updateNewSchema(); 119 return new ConfigChangeResult(); 120 } 121 122 /** 123 * Retrieves the common name for this attribute syntax. 124 * 125 * @return The common name for this attribute syntax. 126 */ 127 @Override 128 public String getName() 129 { 130 return SYNTAX_CERTIFICATE_NAME; 131 } 132 133 /** 134 * Retrieves the OID for this attribute syntax. 135 * 136 * @return The OID for this attribute syntax. 137 */ 138 @Override 139 public String getOID() 140 { 141 return SYNTAX_CERTIFICATE_OID; 142 } 143 144 /** 145 * Retrieves a description for this attribute syntax. 146 * 147 * @return A description for this attribute syntax. 148 */ 149 @Override 150 public String getDescription() 151 { 152 return SYNTAX_CERTIFICATE_DESCRIPTION; 153 } 154} 155