Hi.
I created a new partiton, that is read only. The problemem happens when
it try to search a entry. The log is under, and the code is attached. If
someone could help me thanks.
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO]
[INFO]
------------------------------------------------------------------------
[INFO] Building ApacheDS embedded sample 1.5.7
[INFO]
------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2:java (default-cli) @
apacheds-embedded-sample >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2:java (default-cli) @
apacheds-embedded-sample <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2:java (default-cli) @
apacheds-embedded-sample ---
21/03/2011 14:45:26 com.ati.teste.SGLPartition <init>
INFO: Criando partição
21/03/2011 14:45:26 com.ati.teste.SGLPartition setId
INFO: setId
21/03/2011 14:45:26 com.ati.teste.SGLPartition setSchemaManager
INFO: setSchemaManager
21/03/2011 14:45:26 com.ati.teste.SGLPartition setSuffix
INFO: setSuffix
21/03/2011 14:45:26 com.ati.teste.SGLPartition getSchemaManager
INFO: getSchemaManager
21/03/2011 14:45:26 com.ati.teste.SGLPartition setSchemaManager
INFO: setSchemaManager
21/03/2011 14:45:30 com.ati.teste.SGLPartition setSchemaManager
INFO: setSchemaManager
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition doInit
INFO: doInit
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSchemaManager
INFO: getSchemaManager
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
[14:45:30] ERROR
[org.apache.directory.shared.ldap.entry.DefaultServerAttribute] -
ERR_04450 The value {0} is incorrect, it hasnt been added
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition search
INFO: search for 0.9.2342.19200300.100.1.25=ericsson dc=ericsson
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition search
INFO: DN encontrado.
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition search
INFO: search for 0.9.2342.19200300.100.1.25=ericsson dc=ericsson
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition search
INFO: DN encontrado.
[14:45:30] WARN [org.apache.directory.server.core.authz.TupleCache] -
Found accessControlSubentry 'dc=ericsson' without any prescriptiveACI
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition search
INFO: search for 0.9.2342.19200300.100.1.25=ericsson dc=ericsson
21/03/2011 14:45:30 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:30 com.ati.teste.SGLPartition search
INFO: DN encontrado.
[14:45:30] WARN [org.apache.directory.server.core.authz.GroupCache] -
Found group 'dc=ericsson' without any member or uniqueMember attributes
21/03/2011 14:45:31 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:31 com.ati.teste.SGLPartition search
INFO: search for 0.9.2342.19200300.100.1.25=ericsson dc=ericsson
21/03/2011 14:45:31 com.ati.teste.SGLPartition getSuffixDn
INFO: getSuffixDn
21/03/2011 14:45:31 com.ati.teste.SGLPartition search
INFO: DN encontrado.
java.lang.NullPointerException
at
org.apache.directory.server.core.subtree.SubentryInterceptor.init(SubentryInterceptor.java:185)
at
org.apache.directory.server.core.interceptor.InterceptorChain.register0(InterceptorChain.java:442)
at
org.apache.directory.server.core.interceptor.InterceptorChain.register(InterceptorChain.java:398)
at
org.apache.directory.server.core.interceptor.InterceptorChain.init(InterceptorChain.java:258)
at
org.apache.directory.server.core.DefaultDirectoryService.initialize(DefaultDirectoryService.java:1447)
at
org.apache.directory.server.core.DefaultDirectoryService.startup(DefaultDirectoryService.java:907)
at com.ati.teste.EmbeddedADS.initDirectoryService(EmbeddedADS.java:162)
at com.ati.teste.EmbeddedADS.<init>(EmbeddedADS.java:226)
at com.ati.teste.EmbeddedADS.main(EmbeddedADS.java:254)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:291)
at java.lang.Thread.run(Thread.java:662)
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 10.525s
[INFO] Finished at: Mon Mar 21 14:45:31 BRT 2011
[INFO] Final Memory: 21M/124M
[INFO]
------------------------------------------------------------------------
[WARNING] The requested profile "webclient" could not be activated
because it does not exist.
package com.ati.teste;
import java.io.File;
import java.util.HashSet;
import java.util.List;
import org.apache.directory.server.constants.ServerDNConstants;
import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.partition.Partition;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
import org.apache.directory.server.core.partition.ldif.LdifPartition;
import org.apache.directory.server.core.schema.SchemaPartition;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.server.protocol.shared.transport.TcpTransport;
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.shared.ldap.entry.ServerEntry;
import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
public class EmbeddedADS {
/** The directory service */
private DirectoryService service;
/** The LDAP server */
private LdapServer server;
/**
* Add a new partition to the server
*
* @param partitionId
* The partition Id
* @param partitionDn
* The partition DN
* @return The newly added partition
* @throws Exception
* If the partition can't be added
*/
private Partition addPartition(String partitionId, String partitionDn)
throws Exception {
// Create a new partition named 'foo'.
JdbmPartition partition = new JdbmPartition();
partition.setId(partitionId);
partition.setPartitionDir(new File(service.getWorkingDirectory(),
partitionId));
partition.setSuffix(partitionDn);
service.addPartition(partition);
return partition;
}
/**
* Add a new set of index on the given attributes
*
* @param partition
* The partition on which we want to add index
* @param attrs
* The list of attributes to index
*/
private void addIndex(Partition partition, String... attrs) {
// Index some attributes on the apache partition
HashSet<Index<?, ServerEntry, Long>> indexedAttributes = new HashSet<Index<?, ServerEntry, Long>>();
for (String attribute : attrs) {
indexedAttributes
.add(new JdbmIndex<String, ServerEntry>(attribute));
}
((JdbmPartition) partition).setIndexedAttributes(indexedAttributes);
}
/**
* initialize the schema manager and add the schema partition to diectory
* service
*
* @throws Exception
* if the schema LDIF files are not found on the classpath
*/
private void initSchemaPartition() throws Exception {
SchemaPartition schemaPartition = service.getSchemaService()
.getSchemaPartition();
// Init the LdifPartition
LdifPartition ldifPartition = new LdifPartition();
String workingDirectory = service.getWorkingDirectory().getPath();
ldifPartition.setWorkingDirectory(workingDirectory + "/schema");
// Extract the schema on disk (a brand new one) and load the registries
File schemaRepository = new File(workingDirectory, "schema");
SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(
new File(workingDirectory));
extractor.extractOrCopy(true);
schemaPartition.setWrappedPartition(ldifPartition);
SchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
service.setSchemaManager(schemaManager);
// We have to load the schema now, otherwise we won't be able
// to initialize the Partitions, as we won't be able to parse
// and normalize their suffix DN
schemaManager.loadAllEnabled();
schemaPartition.setSchemaManager(schemaManager);
List<Throwable> errors = schemaManager.getErrors();
if (errors.size() != 0) {
throw new Exception("Schema load failed : " + errors);
}
}
/**
* Initialize the server. It creates the partition, adds the index, and
* injects the context entries for the created partitions.
*
* @param workDir
* the directory to be used for storing the data
* @throws Exception
* if there were some problems while initializing the system
*/
private void initDirectoryService(File workDir) throws Exception {
// Initialize the LDAP service
service = new DefaultDirectoryService();
service.setWorkingDirectory(workDir);
// first load the schema
initSchemaPartition();
// then the system partition
// this is a MANDATORY partition
Partition systemPartition = addPartition("system",
ServerDNConstants.SYSTEM_DN);
service.setSystemPartition(systemPartition);
// Disable the ChangeLog system
service.getChangeLog().setEnabled(false);
service.setDenormalizeOpAttrsEnabled(true);
// Now we can create as many partitions as we need
// Create some new partitions named 'foo', 'bar' and 'apache'.
/*
* Partition fooPartition = addPartition("foo", "dc=foo,dc=com");
* Partition barPartition = addPartition("bar", "dc=bar,dc=com");
* Partition apachePartition = addPartition("apache",
* "dc=apache,dc=org");
*/
Partition sglPartition = new SGLPartition(
service.getSchemaManager(), "ericsson", "dc=ericsson");
service.addPartition(sglPartition);
// Index some attributes on the apache partition
// addIndex(sglPartition, "objectClass", "ou", "uid");
// And start the service
service.startup();
// Inject the foo root entry if it does not already exist
/*
* try { service.getAdminSession().lookup(fooPartition.getSuffixDn()); }
* catch (LdapException lnnfe) { DN dnFoo = new DN("dc=foo,dc=com");
* ServerEntry entryFoo = service.newEntry(dnFoo);
* entryFoo.add("objectClass", "top", "domain", "extensibleObject");
* entryFoo.add("dc", "foo"); service.getAdminSession().add(entryFoo); }
*
* // Inject the bar root entry try {
* service.getAdminSession().lookup(barPartition.getSuffixDn()); } catch
* (LdapException lnnfe) { DN dnBar = new DN("dc=bar,dc=com");
* ServerEntry entryBar = service.newEntry(dnBar);
* entryBar.add("objectClass", "top", "domain", "extensibleObject");
* entryBar.add("dc", "bar"); service.getAdminSession().add(entryBar); }
*/
// Inject the apache root entry
/*
* if (!service.getAdminSession().exists(sglPartition.getSuffixDn())) {
* DN dnEricsson = new DN("dc=ericsson"); ServerEntry entryEricsson =
* service.newEntry(dnEricsson); entryEricsson.add("objectClass", "top",
* "dcObject", "organization"); entryEricsson.add("dc", "ericsson");
* entryEricsson.add("o", "Sony Ericsson");
* service.getAdminSession().add(entryEricsson); } DN dnPessoas = new
* DN("ou=Pessoas,dc=ericsson"); if
* (!service.getAdminSession().exists(dnPessoas)) { ServerEntry
* entryPessoas = service.newEntry(dnPessoas);
* entryPessoas.add("objectClass", "top", "organizationalUnit");
* entryPessoas.add("ou", "Pessoas"); entryPessoas.add("description",
* "Base teste de pessoas");
* service.getAdminSession().add(entryPessoas); } DN dnAdmin = new
* DN("cn=admin,ou=Pessoas,dc=ericsson"); if
* (!service.getAdminSession().exists(dnAdmin)) { ServerEntry entryAdmin
* = service.newEntry(dnAdmin); entryAdmin.add("objectClass", "top",
* "person"); entryAdmin.add("cn", "admin"); entryAdmin.add("sn",
* "ati"); service.getAdminSession().add(entryAdmin); } DN dnSglopr =
* new DN("cn=sglopr,ou=Pessoas,dc=ericsson"); if
* (!service.getAdminSession().exists(dnSglopr)) { ServerEntry
* entrySglopr = service.newEntry(dnSglopr);
* entrySglopr.add("objectClass", "top", "person");
* entrySglopr.add("cn", "sglopr"); entrySglopr.add("sn", "ati");
* service.getAdminSession().add(entrySglopr); } DN dnSglconfig = new
* DN("cn=sglconfig,ou=Pessoas,dc=ericsson"); if
* (!service.getAdminSession().exists(dnSglconfig)) { ServerEntry
* entrySglconfig = service.newEntry(dnSglconfig);
* entrySglconfig.add("objectClass", "top", "person");
* entrySglconfig.add("cn", "sglconfig"); entrySglconfig.add("sn",
* "ati"); // entrySglconfig.add("userPassword", //
* "e1NTSEF9bzJLSWoxTllwY3dqdk4zMWp4ZVpyZ2xnRjdCTVVqTDI=");
* service.getAdminSession().add(entrySglconfig); }
*/
// We are all done !
}
/**
* Creates a new instance of EmbeddedADS. It initializes the directory
* service.
*
* @throws Exception
* If something went wrong
*/
public EmbeddedADS(File workDir) throws Exception {
initDirectoryService(workDir);
}
/**
* starts the LdapServer
*
* @throws Exception
*/
public void startServer() throws Exception {
server = new LdapServer();
int serverPort = 10389;
server.setTransports(new TcpTransport(serverPort));
server.setDirectoryService(service);
server.start();
}
/**
* Main class.
*
* @param args
* Not used.
*/
public static void main(String[] args) {
try {
File workDir = new File("/media/Dados/apacheds_1.5.7/example.com");
workDir.mkdirs();
// Create the server
EmbeddedADS ads = new EmbeddedADS(workDir);
// Read an entry
/*
* Entry result = ads.service.getAdminSession().lookup( new
* DN("cn=sglconfig,ou=Pessoas,dc=ericsson"));
*/
// And print it if available
// System.out.println("Found entry : " + result);
// optionally we can start a server too
ads.startServer();
} catch (Exception e) {
// Ok, we have something wrong going on ...
e.printStackTrace();
}
}
}
package com.ati.teste;
import java.util.logging.Logger;
import javax.naming.InvalidNameException;
import org.apache.directory.server.core.entry.ClonedServerEntry;
import org.apache.directory.server.core.filtering.BaseEntryFilteringCursor;
import org.apache.directory.server.core.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.interceptor.context.BindOperationContext;
import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
import org.apache.directory.server.core.interceptor.context.ListOperationContext;
import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.interceptor.context.UnbindOperationContext;
import org.apache.directory.server.core.partition.AbstractPartition;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.cursor.EmptyCursor;
import org.apache.directory.shared.ldap.cursor.SingletonCursor;
import org.apache.directory.shared.ldap.entry.DefaultServerEntry;
import org.apache.directory.shared.ldap.entry.ServerEntry;
import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
import org.apache.directory.shared.ldap.name.DN;
import org.apache.directory.shared.ldap.schema.SchemaManager;
public class SGLPartition extends AbstractPartition {
private static final Logger LOG = Logger.getLogger(SGLPartition.class
.getName());
private String id;
private String suffix;
private SchemaManager schemaManager;
private DN normSuffixDN;
private ServerEntry entryEricsson;
public SGLPartition(SchemaManager schemaManager, String id, String suffix)
throws LdapInvalidDnException {
LOG.info("Criando partição");
setId(id);
setSchemaManager(schemaManager);
setSuffix(suffix);
}
public void add(AddOperationContext arg0) throws Exception {
LOG.info("Add");
}
public void bind(BindOperationContext arg0) throws Exception {
LOG.info("Bind");
}
public void delete(DeleteOperationContext arg0) throws Exception {
LOG.info("Delete");
}
public void modify(ModifyOperationContext arg0) throws Exception {
LOG.info("Modify");
}
public void move(MoveOperationContext arg0) throws Exception {
LOG.info("Move");
}
public void moveAndRename(MoveAndRenameOperationContext arg0)
throws Exception {
LOG.info("MoveAndRename");
}
public void rename(RenameOperationContext arg0) throws Exception {
LOG.info("Rename");
}
public void unbind(UnbindOperationContext arg0) throws Exception {
LOG.info("Unbind");
}
@Override
protected void doDestroy() throws Exception {
LOG.info("Destroy");
}
@Override
public void sync() throws Exception {
LOG.info("Sync");
}
public String getId() {
LOG.info("getId");
return id;
}
public void setId(String id) {
LOG.info("setId");
this.id = id;
}
public String getSuffix() {
LOG.info("getSuffix");
return suffix;
}
public void setSuffix(String suffix) throws LdapInvalidDnException {
LOG.info("setSuffix");
this.suffix = suffix;
try {
this.normSuffixDN = DN.normalize(new DN(suffix), getSchemaManager()
.getRegistries().getAttributeTypeRegistry()
.getNormalizerMapping());
} catch (Exception e) {
throw new RuntimeException();
}
}
public SchemaManager getSchemaManager() {
LOG.info("getSchemaManager");
return schemaManager;
}
public void setSchemaManager(SchemaManager schemaManager) {
LOG.info("setSchemaManager");
this.schemaManager = schemaManager;
}
public DN getSuffixDn() {
LOG.info("getSuffixDn");
return normSuffixDN;
}
@Override
protected void doInit() throws InvalidNameException, Exception {
LOG.info("doInit");
entryEricsson = new DefaultServerEntry(getSchemaManager(),
getSuffixDn());
entryEricsson.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
SchemaConstants.ORGANIZATION_OC);
entryEricsson.put("dc", "ericsson");
entryEricsson.put("o", "Sony Ericsson");
}
public EntryFilteringCursor search(SearchOperationContext ctx)
throws Exception {
LOG.info("search for " + ctx.getDn() + " " + getSuffixDn());
if (ctx.getDn().equals(getSuffixDn())) {
LOG.info("DN encontrado.");
return new BaseEntryFilteringCursor(
new SingletonCursor<ServerEntry>(entryEricsson), ctx);
}
// return an empty result
return new BaseEntryFilteringCursor(new EmptyCursor<ServerEntry>(), ctx);
}
@Override
public ClonedServerEntry lookup(LookupOperationContext arg0)
throws Exception {
LOG.info("lookup");
// TODO Auto-generated method stub
return null;
}
public EntryFilteringCursor list(ListOperationContext arg0)
throws Exception {
LOG.info("list");
// TODO Auto-generated method stub
return null;
}
}