Search in sources :

Example 66 with CompositeName

use of javax.naming.CompositeName in project gerrit by GerritCodeReview.

the class Helper method recursivelyExpandGroups.

private void recursivelyExpandGroups(final Set<String> groupDNs, final LdapSchema schema, final DirContext ctx, final String groupDN) {
    if (groupDNs.add(groupDN) && schema.accountMemberField != null && schema.accountMemberExpandGroups) {
        ImmutableSet<String> cachedParentsDNs = parentGroups.getIfPresent(groupDN);
        if (cachedParentsDNs == null) {
            // Recursively identify the groups it is a member of.
            ImmutableSet.Builder<String> dns = ImmutableSet.builder();
            try {
                final Name compositeGroupName = new CompositeName().add(groupDN);
                final Attribute in = ctx.getAttributes(compositeGroupName, schema.accountMemberFieldArray).get(schema.accountMemberField);
                if (in != null) {
                    final NamingEnumeration<?> groups = in.getAll();
                    try {
                        while (groups.hasMore()) {
                            dns.add((String) groups.next());
                        }
                    } catch (PartialResultException e) {
                    // Ignored
                    }
                }
            } catch (NamingException e) {
                logger.atWarning().withCause(e).log("Could not find group %s", groupDN);
            }
            cachedParentsDNs = dns.build();
            parentGroups.put(groupDN, cachedParentsDNs);
        }
        for (String dn : cachedParentsDNs) {
            recursivelyExpandGroups(groupDNs, schema, ctx, dn);
        }
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Attribute(javax.naming.directory.Attribute) CompositeName(javax.naming.CompositeName) PartialResultException(javax.naming.PartialResultException) NamingException(javax.naming.NamingException) ParameterizedString(com.google.gerrit.common.data.ParameterizedString) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 67 with CompositeName

use of javax.naming.CompositeName in project uPortal by Jasig.

the class JpaEventAggregationManagementDaoTest method testAggregatedGroupConfig.

@Test
public void testAggregatedGroupConfig() throws Exception {
    final IEntityGroup everyoneGroup = mock(IEntityGroup.class);
    when(everyoneGroup.getServiceName()).thenReturn(new CompositeName("local"));
    when(everyoneGroup.getName()).thenReturn("Everyone");
    when(compositeGroupService.findGroup("local.0")).thenReturn(everyoneGroup);
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
            assertNotNull(defaultAggregatedGroupConfig);
            assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
            assertEquals(0, defaultAggregatedGroupConfig.getIncluded().size());
            AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
            assertNull(loginAggregatedGroupConfig);
            loginAggregatedGroupConfig = eventAggregationManagementDao.createAggregatedGroupConfig(LoginPortalEventAggregator.class);
            assertNotNull(loginAggregatedGroupConfig);
            assertEquals(0, loginAggregatedGroupConfig.getExcluded().size());
            assertEquals(0, loginAggregatedGroupConfig.getIncluded().size());
            final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping("local.0");
            defaultAggregatedGroupConfig.getIncluded().add(group);
            loginAggregatedGroupConfig.getExcluded().add(group);
            eventAggregationManagementDao.updateAggregatedGroupConfig(defaultAggregatedGroupConfig);
            eventAggregationManagementDao.updateAggregatedGroupConfig(loginAggregatedGroupConfig);
        }
    });
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
            assertNotNull(defaultAggregatedGroupConfig);
            assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
            assertEquals(1, defaultAggregatedGroupConfig.getIncluded().size());
            AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
            assertNotNull(loginAggregatedGroupConfig);
            assertEquals(1, loginAggregatedGroupConfig.getExcluded().size());
            assertEquals(0, loginAggregatedGroupConfig.getIncluded().size());
            eventAggregationManagementDao.deleteAggregatedGroupConfig(defaultAggregatedGroupConfig);
            eventAggregationManagementDao.deleteAggregatedGroupConfig(loginAggregatedGroupConfig);
        }
    });
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
            assertNotNull(defaultAggregatedGroupConfig);
            assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
            assertEquals(0, defaultAggregatedGroupConfig.getIncluded().size());
            AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
            assertNull(loginAggregatedGroupConfig);
        }
    });
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) AggregatedGroupConfig(org.apereo.portal.events.aggr.AggregatedGroupConfig) CompositeName(javax.naming.CompositeName) LoginPortalEventAggregator(org.apereo.portal.events.aggr.login.LoginPortalEventAggregator) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Example 68 with CompositeName

use of javax.naming.CompositeName in project uPortal by Jasig.

the class JpaAggregatedGroupLookupDaoTest method testLoginAggregationLifecycle.

@Test
public void testLoginAggregationLifecycle() throws Exception {
    final IEntityGroup everyoneGroup = mock(IEntityGroup.class);
    when(everyoneGroup.getServiceName()).thenReturn(new CompositeName("local"));
    when(everyoneGroup.getName()).thenReturn("Everyone");
    when(compositeGroupService.findGroup("local.0")).thenReturn(everyoneGroup);
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupMapping groupMapping = aggregatedGroupLookupDao.getGroupMapping("local.0");
            assertNotNull(groupMapping);
            assertEquals("local", groupMapping.getGroupService());
            assertEquals("Everyone", groupMapping.getGroupName());
        }
    });
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupMapping groupMapping = aggregatedGroupLookupDao.getGroupMapping("local.0");
            assertNotNull(groupMapping);
            assertEquals("local", groupMapping.getGroupService());
            assertEquals("Everyone", groupMapping.getGroupName());
        }
    });
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupMapping groupMapping = aggregatedGroupLookupDao.getGroupMapping("local.2");
            assertNotNull(groupMapping);
            assertEquals("local", groupMapping.getGroupService());
            assertEquals("2", groupMapping.getGroupName());
        }
    });
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) CompositeName(javax.naming.CompositeName) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Example 69 with CompositeName

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

the class WritableServiceBasedNamingStoreTestCase method testBindNoOwner.

@Test
public void testBindNoOwner() throws Exception {
    try {
        store.bind(new CompositeName("test"), new Object());
        fail("Should have failed with a read-only context exception");
    } catch (UnsupportedOperationException expected) {
    }
}
Also used : CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 70 with CompositeName

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

the class WritableServiceBasedNamingStoreTestCase method testRebind.

@Test
public void testRebind() throws Exception {
    final Name name = new CompositeName("test");
    final Object value = new Object();
    final Object newValue = new Object();
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        store.rebind(name, newValue);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    assertEquals(newValue, store.lookup(name));
}
Also used : CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Aggregations

CompositeName (javax.naming.CompositeName)124 Test (org.junit.Test)69 Name (javax.naming.Name)43 NameNotFoundException (javax.naming.NameNotFoundException)27 NamingException (javax.naming.NamingException)25 Reference (javax.naming.Reference)19 Context (javax.naming.Context)18 InvalidNameException (javax.naming.InvalidNameException)13 NotContextException (javax.naming.NotContextException)12 ServiceName (org.jboss.msc.service.ServiceName)11 Test (org.junit.jupiter.api.Test)10 JndiPermission (org.wildfly.naming.java.permission.JndiPermission)10 Hashtable (java.util.Hashtable)9 Binding (javax.naming.Binding)8 LinkRef (javax.naming.LinkRef)8 OperationNotSupportedException (javax.naming.OperationNotSupportedException)8 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IEntityGroup (org.apereo.portal.groups.IEntityGroup)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 StringRefAddr (javax.naming.StringRefAddr)5