Search in sources :

Example 46 with NameNotFoundException

use of javax.naming.NameNotFoundException in project spring-security by spring-projects.

the class ActiveDirectoryLdapAuthenticationProviderTests method failedUserSearchCausesBadCredentials.

@Test
public void failedUserSearchCausesBadCredentials() throws Exception {
    DirContext ctx = mock(DirContext.class);
    given(ctx.getNameInNamespace()).willReturn("");
    given(ctx.search(any(Name.class), any(String.class), any(Object[].class), any(SearchControls.class))).willThrow(new NameNotFoundException());
    this.provider.contextFactory = createContextFactoryReturning(ctx);
    assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(() -> this.provider.authenticate(this.joe));
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) SearchControls(javax.naming.directory.SearchControls) DirContext(javax.naming.directory.DirContext) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) Name(javax.naming.Name) DistinguishedName(org.springframework.ldap.core.DistinguishedName) Test(org.junit.jupiter.api.Test)

Example 47 with NameNotFoundException

use of javax.naming.NameNotFoundException in project wildfly by wildfly.

the class NamingContextTestCase method testListBindingsNameNotFound.

@Test
public void testListBindingsNameNotFound() throws Exception {
    try {
        namingContext.listBindings(new CompositeName("test"));
        fail("Should have thrown and NameNotFoundException");
    } catch (NameNotFoundException expected) {
    }
    // the same with security permissions
    try {
        testActionPermission(JndiPermission.ACTION_LIST_BINDINGS, namingContext, "test");
        fail("Should have thrown and NameNotFoundException with appropriate permissions");
    } catch (NameNotFoundException expected) {
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 48 with NameNotFoundException

use of javax.naming.NameNotFoundException in project wildfly by wildfly.

the class NamingContextTestCase method testListNameNotFound.

@Test
public void testListNameNotFound() throws Exception {
    try {
        namingContext.list(new CompositeName("test"));
        fail("Should have thrown and NameNotFoundException");
    } catch (NameNotFoundException expected) {
    }
    // the same with security permissions
    try {
        testActionPermission(JndiPermission.ACTION_LIST, namingContext, "test");
        fail("Should have thrown and NameNotFoundException with appropriate permissions");
    } catch (NameNotFoundException expected) {
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 49 with NameNotFoundException

use of javax.naming.NameNotFoundException in project wildfly by wildfly.

the class WritableServiceBasedNamingStoreTestCase method testUnbind.

@Test
public void testUnbind() throws Exception {
    final Name name = new CompositeName("test");
    final Object value = new Object();
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Example 50 with NameNotFoundException

use of javax.naming.NameNotFoundException in project wildfly by wildfly.

the class WritableServiceBasedNamingStoreTestCase method testMultipleOwnersBindingReferences.

@Test
public void testMultipleOwnersBindingReferences() throws Exception {
    final Name name = new CompositeName("test");
    final ServiceName serviceName = store.buildServiceName(name);
    final Object value = new Object();
    // ensure bind does not exists
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
    // ensure the owners RuntimeBindReleaseService have no reference to the future bind
    final RuntimeBindReleaseService.References fooDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_FOO)).getValue();
    assertFalse(fooDuBindingReferences.contains(serviceName));
    final RuntimeBindReleaseService.References barDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_BAR)).getValue();
    assertFalse(barDuBindingReferences.contains(serviceName));
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        // Foo's RuntimeBindReleaseService should now have a reference to the new bind
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // Bar's RuntimeBindReleaseService reference to the bind should not exist
        assertFalse(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_BAR);
    try {
        store.rebind(name, value);
        // after rebind, Foo's RuntimeBindReleaseService reference to the bind should still exist
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // after rebind, Bar's RuntimeBindReleaseService reference to the bind should now exist
        assertTrue(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Aggregations

NameNotFoundException (javax.naming.NameNotFoundException)168 NamingException (javax.naming.NamingException)81 InitialContext (javax.naming.InitialContext)75 Context (javax.naming.Context)71 Reference (javax.naming.Reference)40 Test (org.junit.Test)39 NotContextException (javax.naming.NotContextException)35 Name (javax.naming.Name)34 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)33 OperationNotSupportedException (javax.naming.OperationNotSupportedException)29 CompositeName (javax.naming.CompositeName)27 Binding (javax.naming.Binding)22 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)16 IOException (java.io.IOException)12 NamingContext (org.eclipse.jetty.jndi.NamingContext)12 ArrayList (java.util.ArrayList)10 InvalidNameException (javax.naming.InvalidNameException)10 Attributes (javax.naming.directory.Attributes)10 HashMap (java.util.HashMap)7