| | |
| | | */ |
| | | package org.forgerock.opendj.rest2ldap; |
| | | |
| | | import static org.forgerock.opendj.rest2ldap.Rest2ldapMessages.*; |
| | | import static java.util.Arrays.asList; |
| | | import static org.forgerock.json.resource.ResourceException.newResourceException; |
| | | import static org.forgerock.opendj.ldap.Connections.newCachedConnectionPool; |
| | |
| | | import static org.forgerock.opendj.ldap.schema.CoreSchema.getEntryUUIDAttributeType; |
| | | import static org.forgerock.opendj.rest2ldap.ReadOnUpdatePolicy.CONTROLS; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.ensureNotNull; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.newBadRequestException; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.newLocalizedIllegalArgumentException; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.newJsonValueException; |
| | | import static org.forgerock.util.time.Duration.*; |
| | | |
| | | import java.io.IOException; |
| | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import org.forgerock.json.JsonValue; |
| | | import org.forgerock.json.JsonValueException; |
| | | import org.forgerock.json.resource.BadRequestException; |
| | | import org.forgerock.json.resource.CollectionResourceProvider; |
| | | import org.forgerock.json.resource.ResourceException; |
| | | import org.forgerock.opendj.ldap.AssertionFailureException; |
| | |
| | | public CollectionResourceProvider build() { |
| | | ensureNotNull(baseDN); |
| | | if (rootMapper == null) { |
| | | throw new IllegalStateException("No mappings provided"); |
| | | throw new IllegalStateException(ERR_CONFIG_NO_MAPPINGS_PROVIDED.get().toString()); |
| | | } |
| | | return new LDAPCollectionResourceProvider(baseDN, rootMapper, nameStrategy, etagAttribute, |
| | | new Config(readOnUpdatePolicy, useSubtreeDelete, usePermissiveModify, schema), |
| | |
| | | useServerNaming(namingStrategy.get("dnAttribute").required().asString(), |
| | | namingStrategy.get("idAttribute").required().asString()); |
| | | } else { |
| | | throw new IllegalArgumentException( |
| | | "Illegal naming strategy. Must be one of: clientDNNaming, clientNaming, or serverNaming"); |
| | | throw newLocalizedIllegalArgumentException(ERR_CONFIG_UNKNOWN_NAMING_CONFIGURATION.get( |
| | | namingStrategy.asString(), "clientDNNaming, clientNaming or serverNaming")); |
| | | } |
| | | } |
| | | |
| | |
| | | } else if (mapper.isDefined("object")) { |
| | | return configureObjectMapper(mapper.get("object")); |
| | | } else { |
| | | throw new JsonValueException(mapper, |
| | | "Illegal mapping: must contain constant, simple, or object"); |
| | | throw newJsonValueException(mapper, ERR_CONFIG_NO_MAPPING_IN_CONFIGURATION.get( |
| | | "constant, simple, reference or object")); |
| | | } |
| | | } |
| | | |
| | |
| | | } else if (writability.equalsIgnoreCase("readWrite")) { |
| | | return WritabilityPolicy.READ_WRITE; |
| | | } else { |
| | | throw new JsonValueException(mapper, |
| | | "Illegal writability: must be one of readOnly, readOnlyDiscardWrites, " |
| | | + "createOnly, createOnlyDiscardWrites, or readWrite"); |
| | | throw newJsonValueException(mapper, ERR_CONFIG_UNKNOWN_WRITABILITY.get(writability, |
| | | "readOnly, readOnlyDiscardWrites, createOnly, createOnlyDiscardWrites, or readWrite")); |
| | | } |
| | | } else { |
| | | return WritabilityPolicy.READ_WRITE; |
| | |
| | | final AttributeDescription idAttribute, final boolean isServerProvided) { |
| | | this.dnAttribute = AttributeDescription.create(dnAttribute); |
| | | if (this.dnAttribute.equals(idAttribute)) { |
| | | throw new IllegalArgumentException("DN and ID attributes must be different"); |
| | | throw newLocalizedIllegalArgumentException(ERR_CONFIG_NAMING_STRATEGY_DN_AND_ID_NOT_DIFFERENT.get()); |
| | | } |
| | | this.idAttribute = ensureNotNull(idAttribute); |
| | | this.isServerProvided = isServerProvided; |
| | |
| | | final Entry entry) throws ResourceException { |
| | | if (isServerProvided) { |
| | | if (resourceId != null) { |
| | | throw new BadRequestException("Resources cannot be created with a " |
| | | + "client provided resource ID"); |
| | | throw newBadRequestException(ERR_CLIENT_PROVIDER_RESOURCE_ID_MISSING.get()); |
| | | } |
| | | } else { |
| | | entry.addAttribute(new LinkedAttribute(idAttribute, ByteString.valueOfUtf8(resourceId))); |
| | |
| | | } else if (entry.getAttribute(attribute) != null) { |
| | | entry.setName(baseDN.child(rdn(entry.parseAttribute(attribute).asString()))); |
| | | } else { |
| | | throw new BadRequestException("Resources cannot be created without a " |
| | | + "client provided resource ID"); |
| | | throw newBadRequestException(ERR_CLIENT_PROVIDER_RESOURCE_ID_MISSING.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | simple.get("bindPassword").required().asString().toCharArray()); |
| | | options.set(AUTHN_BIND_REQUEST, bindRequest); |
| | | } else { |
| | | throw new IllegalArgumentException("Only simple authentication is supported"); |
| | | throw newLocalizedIllegalArgumentException(ERR_CONFIG_INVALID_AUTHENTICATION.get()); |
| | | } |
| | | } |
| | | |
| | |
| | | secondary = parseLDAPServers(secondaryLDAPServers, connectionPoolSize, options); |
| | | } |
| | | } else if (!secondaryLDAPServers.isNull()) { |
| | | throw new IllegalArgumentException("Invalid secondaryLDAPServers configuration"); |
| | | throw newLocalizedIllegalArgumentException(ERR_CONFIG_INVALID_SECONDARY_LDAP_SERVER.get()); |
| | | } |
| | | |
| | | // Create fail-over. |
| | |
| | | final String name, final int depth) { |
| | | // Protect against infinite recursion in the configuration. |
| | | if (depth > 100) { |
| | | throw new IllegalArgumentException( |
| | | "The LDAP server configuration '" |
| | | + name |
| | | + "' could not be parsed because of potential circular inheritance dependencies"); |
| | | throw newLocalizedIllegalArgumentException(ERR_CONFIG_SERVER_CIRCULAR_DEPENDENCIES.get(name)); |
| | | } |
| | | |
| | | final JsonValue current = configuration.get(name).required(); |