handavid commented on code in PR #1523:
URL: https://github.com/apache/knox/pull/1523#discussion_r4623206535
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/ldap/backend/LdapProxyBackend.java:
##########
@@ -462,6 +474,170 @@ private void releaseConnection(LdapConnection connection)
{
}
}
+ /**
+ * Imports the operator-declared {@code extraAttributes} from the remote
LDAP server's schema
+ * into the shared schema manager, so the proxy can recognise and request
them (e.g. operational
+ * attributes like whenChanged). Only the configured attributes are
imported — the remote schema
+ * is never trusted wholesale — and each imported definition comes from
the remote server, so its
+ * syntax and usage are authoritative. Attribute types already registered
(by OID) are left
+ * untouched, so the hardcoded definitions in {@code SchemaManagerFactory}
always win. A configured
+ * attribute that the remote server does not publish is logged as an error
and skipped.
+ * <p>
+ * Any failure (the remote server being unreachable, not publishing a
schema, or a single
+ * attribute type that cannot be resolved against the bundled
syntaxes/matching rules) is
+ * logged and skipped rather than propagated, so a backend's schema being
unavailable never
+ * prevents the embedded LDAP service from starting.
+ */
+ @Override
+ public void loadRemoteSchema(SchemaManager schemaManager) {
+ if (extraAttributes == null || extraAttributes.length == 0) {
+ // Nothing declared to import; do not even contact the remote
server.
+ return;
+ }
+ LdapConnection connection = null;
+ try {
+ connection = getConnection();
+ // Quirks mode (the second argument) relaxes the schema parser so
non-RFC-4512 schemas
+ // load instead of failing. Active Directory in particular
publishes attribute type and
+ // object class descriptions with non-numeric OIDs and missing
elements that the strict
+ // parser rejects with ERR_13787_OID_EXPECTED.
+ final DefaultSchemaLoader remoteLoader = new
DefaultSchemaLoader(connection, true);
+ final SchemaManager remoteSchemaManager = new
DefaultSchemaManager(remoteLoader);
+ // Relaxed loading so an incomplete or non-standard remote schema
yields what it can
+ // instead of failing wholesale.
+ remoteSchemaManager.loadAllEnabledRelaxed();
+ importConfiguredAttributeTypes(schemaManager, remoteSchemaManager);
+ } catch (Exception e) {
+ LOG.ldapRemoteSchemaLoadFailed(getName(), e);
+ } finally {
+ releaseConnection(connection);
+ }
+ }
+
+ /**
+ * Imports each configured {@code extraAttributes} entry from {@code
remoteSchemaManager} into
+ * {@code schemaManager}, using the remote server's own definition.
Attributes the remote server
+ * does not publish are logged and skipped. Separated from the connection
handling in
+ * {@link #loadRemoteSchema(SchemaManager)} so the import can be exercised
without a live server.
+ */
+ void importConfiguredAttributeTypes(SchemaManager schemaManager,
SchemaManager remoteSchemaManager) {
+ if (extraAttributes == null) {
+ return;
+ }
+ int imported = 0;
+ for (String attributeName : extraAttributes) {
+ final AttributeType remoteType =
remoteSchemaManager.getAttributeType(attributeName);
+ if (remoteType == null || remoteType.getOid() == null) {
+ // Configured but not published by the remote server: almost
always a typo or an
+ // attribute that does not exist on this directory. Surface it
rather than ignore it.
+ LOG.ldapConfiguredAttributeNotInRemoteSchema(getName(),
attributeName);
+ continue;
+ }
+ if (registerRemoteAttributeType(schemaManager, remoteType)) {
+ imported++;
+ }
+ }
+ LOG.ldapRemoteSchemaLoaded(getName(), imported);
+ }
+
+ /**
+ * Registers a single remote attribute type into the target schema
manager, unless an attribute
+ * type with the same OID is already present. The definition is rebuilt as
a standalone attribute
+ * type whose syntax and matching rules are expressed by OID so that the
target manager resolves
+ * them against its own (bundled) registries; its superior chain is
flattened for the same reason.
+ *
+ * @return true if a new attribute type was added, false if it already
existed or could not be added
+ */
+ boolean registerRemoteAttributeType(SchemaManager schemaManager,
AttributeType remoteType) {
+ final String oid = remoteType.getOid();
+ if (oid == null ||
schemaManager.getAttributeTypeRegistry().contains(oid)) {
+ return false;
+ }
+ try {
+ final AttributeType attributeType =
toStandaloneAttributeType(schemaManager, remoteType);
+ final boolean addedToManager = schemaManager.add(attributeType);
+ if (!addedToManager) {
+ // add() records the reason (e.g. an unresolved syntax) in the
manager's error list
+ // rather than throwing; surface it and move on so one bad
definition is skipped.
+ LOG.ldapRemoteAttributeTypeSkipped(getName(), oid,
String.valueOf(schemaManager.getErrors()));
Review Comment:
bumped the logs up to WARN and added the attribute name
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]