Skip to content

Commit

Permalink
OAK-11035: Remove usage of Guava Strings.nullToEmpty (apache#1656)
Browse files Browse the repository at this point in the history
* OAK-11033: Remove usage of Guava Objects class

* OAK-11035: Remove usage of Guava Strings.nullToEmpty

* OAK-11035: Remove usage of Guava Strings.nullToEmpty (fix WS)
  • Loading branch information
reschke authored Aug 20, 2024
1 parent 0ac755f commit 1a4e15e
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal;

import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Iterators;
Expand Down Expand Up @@ -121,7 +120,7 @@ class ExternalGroupPrincipalProvider implements PrincipalProvider, ExternalIdent
this.root = root;
this.namePathMapper = namePathMapper;
this.userManager = userManager;

idpNamesWithDynamicGroups = syncConfigTracker.getIdpNamesWithDynamicGroups();
hasOnlyDynamicGroups = (idpNamesWithDynamicGroups.size() == syncConfigTracker.getServiceReferences().length);

Expand Down Expand Up @@ -158,7 +157,7 @@ public Principal getPrincipal(@NotNull String principalName) {
// shortcut: the default user-principal-provider will return the group principal
return null;
}

Result result = findPrincipals(principalName, true);
Iterator<? extends ResultRow> rows = (result == null) ? Collections.emptyIterator() : result.getRows().iterator();
if (rows.hasNext()) {
Expand Down Expand Up @@ -210,9 +209,9 @@ public Iterator<? extends Principal> findPrincipals(@Nullable String nameHint, i
if (PrincipalManager.SEARCH_TYPE_NOT_GROUP == searchType || hasOnlyDynamicGroups) {
return Collections.emptyIterator();
}

// search for external group principals that have not been synchronzied into the repository
Result result = findPrincipals(Strings.nullToEmpty(nameHint), false);
Result result = findPrincipals(Objects.toString(nameHint, ""), false);
if (result != null) {
return Iterators.filter(new GroupPrincipalIterator(nameHint, result), Objects::nonNull);
} else {
Expand Down Expand Up @@ -304,7 +303,7 @@ public boolean isMember(@NotNull Group group, @NotNull Authorizable authorizable
if (vs == null || vs.length == 0) {
return Collections.emptyIterator();
}

Set<Value> valueSet = ImmutableSet.copyOf(vs);
Iterator<Group> declared = Iterators.filter(Iterators.transform(valueSet.iterator(), value -> {
try {
Expand Down Expand Up @@ -340,7 +339,7 @@ private static boolean isValidGroup(@Nullable Authorizable group, @NotNull Autho
}
return isSameIDP(group, member);
}

/**
* Returns true if the given user/group belongs to an IDP that has dynamic-group configuration option enabled.
*/
Expand Down Expand Up @@ -482,7 +481,7 @@ private Result findPrincipals(@NotNull String nameHint, boolean exactMatch) {
}
return Collections.singletonMap(BINDING_PRINCIPAL_NAMES, PropertyValues.newString(val));
}

private static boolean isDynamicMember(@NotNull String groupPrincipalName, @Nullable Authorizable member) throws RepositoryException {
if (member == null || member.isGroup()) {
return false;
Expand All @@ -499,7 +498,7 @@ private static boolean isDynamicMember(@NotNull String groupPrincipalName, @Null
}
return false;
}

private boolean hasDynamicMembershipPrincipals(@NotNull Principal principal) {
if (!GroupPrincipals.isGroup(principal)) {
return true;
Expand All @@ -509,9 +508,9 @@ private boolean hasDynamicMembershipPrincipals(@NotNull Principal principal) {
return principal instanceof ItemBasedPrincipal;
}
}

//------------------------------------------------------< inner classes >---

private GroupPrincipal createExternalGroupPrincipal(@NotNull String principalName, @Nullable String idpName) {
if (idpNamesWithDynamicGroups.contains(idpName)) {
return new ExternalGroupPrincipalItemBased(principalName, idpName);
Expand Down Expand Up @@ -550,10 +549,10 @@ private ExternalGroupPrincipalItemBased(@NotNull String principalName, @Nullable
private class ExternalGroupPrincipal extends PrincipalImpl implements GroupPrincipal {

private final String idpName;

private ExternalGroupPrincipal(@NotNull String principalName, @Nullable String idpName) {
super(principalName);
this.idpName = Strings.nullToEmpty(idpName);
this.idpName = Objects.toString(idpName, "");
}

/**
Expand Down Expand Up @@ -687,7 +686,7 @@ private abstract class MemberIterator<T> extends AbstractLazyIterator<T> {
* {@link #REP_EXTERNAL_PRINCIPAL_NAMES} property values.
*/
private final Iterator<? extends ResultRow> rows;

private MemberIterator(@NotNull Result queryResult) {
rows = queryResult.getRows().iterator();
}
Expand All @@ -707,7 +706,7 @@ private MemberIterator(@NotNull Result queryResult) {
}
return null;
}

abstract T get(@NotNull Authorizable authorizable) throws RepositoryException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;

class EntryCache implements Constants {

Expand All @@ -63,7 +64,7 @@ class EntryCache implements Constants {
for (Tree child : policyTree.getChildren()) {
if (Constants.NT_REP_PRINCIPAL_ENTRY.equals(TreeUtil.getPrimaryTypeName(child))) {
PermissionEntryImpl entry = new PermissionEntryImpl(child);
String key = Strings.nullToEmpty(entry.effectivePath);
String key = Objects.toString(entry.effectivePath, "");
List<PermissionEntry> list = entries.computeIfAbsent(key, k -> new ArrayList<>());
list.add(entry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import javax.jcr.RepositoryException;
import java.security.Principal;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState;
Expand Down Expand Up @@ -199,7 +200,7 @@ private boolean isValidPrincipal(@NotNull Principal principal) {
return true;
} else {
validatedPrincipalNamesPathMap.remove(principalName);
unsupportedPrincipalNames.put(principalName, Strings.nullToEmpty(principalPath));
unsupportedPrincipalNames.put(principalName, Objects.toString(principalPath, ""));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -109,7 +110,7 @@ class PrincipalBasedAccessControlManager extends AbstractAccessControlManager im
this.filterProvider = filterProvider;
filter = filterProvider.getFilter(mgrProvider.getSecurityProvider(), mgrProvider.getRoot(), mgrProvider.getNamePathMapper());
}

@Override
protected @NotNull PrivilegeBitsProvider getPrivilegeBitsProvider() {
return mgrProvider.getPrivilegeBitsProvider();
Expand Down Expand Up @@ -273,7 +274,7 @@ public void setPolicy(String absPath, AccessControlPolicy policy) throws Reposit
int i = 0;
RestrictionProvider restrictionProvider = mgrProvider.getRestrictionProvider();
for (PrincipalPolicyImpl.EntryImpl entry : pp.getEntries()) {
String effectiveOakPath = Strings.nullToEmpty(entry.getOakPath());
String effectiveOakPath = Objects.toString(entry.getOakPath(), "");
Tree entryTree = TreeUtil.addChild(policyTree, "entry" + i++, NT_REP_PRINCIPAL_ENTRY);
if (!Utils.hasModAcPermission(getPermissionProvider(), effectiveOakPath)) {
throw new AccessDeniedException("Access denied.");
Expand Down Expand Up @@ -406,7 +407,7 @@ private boolean isAccessControlled(@NotNull Tree tree) {
private static Iterable<String> getEffectivePaths(@Nullable String oakPath) {
// read-access-control permission has already been check for 'oakPath'
List<String> paths = Lists.newArrayList();
paths.add(Strings.nullToEmpty(oakPath));
paths.add(Objects.toString(oakPath, ""));

String effectivePath = oakPath;
while (effectivePath != null && !PathUtils.denotesRoot(effectivePath)) {
Expand All @@ -425,12 +426,12 @@ private AbstractEntry createEffectiveEntry(@NotNull Tree entryTree) throws Acces
}
String oakPath = Strings.emptyToNull(TreeUtil.getString(entryTree, REP_EFFECTIVE_PATH));
PrivilegeBits bits = privilegeBitsProvider.getBits(entryTree.getProperty(Constants.REP_PRIVILEGES).getValue(Type.NAMES));

RestrictionProvider rp = mgrProvider.getRestrictionProvider();
if (!Utils.hasValidRestrictions(oakPath, entryTree, rp)) {
return null;
}

Set<Restriction> restrictions = Utils.readRestrictions(rp, oakPath, entryTree);
NamePathMapper npMapper = getNamePathMapper();
return new AbstractEntry(oakPath, principal, bits, restrictions, npMapper) {
Expand All @@ -443,7 +444,7 @@ private AbstractEntry createEffectiveEntry(@NotNull Tree entryTree) throws Acces
protected @NotNull PrivilegeBitsProvider getPrivilegeBitsProvider() {
return privilegeBitsProvider;
}

@Override
public Privilege[] getPrivileges() {
Set<String> names = privilegeBitsProvider.getPrivilegeNames(getPrivilegeBits());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl;

import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.ImmutableMap;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
Expand Down Expand Up @@ -56,6 +55,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants.REP_GLOB;
import static org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants.REP_ITEM_NAMES;
Expand Down Expand Up @@ -117,7 +117,7 @@ private PrincipalPolicyImpl createPolicy(@NotNull String oakPath) {

private Tree createEntryTree(@NotNull PrincipalPolicyImpl.EntryImpl entry) {
Tree t = mock(Tree.class);
PropertyState path = PropertyStates.createProperty(REP_EFFECTIVE_PATH, Strings.nullToEmpty(entry.getOakPath()));
PropertyState path = PropertyStates.createProperty(REP_EFFECTIVE_PATH, Objects.toString(entry.getOakPath(), ""));
when(t.getProperty(REP_EFFECTIVE_PATH)).thenReturn(path);
PropertyState privs = PropertyStates.createProperty(REP_PRIVILEGES, privilegeBitsProvider.getPrivilegeNames(entry.getPrivilegeBits()), Type.NAMES);
when(t.getProperty(REP_PRIVILEGES)).thenReturn(privs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage;

import static org.apache.jackrabbit.guava.common.base.Strings.nullToEmpty;
import static java.lang.Thread.currentThread;

import java.io.BufferedInputStream;
Expand All @@ -40,6 +38,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Queue;
Expand Down Expand Up @@ -853,8 +852,8 @@ URI createHttpDownloadURI(@NotNull DataIdentifier identifier,

String cacheKey = identifier.toString()
+ domain
+ nullToEmpty(downloadOptions.getContentTypeHeader())
+ nullToEmpty(downloadOptions.getContentDispositionHeader());
+ Objects.toString(downloadOptions.getContentTypeHeader(), "")
+ Objects.toString(downloadOptions.getContentDispositionHeader(), "");
if (null != httpDownloadURICache) {
uri = httpDownloadURICache.getIfPresent(cacheKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;

import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.guava.common.base.Strings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -242,7 +242,7 @@ public static int writeStrings(Iterator<String> iterator, File f, boolean escape
count++;
if (logger != null) {
if (count % 100000 == 0) {
logger.info(Strings.nullToEmpty(message) + count);
logger.info(Objects.toString(message, "") + count);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.security.authorization.permission;

import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.commons.iterator.AbstractLazyIterator;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
Expand All @@ -25,6 +24,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;

class PermissionEntryProviderImpl implements PermissionEntryProvider {
Expand Down Expand Up @@ -104,7 +104,7 @@ private final class EntryIterator extends AbstractLazyIterator<PermissionEntry>

private EntryIterator(@NotNull EntryPredicate predicate) {
this.predicate = predicate;
this.path = Strings.nullToEmpty(predicate.getPath());
this.path = Objects.toString(predicate.getPath(), "");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import java.security.Principal;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import org.apache.jackrabbit.guava.common.base.Strings;

import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
Expand Down Expand Up @@ -57,7 +58,7 @@ public static String getParentPathOrNull(@NotNull final String path) {

@NotNull
public static String getEntryName(@Nullable String accessControlledPath) {
String path = Strings.nullToEmpty(accessControlledPath);
String path = Objects.toString(accessControlledPath, "");
return String.valueOf(path.hashCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import java.text.ParseException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Objects;

import javax.jcr.AccessDeniedException;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.query.Query;

import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.QueryEngine;
import org.apache.jackrabbit.oak.api.Result;
Expand Down Expand Up @@ -268,7 +269,7 @@ private Tree createAuthorizableNode(@NotNull String authorizableId,
}

Tree typeRoot = root.getTree(NODE_TYPES_PATH);
String userId = Strings.nullToEmpty(root.getContentSession().getAuthInfo().getUserID());
String userId = Objects.toString(root.getContentSession().getAuthInfo().getUserID(), "");
Tree authorizableNode = TreeUtil.addChild(folder, nodeName, ntName, typeRoot, userId);
authorizableNode.setProperty(REP_AUTHORIZABLE_ID, authorizableId);
authorizableNode.setProperty(JcrConstants.JCR_UUID, getContentID(authorizableId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Calendar;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;

Expand All @@ -26,7 +27,6 @@
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;

import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.collect.Sets;
Expand Down Expand Up @@ -443,7 +443,7 @@ public static PropertyState autoCreateProperty(@NotNull String name,
return PropertyStates.createProperty(name, ISO8601.format(Calendar.getInstance()), DATE);
case JCR_CREATEDBY:
case JCR_LASTMODIFIEDBY:
return PropertyStates.createProperty(name, Strings.nullToEmpty(userID), STRING);
return PropertyStates.createProperty(name, Objects.toString(userID, ""), STRING);
default:
// no default, continue inspecting the definition
}
Expand Down
Loading

0 comments on commit 1a4e15e

Please sign in to comment.