1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.helper;
17
18 import java.util.Locale;
19
20 import org.apache.logging.log4j.LogManager;
21 import org.apache.logging.log4j.Logger;
22 import org.codelibs.fess.mylasta.direction.FessConfig;
23 import org.codelibs.fess.util.ComponentUtil;
24 import org.codelibs.jcifs.smb.SID;
25
26 import jakarta.annotation.PostConstruct;
27
28
29
30
31 public class SambaHelper {
32
33 private static final Logger logger = LogManager.getLogger(SambaHelper.class);
34
35
36
37
38 public static final int SID_TYPE_ALIAS = 4;
39
40
41
42
43 public static final int SID_TYPE_DELETED = 6;
44
45
46
47
48 public static final int SID_TYPE_DOM_GRP = 2;
49
50
51
52
53 public static final int SID_TYPE_DOMAIN = 3;
54
55
56
57
58 public static final int SID_TYPE_INVALID = 7;
59
60
61
62
63 public static final int SID_TYPE_UNKNOWN = 8;
64
65
66
67
68 public static final int SID_TYPE_USE_NONE = 0;
69
70
71
72
73 public static final int SID_TYPE_USER = 1;
74
75
76
77
78 public static final int SID_TYPE_WKN_GRP = 5;
79
80
81
82
83 protected FessConfig fessConfig;
84
85
86
87
88 public SambaHelper() {
89 super();
90 }
91
92
93
94
95 @PostConstruct
96 public void init() {
97 if (logger.isDebugEnabled()) {
98 logger.debug("Initializing {}", this.getClass().getSimpleName());
99 }
100 fessConfig = ComponentUtil.getFessConfig();
101 }
102
103
104
105
106
107
108 public String getAccountId(final SID sid) {
109 final int type = sid.getType();
110 if (logger.isDebugEnabled()) {
111 try {
112 logger.debug("Processing SID: {} {} {}", type, sid, sid.toDisplayString());
113 } catch (final Exception e) {
114
115 }
116 }
117 final Integer id = fessConfig.getAvailableSmbSidType(type);
118 if (id != null) {
119 return createSearchRole(id, sid.getAccountName());
120 }
121 if (logger.isDebugEnabled()) {
122 logger.debug("Ignored SID: {} {}", type, sid);
123 }
124 return null;
125 }
126
127
128
129
130
131
132 public String getAccountId(final org.codelibs.jcifs.smb1.SID sid) {
133 final int type = sid.getType();
134 if (logger.isDebugEnabled()) {
135 try {
136 logger.debug("Processing SID: {} {} {}", type, sid, sid.toDisplayString());
137 } catch (final Exception e) {
138
139 }
140 }
141 final Integer id = fessConfig.getAvailableSmbSidType(type);
142 if (id != null) {
143 return createSearchRole(id, sid.getAccountName());
144 }
145 if (logger.isDebugEnabled()) {
146 logger.debug("Ignored SID: {} {}", type, sid);
147 }
148 return null;
149 }
150
151
152
153
154
155
156
157 protected String createSearchRole(final int type, final String name) {
158 if (fessConfig.isLdapLowercasePermissionName()) {
159 return type + fessConfig.getCanonicalLdapName(name).toLowerCase(Locale.ROOT);
160 }
161 return type + fessConfig.getCanonicalLdapName(name);
162 }
163 }