1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.server.core.security;
22
23
24 import static org.junit.Assert.*;
25
26 import java.security.KeyPair;
27 import java.security.cert.X509Certificate;
28 import java.util.HashSet;
29 import java.util.Set;
30
31 import org.apache.directory.server.core.entry.DefaultServerEntry;
32 import org.apache.directory.server.schema.bootstrap.ApacheSchema;
33 import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
34 import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
35 import org.apache.directory.server.schema.bootstrap.CoreSchema;
36 import org.apache.directory.server.schema.bootstrap.CosineSchema;
37 import org.apache.directory.server.schema.bootstrap.InetorgpersonSchema;
38 import org.apache.directory.server.schema.bootstrap.Schema;
39 import org.apache.directory.server.schema.bootstrap.SystemSchema;
40 import org.apache.directory.server.schema.registries.DefaultOidRegistry;
41 import org.apache.directory.server.schema.registries.DefaultRegistries;
42 import org.apache.directory.server.schema.registries.OidRegistry;
43 import org.apache.directory.server.schema.registries.Registries;
44 import org.apache.directory.shared.ldap.constants.SchemaConstants;
45 import org.apache.directory.shared.ldap.name.LdapDN;
46 import org.junit.BeforeClass;
47 import org.junit.Test;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50
51
52
53
54
55
56
57
58 public class TlsKeyGeneratorTest
59 {
60 private static final Logger LOG = LoggerFactory.getLogger( TlsKeyGeneratorTest.class );
61 private static BootstrapSchemaLoader loader;
62 private static Registries registries;
63 private static OidRegistry oidRegistry;
64
65
66
67
68
69 @BeforeClass
70 public static void setup() throws Exception
71 {
72 loader = new BootstrapSchemaLoader();
73 oidRegistry = new DefaultOidRegistry();
74 registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
75
76
77 Set<Schema> bootstrapSchemas = new HashSet<Schema>();
78 bootstrapSchemas.add( new ApachemetaSchema() );
79 bootstrapSchemas.add( new ApacheSchema() );
80 bootstrapSchemas.add( new CoreSchema() );
81 bootstrapSchemas.add( new SystemSchema() );
82 bootstrapSchemas.add( new InetorgpersonSchema() );
83 bootstrapSchemas.add( new CosineSchema() );
84 loader.loadWithDependencies( bootstrapSchemas, registries );
85
86 }
87
88
89
90
91
92 @Test
93 public void testAll() throws Exception
94 {
95 DefaultServerEntry entry = new DefaultServerEntry( registries, new LdapDN() );
96 TlsKeyGenerator.addKeyPair( entry );
97 LOG.debug( "Entry: {}", entry );
98 assertTrue( entry.contains( SchemaConstants.OBJECT_CLASS_AT, TlsKeyGenerator.TLS_KEY_INFO_OC ) );
99
100 KeyPair keyPair = TlsKeyGenerator.getKeyPair( entry );
101 assertNotNull( keyPair );
102
103 X509Certificate cert = TlsKeyGenerator.getCertificate( entry );
104 assertNotNull( cert );
105 }
106 }