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