1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.helper;
17
18 import javax.annotation.PostConstruct;
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
25 import jcifs.SID;
26
27 public class SambaHelper {
28
29 private static final Logger logger = LogManager.getLogger(SambaHelper.class);
30
31 public static final int SID_TYPE_ALIAS = 4;
32
33 public static final int SID_TYPE_DELETED = 6;
34
35 public static final int SID_TYPE_DOM_GRP = 2;
36
37 public static final int SID_TYPE_DOMAIN = 3;
38
39 public static final int SID_TYPE_INVALID = 7;
40
41 public static final int SID_TYPE_UNKNOWN = 8;
42
43 public static final int SID_TYPE_USE_NONE = 0;
44
45 public static final int SID_TYPE_USER = 1;
46
47 public static final int SID_TYPE_WKN_GRP = 5;
48
49 protected FessConfig fessConfig;
50
51 @PostConstruct
52 public void init() {
53 if (logger.isDebugEnabled()) {
54 logger.debug("Initialize {}", this.getClass().getSimpleName());
55 }
56 fessConfig = ComponentUtil.getFessConfig();
57 }
58
59 public String getAccountId(final SID sid) {
60 final int type = sid.getType();
61 if (logger.isDebugEnabled()) {
62 try {
63 logger.debug("Processing SID: {} {} {}", type, sid, sid.toDisplayString());
64 } catch (final Exception e) {
65
66 }
67 }
68 final Integer id = fessConfig.getAvailableSmbSidType(type);
69 if (id != null) {
70 return createSearchRole(id, sid.getAccountName());
71 }
72 if (logger.isDebugEnabled()) {
73 logger.debug("Ignored SID: {} {}", type, sid);
74 }
75 return null;
76 }
77
78 public String getAccountId(final jcifs.smb1.smb1.SID sid) {
79 final int type = sid.getType();
80 if (logger.isDebugEnabled()) {
81 try {
82 logger.debug("Processing SID: {} {} {}", type, sid, sid.toDisplayString());
83 } catch (final Exception e) {
84
85 }
86 }
87 final Integer id = fessConfig.getAvailableSmbSidType(type);
88 if (id != null) {
89 return createSearchRole(id, sid.getAccountName());
90 }
91 if (logger.isDebugEnabled()) {
92 logger.debug("Ignored SID: {} {}", type, sid);
93 }
94 return null;
95 }
96
97 protected String createSearchRole(final int type, final String name) {
98 return type + fessConfig.getCanonicalLdapName(name);
99 }
100 }