[
https://issues.apache.org/jira/browse/KNOX-3574?focusedWorklogId=1055814&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1055814
]
ASF GitHub Bot logged work on KNOX-3574:
----------------------------------------
Author: ASF GitHub Bot
Created on: 19/Nov/26 01:31
Start Date: 19/Nov/26 01:31
Worklog Time Spent: 10m
Work Description: 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
Issue Time Tracking
-------------------
Worklog Id: (was: 1055814)
Time Spent: 1h 10m (was: 1h)
> LDAP proxy backend returns operational attributes
> -------------------------------------------------
>
> Key: KNOX-3574
> URL: https://issues.apache.org/jira/browse/KNOX-3574
> Project: Apache Knox
> Issue Type: Improvement
> Components: LDAP
> Affects Versions: 3.0.0
> Reporter: David Han
> Assignee: David Han
> Priority: Major
> Fix For: 3.1.0
>
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> The returned attributes from the search should be passed directly to the
> backend so that operational attributes will be returned when specified.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)