Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIRSERVER-1844 adding automatic memberOf attributes #23

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions interceptors/members/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-interceptors</artifactId>
<version>2.0.0.AM26-SNAPSHOT</version>
</parent>

<artifactId>apacheds-interceptors-members</artifactId>
<name>ApacheDS memberOf Virtual Attribute Interceptor</name>
<packaging>bundle</packaging>

<description>
Virtual Attribute interceptor to add memberOf attributes to results
</description>

<dependencies>
<dependency>
<groupId>org.apache.directory.junit</groupId>
<artifactId>junit-addons</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apacheds-i18n</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apacheds-core-api</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apacheds-core-api</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-client-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-i18n</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-codec-standalone</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-codec-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-extras-aci</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-extras-trigger</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-extras-util</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-model</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-schema-data</artifactId>
</dependency>

<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-extras-codec</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<workingDirectory>${basedir}/target/server-work</workingDirectory>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>META-INF/MANIFEST.MF</manifestFile>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<inherited>true</inherited>
<extensions>true</extensions>
<configuration>
<manifestLocation>META-INF</manifestLocation>
<instructions>
<Bundle-SymbolicName>${project.groupId}.interceptors.logger</Bundle-SymbolicName>
<Export-Package>
org.apache.directory.server.core.logger;version=${project.version}
</Export-Package>
<Import-Package>
org.apache.directory.api.ldap.model.constants;version=${org.apache.directory.api.version},
org.apache.directory.api.ldap.model.entry;version=${org.apache.directory.api.version},
org.apache.directory.api.ldap.model.exception;version=${org.apache.directory.api.version},
org.apache.directory.server.core.api;version=${project.version},
org.apache.directory.server.core.api.filtering;version=${project.version},
org.apache.directory.server.core.api.interceptor;version=${project.version},
org.apache.directory.server.core.api.interceptor.context;version=${project.version},
org.slf4j;version=${slf4j.api.bundleversion}
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.gif</exclude>
</excludes>
</resource>
</resources>
</build>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.directory.server.core.memberof;


import org.apache.directory.api.ldap.model.constants.Loggers;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.entry.Value;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.exception.LdapOperationException;
import org.apache.directory.api.ldap.model.exception.LdapOtherException;
import org.apache.directory.api.ldap.model.filter.ExprNode;
import org.apache.directory.api.ldap.model.filter.PresenceNode;
import org.apache.directory.api.ldap.model.message.AliasDerefMode;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.server.core.api.CoreSession;
import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
import org.apache.directory.server.core.api.partition.PartitionTxn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* An interceptor for adding virtual memberOf attributes to {code}Entry{code}s.
*
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class MemberOfInterceptor extends BaseInterceptor
{
/** A aggregating logger */
private static final Logger OPERATION_STATS = LoggerFactory.getLogger( Loggers.OPERATION_STAT.getName() );

/** An operation logger */
private static final Logger OPERATION_TIME = LoggerFactory.getLogger( Loggers.OPERATION_TIME.getName() );

/**
*
* Creates a new instance of MemberOfInterceptor.
*
* @param name This interceptor's getName()
*/
public MemberOfInterceptor( String name )
{
super( name );
}

/**
* {@inheritDoc}
*/
@Override
public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
{
Entry entry = next( lookupContext );

CoreSession adminSession = directoryService.getAdminSession();
Value dnValue = new Value( directoryService.getAtProvider().getMember(), entry.getDn().getNormName() );
PartitionNexus nexus = directoryService.getPartitionNexus();

// either
ExprNode filter = new PresenceNode( directoryService.getAtProvider().getAdministrativeRole() );
// or
// ExprNode filter = new PresenceNode( dnValue );

SearchOperationContext searchOperationContext = new SearchOperationContext( adminSession, Dn.ROOT_DSE, SearchScope.SUBTREE, filter, "1.1" );
Partition partition = nexus.getPartition( Dn.ROOT_DSE );
searchOperationContext.setAliasDerefMode( AliasDerefMode.NEVER_DEREF_ALIASES );
searchOperationContext.setPartition( partition );

try ( PartitionTxn partitionTxn = partition.beginReadTransaction() )
{
searchOperationContext.setTransaction( partitionTxn );
EntryFilteringCursor results = nexus.search( searchOperationContext );

try
{
String memberOf = "memberOf";
while ( results.next() )
{
Entry memberEntry = results.get();

entry = entry.add( memberOf, memberEntry.getDn().getName() );
// Note: not sure f I should:
// if has memberOf
// add to memberOf
// else
// create memberOf with value of
}

results.close();
}
catch ( Exception e )
{
throw new LdapOperationException( e.getMessage(), e );
}
}
catch ( Exception e )
{
throw new LdapOtherException( e.getMessage(), e );
}

return entry;
}

/**
* {@inheritDoc}
*/
@Override
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
EntryFilteringCursor cursor = next( searchContext );

return cursor;
}
}
1 change: 1 addition & 0 deletions interceptors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<module>operational</module>
<module>collective</module>
<module>logger</module>
<module>members</module>
<module>exception</module>
<module>hash</module>
<module>schema</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,13 @@ else if ( vendor.equalsIgnoreCase( "AdoptOpenJDK" ) )
{
assertTrue( "Number of keys", krb5key.size() > 4 );
}
else if ( vendor.equalsIgnoreCase( "Eclipse OpenJ9" ) )
{
assertTrue( "Number of keys", krb5key.size() > 4 );
}
else
{
fail( "Unkown JVM: " + vendor );
fail( "Unkown JVM/keysize: '" + vendor + "' / " + krb5key.size() );
}
}

Expand Down
Loading