View Javadoc
1   /*
2    * Copyright 2012-2019 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.helper;
17  
18  import javax.annotation.PostConstruct;
19  
20  import org.codelibs.fess.mylasta.direction.FessConfig;
21  import org.codelibs.fess.util.ComponentUtil;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import jcifs.SID;
26  
27  public class SambaHelper {
28  
29      private static final Logger logger = LoggerFactory.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          fessConfig = ComponentUtil.getFessConfig();
54      }
55  
56      public String getAccountId(final SID sid) {
57          final int type = sid.getType();
58          if (logger.isDebugEnabled()) {
59              try {
60                  logger.debug("Processing SID: {} {} {}", type, sid, sid.toDisplayString());
61              } catch (final Exception e) {
62                  // ignore
63              }
64          }
65          final Integer id = fessConfig.getAvailableSmbSidType(type);
66          if (id != null) {
67              return createSearchRole(id, sid.getAccountName());
68          } else if (logger.isDebugEnabled()) {
69              logger.debug("Ignored SID: {} {}", type, sid);
70          }
71          return null;
72      }
73  
74      public String getAccountId(final jcifs.smb1.smb1.SID sid) {
75          final int type = sid.getType();
76          if (logger.isDebugEnabled()) {
77              try {
78                  logger.debug("Processing SID: {} {} {}", type, sid, sid.toDisplayString());
79              } catch (Exception e) {
80                  // ignore
81              }
82          }
83          final Integer id = fessConfig.getAvailableSmbSidType(type);
84          if (id != null) {
85              return createSearchRole(id, sid.getAccountName());
86          } else if (logger.isDebugEnabled()) {
87              logger.debug("Ignored SID: {} {}", type, sid);
88          }
89          return null;
90      }
91  
92      protected String createSearchRole(final int type, final String name) {
93          return type + fessConfig.getCanonicalLdapName(name);
94      }
95  }