本文整理汇总了Java中org.apache.directory.server.protocol.shared.transport.TcpTransport类的典型用法代码示例。如果您正苦于以下问题:Java TcpTransport类的具体用法?Java TcpTransport怎么用?Java TcpTransport使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TcpTransport类属于org.apache.directory.server.protocol.shared.transport包,在下文中一共展示了TcpTransport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startLdapServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
private ApacheDS startLdapServer() throws Exception {
Preconditions.checkState(directoryService.isStarted());
Preconditions.checkState(!ldapServer.isStarted());
int port = AvailablePortFinder.getNextAvailable(1024);
ldapServer.setTransports(new TcpTransport(port));
ldapServer.setDirectoryService(directoryService);
// Setup SASL mechanisms
Map<String, MechanismHandler> mechanismHandlerMap = Maps.newHashMap();
mechanismHandlerMap.put(SupportedSaslMechanisms.PLAIN, new PlainMechanismHandler());
mechanismHandlerMap.put(SupportedSaslMechanisms.CRAM_MD5, new CramMd5MechanismHandler());
mechanismHandlerMap.put(SupportedSaslMechanisms.DIGEST_MD5, new DigestMd5MechanismHandler());
mechanismHandlerMap.put(SupportedSaslMechanisms.GSSAPI, new GssapiMechanismHandler());
ldapServer.setSaslMechanismHandlers(mechanismHandlerMap);
ldapServer.setSaslHost("localhost");
ldapServer.setSaslRealms(Collections.singletonList(realm));
// TODO ldapServer.setSaslPrincipal();
// The base DN containing users that can be SASL authenticated.
ldapServer.setSearchBaseDn(baseDn);
ldapServer.start();
return this;
}
示例2: setUp
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
/**
* Get's the initial context factory for the provider's ou=system context root.
*
* @throws Exception
* if there is a failure of any kind
*/
protected void setUp() throws Exception {
setStart(getStart() + 1);
setDirectoryService(new DefaultDirectoryService());
getDirectoryService().setShutdownHookEnabled(false);
setPort(AvailablePortFinder.getNextAvailable(1024));
setLdapServer(new LdapServer());
getLdapServer().setTransports(new TcpTransport(getPort()));
getLdapServer().setDirectoryService(getDirectoryService());
setupSaslMechanisms(getLdapServer());
getDirectoryService().setWorkingDirectory(
new File("target" + File.separator + "server-work"));
doDelete(getDirectoryService().getWorkingDirectory());
configureDirectoryService();
getDirectoryService().startup();
configureLdapServer();
// TODO shouldn't this be before calling configureLdapServer() ???
getLdapServer().addExtendedOperationHandler(new StartTlsHandler());
getLdapServer().addExtendedOperationHandler(new StoredProcedureExtendedOperationHandler());
getLdapServer().start();
setContexts(ServerDNConstants.ADMIN_SYSTEM_DN, "secret");
}
示例3: EmbeddedLdapServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
public EmbeddedLdapServer(
File workingDir,
String partitionDn,
String partitionId,
int port,
boolean enableChangelog,
boolean allowAnonymousAccess,
long maxSizeLimit)
throws Exception {
requireNonNull(partitionDn, "Required non-null partition dn");
requireNonNull(partitionId, "Required non-null partition id");
this.workingDir = workingDir;
this.baseDn = new DN(partitionDn);
this.port = port > 0 ? port : PORT_SERVICE.acquire();
this.url = "ldap://localhost:" + this.port;
ldapServer = new LdapServer();
ldapServer.setTransports(new TcpTransport(this.port));
if (maxSizeLimit > 0) {
ldapServer.setMaxSizeLimit(maxSizeLimit);
}
service =
initDirectoryService(
workingDir, partitionId, partitionDn, enableChangelog, allowAnonymousAccess);
ldapServer.setDirectoryService(service);
}
示例4: afterPropertiesSet
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
public void afterPropertiesSet() throws Exception {
if (this.enabledLdapOverSsl && this.keyStoreFile == null) {
throw new IllegalArgumentException("When LdapOverSsl is enabled, the keyStoreFile property must be set.");
}
if (workingDir == null) {
String apacheWorkDir = System.getProperty("apacheDSWorkDir");
if (apacheWorkDir == null) {
apacheWorkDir = createTempDirectory("apacheds-spring-security-");
}
setWorkingDirectory(new File(apacheWorkDir));
}
server = new LdapServer();
// AbstractLdapIntegrationTests assume IPv4, so we specify the same here
TcpTransport transport = new TcpTransport(port);
if (enabledLdapOverSsl) {
transport.setEnableSSL(true);
server.setKeystoreFile(this.keyStoreFile.getAbsolutePath());
server.setCertificatePassword(this.keyStorePassword);
}
server.setTransports(transport);
server.setDirectoryService(service);
start();
}
示例5: initKdcServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
private void initKdcServer() throws KerberosException {
KerberosConfig kdcConfig = new KerberosConfig();
kdcConfig.setSearchBaseDn(USERS_DN);
kdcConfig.setServicePrincipal(getPrincipal("krbtgt/" + realm));
kdcConfig.setPrimaryRealm(realm);
kdcConfig.setMaximumTicketLifetime(TimeUnit.DAYS.toMillis(1));
kdcConfig.setMaximumRenewableLifetime(TimeUnit.DAYS.toMillis(1));
kdcConfig.setForwardableAllowed(true);
kdcConfig.setPostdatedAllowed(true);
kdcConfig.setProxiableAllowed(true);
kdcConfig.setRenewableAllowed(true);
kdcConfig.setEmptyAddressesAllowed(true);
kdcConfig.setPaEncTimestampRequired(false);
kdcServer = new KdcServer(kdcConfig);
try {
host = InetAddress.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException e) {
LOGGER.warn("Failed to get canonical host name. Using default: " + host);
}
TcpTransport defaultTransport = new TcpTransport(host, port);
kdcServer.addTransports(defaultTransport);
kdcServer.setDirectoryService(directoryService);
addUserEntry("krbtgt/" + realm, "pass");
}
示例6: LdapServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
/**
* Create a single LDAP server.
*
* @param ldifFile
* @throws Exception
*/
public LdapServer(String ldifFile) throws Exception {
InMemoryDirectoryServiceFactory dsFactory = new InMemoryDirectoryServiceFactory();
dsFactory.init("ds");
directoryService = dsFactory.getDirectoryService();
final SchemaManager schemaManager = directoryService.getSchemaManager();
importLdif(directoryService, schemaManager, new LdifReader(ldifFile));
ldapServer = new org.apache.directory.server.ldap.LdapServer();
ldapServer.setTransports(new TcpTransport("127.0.0.1", 1024));
ldapServer.setDirectoryService(directoryService);
ldapServer.start();
}
示例7: configureTransportHandlers
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
private void configureTransportHandlers(KdcConfiguration configuration) {
int port = getServerPort(configuration);
if (configuration.getKdcCommunicationProtocol() ==
KdcConfiguration.ProtocolType.UDP_PROTOCOL) {
logger.info("Starting KDC on UDP mode at port - " + port + " at host - " +
configuration.getKdcHostAddress());
UdpTransport defaultTransport = new UdpTransport(port);
this.kdcServer.addTransports(defaultTransport);
} else {
logger.info("Starting KDC on a TCP port " + port + " at host " +
configuration.getKdcHostAddress());
Transport tcp =
new TcpTransport(configuration.getKdcHostAddress(), port,
configuration.getNumberOfThreads(),
configuration.getBackLogCount());
this.kdcServer.addTransports(tcp);
}
}
示例8: addTcpServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
/**
* Adds a TCP server to the directory service.
*
* Note: The TCP server is not started until start() is called on this Builder.
*
* @param serviceName - The name of this server.
* @param hostName - The host name to listen on.
* @param port - The port to listen on.
* @return This Builder for subsequent changes.
*/
public Builder addTcpServer(final String serviceName, final String hostName, final int port, final String keyStore, final String keyStorePassword) throws URISyntaxException {
assertNotStarted();
if (directoryService == null) {
throw new IllegalStateException("The Directory service has not been created.");
}
LdapServer server = new LdapServer();
server.setServiceName(serviceName);
Transport ldaps = new TcpTransport( hostName, port, 3, 5 );
ldaps.enableSSL(true);
server.addTransports(ldaps);
server.setKeystoreFile(getClass().getResource(keyStore).getFile());
server.setCertificatePassword(keyStorePassword);
server.setDirectoryService(directoryService);
servers.add(server);
return this;
}
示例9: startMasterLdapServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
private static void startMasterLdapServer() throws Exception {
masterWorkingDir = createWorkingDir(masterWorkingDir, "master");
DirectoryServiceFactory dsf = new InMemoryDirectoryServiceFactory();
dsf.init(MASTER_DIRECTORY_NAME);
masterDirectoryService = dsf.getDirectoryService();
masterDirectoryService.getChangeLog().setEnabled(false);
SchemaManager schemaManager = masterDirectoryService.getSchemaManager();
createPartition(dsf, schemaManager, "simple", "dc=simple,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);
createPartition(dsf, schemaManager, "group-to-principal", "dc=group-to-principal,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);
createPartition(dsf, schemaManager, "principal-to-group", "dc=principal-to-group,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);
CoreSession adminSession = masterDirectoryService.getAdminSession();
processLdif(schemaManager, adminSession, "memberOf-schema.ldif");
processLdif(schemaManager, adminSession, "simple-partition.ldif");
processLdif(schemaManager, adminSession, "group-to-principal.ldif");
processLdif(schemaManager, adminSession, "principal-to-group.ldif");
masterLdapServer = new LdapServer();
masterLdapServer.setServiceName("DefaultLDAP");
Transport ldap = new TcpTransport( "0.0.0.0", MASTER_LDAP_PORT, 3, 5 );
masterLdapServer.addTransports(ldap);
masterLdapServer.setDirectoryService(masterDirectoryService);
masterLdapServer.start();
}
示例10: startSlaveLdapServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
private static void startSlaveLdapServer() throws Exception {
slaveWorkingDir = createWorkingDir(slaveWorkingDir, "slave");
DirectoryServiceFactory dsf = new InMemoryDirectoryServiceFactory();
dsf.init(SLAVE_DIRECTORY_NAME);
slaveDirectoryService = dsf.getDirectoryService();
slaveDirectoryService.getChangeLog().setEnabled(false);
SchemaManager schemaManager = slaveDirectoryService.getSchemaManager();
createPartition(dsf, schemaManager, "simple", "dc=simple,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);
createPartition(dsf, schemaManager, "group-to-principal", "dc=group-to-principal,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);
createPartition(dsf, schemaManager, "principal-to-group", "dc=principal-to-group,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);
CoreSession adminSession = slaveDirectoryService.getAdminSession();
processLdif(schemaManager, adminSession, "memberOf-schema.ldif");
processLdif(schemaManager, adminSession, "simple-partition-slave.ldif");
processLdif(schemaManager, adminSession, "group-to-principal-slave.ldif");
processLdif(schemaManager, adminSession, "principal-to-group-slave.ldif");
slaveLdapServer = new LdapServer();
slaveLdapServer.setServiceName("DefaultLDAP");
Transport ldap = new TcpTransport( "0.0.0.0", SLAVE_LDAP_PORT, 3, 5 );
slaveLdapServer.addTransports(ldap);
slaveLdapServer.setDirectoryService(slaveDirectoryService);
slaveLdapServer.start();
}
示例11: LdapStandaloneServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
/**
* Create a single LDAP server.
*
* @throws Exception
*/
public LdapStandaloneServer() throws Exception {
long startTime = System.currentTimeMillis();
InMemoryDirectoryServiceFactory dsFactory = new InMemoryDirectoryServiceFactory();
dsFactory.init("ds");
directoryService = dsFactory.getDirectoryService();
System.out.println("Directory service started in " + (System.currentTimeMillis() - startTime) + "ms");
directoryService.setAllowAnonymousAccess(true);
importLdif("src/dev/resources/ldap/microsoft.ldif",
"src/dev/resources/ldap/users.ldif");
ldapServer = new org.apache.directory.server.ldap.LdapServer();
TcpTransport tcp = new TcpTransport("0.0.0.0", 10389);
TcpTransport ldapsTcp = new TcpTransport("0.0.0.0", 10636);
ldapsTcp.setEnableSSL(true);
ldapsTcp.setEnabledProtocols(Arrays.asList("TLSv1.2"));
ldapServer.setKeystoreFile("src/dev/resources/bouncr.jks");
ldapServer.setCertificatePassword("password");
ldapServer.setTransports(tcp, ldapsTcp);
ldapServer.setDirectoryService(directoryService);
ldapServer.start();
System.out.println("You can connect to the server now");
final String host = "127.0.0.1";
System.out.println("URL: ldap://" + formatPossibleIpv6(host) + ":" + 10389);
System.out.println("User DN: uid=admin,ou=system");
System.out.println("Password: secret");
System.out.println("LDAP server started in " + (System.currentTimeMillis() - startTime) + "ms");
}
示例12: startKerberos
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
@SuppressWarnings("unused")
private ApacheDS startKerberos() throws Exception {
Preconditions.checkState(ldapServer.isStarted());
kdcServer.setDirectoryService(directoryService);
// FIXME hard-coded ports
kdcServer.setTransports(new TcpTransport(6088), new UdpTransport(6088));
kdcServer.setEnabled(true);
kdcServer.setPrimaryRealm(realm);
kdcServer.setSearchBaseDn(baseDn);
kdcServer.setKdcPrincipal("krbtgt/" + realm + "@" + baseDn);
kdcServer.start();
// -------------------------------------------------------------------
// Enable the krb5kdc schema
// -------------------------------------------------------------------
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(DirectoryService.JNDI_KEY, directoryService);
env.put(Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName());
env.put(Context.PROVIDER_URL, ServerDNConstants.OU_SCHEMA_DN);
InitialLdapContext schemaRoot = new InitialLdapContext(env, null);
// check if krb5kdc is disabled
Attributes krb5kdcAttrs = schemaRoot.getAttributes("cn=Krb5kdc");
boolean isKrb5KdcDisabled = false;
if (krb5kdcAttrs.get("m-disabled") != null) {
isKrb5KdcDisabled = ((String) krb5kdcAttrs.get("m-disabled").get()).equalsIgnoreCase("TRUE");
}
// if krb5kdc is disabled then enable it
if (isKrb5KdcDisabled) {
Attribute disabled = new BasicAttribute("m-disabled");
ModificationItem[] mods = new ModificationItem[] {new ModificationItem(DirContext.REMOVE_ATTRIBUTE, disabled)};
schemaRoot.modifyAttributes("cn=Krb5kdc", mods);
}
return this;
}
示例13: contextInitialized
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
/**
* Startup ApacheDS embedded.
*
* @param sce ServletContext event
*/
@Override
public void contextInitialized(final ServletContextEvent sce) {
File workDir = (File) sce.getServletContext().getAttribute(
"javax.servlet.context.tempdir");
workDir = new File(workDir, "server-work");
if (!workDir.mkdirs()) {
throw new RuntimeException("Could not create " + workDir.
getAbsolutePath());
}
Entry result;
try {
initDirectoryService(sce.getServletContext(), workDir);
server = new LdapServer();
server.setTransports(new TcpTransport(Integer.valueOf(
sce.getServletContext().
getInitParameter("testds.port"))));
server.setDirectoryService(service);
server.start();
// store directoryService in context to provide it to servlets etc.
sce.getServletContext().setAttribute(DirectoryService.JNDI_KEY,
service);
result = service.getAdminSession().lookup(new DN("o=isp"));
} catch (Exception e) {
sce.getServletContext().log("Fatal error in context init", e);
throw new RuntimeException(e);
}
if (result == null) {
throw new RuntimeException("Base DN not found");
} else {
sce.getServletContext().log(
"ApacheDS startup completed succesfully");
}
}
示例14: startServer
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
/**
* 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();
}
示例15: start
import org.apache.directory.server.protocol.shared.transport.TcpTransport; //导入依赖的package包/类
public void start() throws Exception {
DirectoryServiceFactory factory = new DefaultDirectoryServiceFactory();
factory.init("server");
service = factory.getDirectoryService();
service.addPartition(createPartition("default", "cn=test"));
service.addPartition(createPartition("domain", "dc=example,dc=com"));
server = new LdapServer();
server.setDirectoryService(service);
server.setTransports(new TcpTransport(PORT));
server.start();
}