### Eclipse Workspace Patch 1.0 #P oak-core Index: src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionEntryProviderImpl.java =================================================================== --- src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionEntryProviderImpl.java (revision 1655580) +++ src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionEntryProviderImpl.java (working copy) @@ -65,6 +65,13 @@ existingNames.clear(); for (String name: principalNames) { long n = cache.getNumEntries(store, name, maxSize); + // cache.getNumEntries can return Long.MAX_VALUE + // if the underlying implementation does not know the + // exact value, and the child node count is higher than maxSize + if (Long.MAX_VALUE == n) { + cnt = Long.MAX_VALUE; + break; + } cnt+= n; if (n > 0) { existingNames.add(name); Index: src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionEntryProviderImplTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionEntryProviderImplTest.java (revision 0) +++ src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionEntryProviderImplTest.java (working copy) @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.security.authorization.permission; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nonnull; +import junit.framework.Assert; +import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; +import org.junit.Test; + +public class PermissionEntryProviderImplTest { + + private final String GROUP_1 = "group1"; + private final String EVERYONE = "everyone"; + + @Test + public void testInitLongOverflow() throws Exception { + PermissionStore store = new MockPermissionStore(); + PermissionEntryCache cache = new MockPermissionEntryCache(); + Set principalNames = new HashSet() { + { + add(GROUP_1); + add(EVERYONE); + } + }; + + PermissionEntryProviderImpl permissionEntryProviderImpl = new PermissionEntryProviderImpl( + store, cache, principalNames, ConfigurationParameters.EMPTY); + } + + // Inner Classes + private class MockPermissionStore implements PermissionStore { + + @Override + public Collection load( + Collection entries, String principalName, + String path) { + return null; + } + + @Override + public void load(Map> entries, + String principalName) { + + } + + @Override + public PrincipalPermissionEntries load(String principalName) { + return null; + } + + @Override + public long getNumEntries(String principalName, long max) { + if (GROUP_1.equals(principalName)) { + return 10; + } else { + return Long.MAX_VALUE; + } + } + + } + + private class MockPermissionEntryCache extends PermissionEntryCache { + @Override + public void load(@Nonnull PermissionStore store, + @Nonnull Map> pathEntryMap, + @Nonnull String principalName) { + Assert.fail("The number of entries exceeds the max cache size"); + } + } +}