From a233a847a46ca44057f3b13181f0f6db430ebfc0 Mon Sep 17 00:00:00 2001 From: Shinsuke Sugaya Date: Thu, 27 Jun 2024 19:55:43 +0900 Subject: [PATCH] fix #2824 Convert role names to lowercase for SMB crawling when ldap.lowercase.permission.name=true --- .../org/codelibs/fess/helper/SambaHelper.java | 5 + .../codelibs/fess/helper/SambaHelperTest.java | 124 ++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 src/test/java/org/codelibs/fess/helper/SambaHelperTest.java diff --git a/src/main/java/org/codelibs/fess/helper/SambaHelper.java b/src/main/java/org/codelibs/fess/helper/SambaHelper.java index cb7e46fb4..c0d8a494a 100644 --- a/src/main/java/org/codelibs/fess/helper/SambaHelper.java +++ b/src/main/java/org/codelibs/fess/helper/SambaHelper.java @@ -15,6 +15,8 @@ */ package org.codelibs.fess.helper; +import java.util.Locale; + import javax.annotation.PostConstruct; import org.apache.logging.log4j.LogManager; @@ -95,6 +97,9 @@ public String getAccountId(final jcifs.smb1.smb1.SID sid) { } protected String createSearchRole(final int type, final String name) { + if (fessConfig.isLdapLowercasePermissionName()) { + return type + fessConfig.getCanonicalLdapName(name).toLowerCase(Locale.ROOT); + } return type + fessConfig.getCanonicalLdapName(name); } } diff --git a/src/test/java/org/codelibs/fess/helper/SambaHelperTest.java b/src/test/java/org/codelibs/fess/helper/SambaHelperTest.java new file mode 100644 index 000000000..c878dd44e --- /dev/null +++ b/src/test/java/org/codelibs/fess/helper/SambaHelperTest.java @@ -0,0 +1,124 @@ +/* + * Copyright 2012-2024 CodeLibs Project and the Others. + * + * Licensed 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.codelibs.fess.helper; + +import org.codelibs.fess.mylasta.direction.FessConfig; +import org.codelibs.fess.unit.UnitFessTestCase; +import org.codelibs.fess.util.ComponentUtil; + +import jcifs.SID; +import jcifs.smb.SmbException; + +public class SambaHelperTest extends UnitFessTestCase { + + public SambaHelper sambaHelper; + + @Override + public void setUp() throws Exception { + super.setUp(); + sambaHelper = new SambaHelper(); + } + + public void test_smb_account() throws SmbException { + ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() { + @Override + public String getSmbAvailableSidTypes() { + return "1,2,4:2,5:1"; + } + + @Override + public boolean isLdapLowercasePermissionName() { + return false; + } + + @Override + public boolean isLdapIgnoreNetbiosName() { + return false; + } + }); + sambaHelper.init(); + + assertEquals("1Test User", sambaHelper.getAccountId(USER_SID)); + + } + + public void test_smb_account_lowercase() throws SmbException { + ComponentUtil.setFessConfig(new FessConfig.SimpleImpl() { + @Override + public String getSmbAvailableSidTypes() { + return "1,2,4:2,5:1"; + } + + @Override + public boolean isLdapLowercasePermissionName() { + return true; + } + + @Override + public boolean isLdapIgnoreNetbiosName() { + return false; + } + }); + sambaHelper.init(); + + assertEquals("1test user", sambaHelper.getAccountId(USER_SID)); + + } + + private static final SID USER_SID = new SID() { + + @Override + public SID getDomainSid() { + return null; + } + + @Override + public int getRid() { + return 0; + } + + @Override + public String toDisplayString() { + return getDomainName() + "\\" + getAccountName(); + } + + @Override + public String getAccountName() { + return "Test User"; + } + + @Override + public String getDomainName() { + return "WORKGROUP"; + } + + @Override + public String getTypeText() { + return "User"; + } + + @Override + public int getType() { + return 1; + } + + @Override + public T unwrap(Class type) { + return null; + } + }; + +}