use of javax.naming.NameClassPair in project activemq-artemis by apache.
the class SaslKrb5LDAPSecurityTest method testSaslGssapiLdapAuth.
@Test
public void testSaslGssapiLdapAuth() throws Exception {
final Hashtable<String, String> env = new Hashtable<>();
env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");
LoginContext loginContext = new LoginContext("broker-sasl-gssapi");
loginContext.login();
try {
Subject.doAs(loginContext.getSubject(), (PrivilegedExceptionAction<Object>) () -> {
HashSet<String> set = new HashSet<>();
DirContext ctx = new InitialDirContext(env);
NamingEnumeration<NameClassPair> list = ctx.list("ou=system");
while (list.hasMore()) {
NameClassPair ncp = list.next();
set.add(ncp.getName());
}
Assert.assertTrue(set.contains("uid=first"));
Assert.assertTrue(set.contains("cn=users"));
Assert.assertTrue(set.contains("ou=configuration"));
Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
ctx.close();
return null;
});
} catch (PrivilegedActionException e) {
throw e.getException();
}
}
use of javax.naming.NameClassPair in project activemq-artemis by apache.
the class LDAPAuthorizationMapTest method testOpen.
@Test
public void testOpen() throws Exception {
DirContext ctx = authMap.open();
HashSet<String> set = new HashSet<>();
NamingEnumeration<NameClassPair> list = ctx.list("ou=destinations,o=ActiveMQ,ou=system");
while (list.hasMore()) {
NameClassPair ncp = list.next();
set.add(ncp.getName());
}
assertTrue(set.contains("ou=topics"));
assertTrue(set.contains("ou=queues"));
}
use of javax.naming.NameClassPair in project activemq-artemis by apache.
the class LegacyLDAPSecuritySettingPluginListenerTest method testRunning.
@Test
public void testRunning() throws Exception {
DirContext ctx = getContext();
HashSet<String> set = new HashSet<>();
NamingEnumeration<NameClassPair> list = ctx.list("ou=system");
while (list.hasMore()) {
NameClassPair ncp = list.next();
set.add(ncp.getName());
}
Assert.assertTrue(set.contains("uid=admin"));
Assert.assertTrue(set.contains("ou=users"));
Assert.assertTrue(set.contains("ou=groups"));
Assert.assertTrue(set.contains("ou=configuration"));
Assert.assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
use of javax.naming.NameClassPair in project activemq-artemis by apache.
the class LDAPLoginModuleTest method testRunning.
@Test
public void testRunning() throws Exception {
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.PROVIDER_URL, "ldap://localhost:1024");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, PRINCIPAL);
env.put(Context.SECURITY_CREDENTIALS, CREDENTIALS);
DirContext ctx = new InitialDirContext(env);
HashSet<String> set = new HashSet<>();
NamingEnumeration<NameClassPair> list = ctx.list("ou=system");
while (list.hasMore()) {
NameClassPair ncp = list.next();
set.add(ncp.getName());
}
assertTrue(set.contains("uid=admin"));
assertTrue(set.contains("ou=users"));
assertTrue(set.contains("ou=groups"));
assertTrue(set.contains("ou=configuration"));
assertTrue(set.contains("prefNodeName=sysPrefRoot"));
}
use of javax.naming.NameClassPair in project tomcat70 by apache.
the class WebappLoader method setRepositories.
/**
* Configure the repositories for our class loader, based on the
* associated Context.
* @throws IOException
*/
private void setRepositories() throws IOException {
if (!(container instanceof Context))
return;
ServletContext servletContext = ((Context) container).getServletContext();
if (servletContext == null)
return;
loaderRepositories = new ArrayList<String>();
// Loading the work directory
File workDir = (File) servletContext.getAttribute(ServletContext.TEMPDIR);
if (workDir == null) {
log.info("No work dir for " + servletContext);
}
if (log.isDebugEnabled() && workDir != null)
log.debug(sm.getString("webappLoader.deploy", workDir.getAbsolutePath()));
classLoader.setWorkDir(workDir);
DirContext resources = container.getResources();
// Setting up the class repository (/WEB-INF/classes), if it exists
String classesPath = "/WEB-INF/classes";
DirContext classes = null;
try {
Object object = resources.lookup(classesPath);
if (object instanceof DirContext) {
classes = (DirContext) object;
}
} catch (NamingException e) {
// Silent catch: it's valid that no /WEB-INF/classes collection
// exists
}
if (classes != null) {
File classRepository = null;
String absoluteClassesPath = servletContext.getRealPath(classesPath);
if (absoluteClassesPath != null) {
classRepository = new File(absoluteClassesPath);
} else {
classRepository = new File(workDir, classesPath);
if (!classRepository.mkdirs() && !classRepository.isDirectory()) {
throw new IOException(sm.getString("webappLoader.mkdirFailure"));
}
if (!copyDir(classes, classRepository)) {
throw new IOException(sm.getString("webappLoader.copyFailure"));
}
}
if (log.isDebugEnabled())
log.debug(sm.getString("webappLoader.classDeploy", classesPath, classRepository.getAbsolutePath()));
// Adding the repository to the class loader
classLoader.addRepository(classesPath + "/", classRepository);
loaderRepositories.add(classesPath + "/");
}
// Setting up the JAR repository (/WEB-INF/lib), if it exists
String libPath = "/WEB-INF/lib";
classLoader.setJarPath(libPath);
DirContext libDir = null;
// Looking up directory /WEB-INF/lib in the context
try {
Object object = resources.lookup(libPath);
if (object instanceof DirContext)
libDir = (DirContext) object;
} catch (NamingException e) {
// Silent catch: it's valid that no /WEB-INF/lib collection
// exists
}
if (libDir != null) {
boolean copyJars = false;
String absoluteLibPath = servletContext.getRealPath(libPath);
File destDir = null;
if (absoluteLibPath != null) {
destDir = new File(absoluteLibPath);
} else {
copyJars = true;
destDir = new File(workDir, libPath);
if (!destDir.mkdirs() && !destDir.isDirectory()) {
throw new IOException(sm.getString("webappLoader.mkdirFailure"));
}
}
// Looking up directory /WEB-INF/lib in the context
NamingEnumeration<NameClassPair> enumeration = null;
try {
enumeration = libDir.list("");
} catch (NamingException e) {
IOException ioe = new IOException(sm.getString("webappLoader.namingFailure", libPath));
ioe.initCause(e);
throw ioe;
}
while (enumeration.hasMoreElements()) {
NameClassPair ncPair = enumeration.nextElement();
String filename = libPath + "/" + ncPair.getName();
if (!filename.endsWith(".jar"))
continue;
// Copy JAR in the work directory, always (the JAR file
// would get locked otherwise, which would make it
// impossible to update it or remove it at runtime)
File destFile = new File(destDir, ncPair.getName());
if (log.isDebugEnabled())
log.debug(sm.getString("webappLoader.jarDeploy", filename, destFile.getAbsolutePath()));
// Bug 45403 - Explicitly call lookup() on the name to check
// that the resource is readable. We cannot use resources
// returned by listBindings(), because that lists all of them,
// but does not perform the necessary checks on each.
Object obj = null;
try {
obj = libDir.lookup(ncPair.getName());
} catch (NamingException e) {
IOException ioe = new IOException(sm.getString("webappLoader.namingFailure", filename));
ioe.initCause(e);
throw ioe;
}
if (!(obj instanceof Resource))
continue;
Resource jarResource = (Resource) obj;
if (copyJars) {
if (!copy(jarResource.streamContent(), new FileOutputStream(destFile))) {
throw new IOException(sm.getString("webappLoader.copyFailure"));
}
}
try {
JarFile jarFile = JreCompat.getInstance().jarFileNewInstance(destFile);
classLoader.addJar(filename, jarFile, destFile);
} catch (Exception ex) {
// Catch the exception if there is an empty jar file
// Should ignore and continue loading other jar files
// in the dir
}
loaderRepositories.add(filename);
}
}
}
Aggregations