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 2013-2016 ForgeRock AS. 015 * Portions copyright 2026 Wren Security 016 */ 017package org.forgerock.opendj.rest2ldap; 018 019import org.forgerock.opendj.ldap.AttributeDescription; 020 021/** The writability policy determines whether an attribute supports updates. */ 022public enum WritabilityPolicy { 023 // @formatter:off 024 /** 025 * The attribute cannot be provided when creating a new resource, nor 026 * modified afterwards. Attempts to update the attribute will result in an 027 * error. 028 */ 029 READ_ONLY("readOnly", false), 030 031 /** 032 * The attribute cannot be provided when creating a new resource, nor 033 * modified afterwards. Attempts to update the attribute will not result in 034 * an error (the new values will be ignored). 035 */ 036 READ_ONLY_DISCARD_WRITES("readOnlyDiscardWrites", true), 037 038 /** 039 * The attribute may be provided when creating a new resource, but cannot be 040 * modified afterwards. Attempts to update the attribute will result in an 041 * error. 042 */ 043 CREATE_ONLY("createOnly", false), 044 045 /** 046 * The attribute may be provided when creating a new resource, but cannot be 047 * modified afterwards. Attempts to update the attribute will not result in 048 * an error (the new values will be ignored). 049 */ 050 CREATE_ONLY_DISCARD_WRITES("createOnlyDiscardWrites", true), 051 052 /** 053 * The attribute may be provided when creating a new resource, and modified 054 * afterwards. 055 */ 056 READ_WRITE("readWrite", false); 057 // @formatter:on 058 059 private final String name; 060 private final boolean discardWrites; 061 062 WritabilityPolicy(final String name, final boolean discardWrites) { 063 this.name = name; 064 this.discardWrites = discardWrites; 065 } 066 067 boolean canCreate(final AttributeDescription attribute) { 068 return this != READ_ONLY && this != READ_ONLY_DISCARD_WRITES 069 && !attribute.getAttributeType().isNoUserModification(); 070 } 071 072 boolean canWrite(final AttributeDescription attribute) { 073 return this == READ_WRITE && !attribute.getAttributeType().isNoUserModification(); 074 } 075 076 boolean discardWrites() { 077 return discardWrites; 078 } 079 080 @Override 081 public String toString() { 082 return name; 083 } 084}