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.sso;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.codelibs.fess.util.ComponentUtil;
22  import org.lastaflute.web.login.credential.LoginCredential;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  public class SsoManager {
27      private static final Logger logger = LoggerFactory.getLogger(SsoManager.class);
28  
29      protected static final String SSO_TYPE = "sso.type";
30  
31      protected static final String NONE = "none";
32  
33      protected final List<SsoAuthenticator> authenticatorList = new ArrayList<>();
34  
35      public boolean available() {
36          return !NONE.equals(getSsoType());
37      }
38  
39      public LoginCredential getLoginCredential() {
40          if (available()) {
41              final SsoAuthenticator authenticator = ComponentUtil.getComponent(getSsoType() + "Authenticator");
42              return authenticator.getLoginCredential();
43          }
44          return null;
45      }
46  
47      protected String getSsoType() {
48          return ComponentUtil.getFessConfig().getSystemProperty(SSO_TYPE, NONE);
49      }
50  
51      public SsoAuthenticator[] getAuthenticators() {
52          return authenticatorList.toArray(new SsoAuthenticator[authenticatorList.size()]);
53      }
54  
55      public void register(final SsoAuthenticator authenticator) {
56          if (logger.isInfoEnabled()) {
57              logger.info("Load " + authenticator.getClass().getSimpleName());
58          }
59          authenticatorList.add(authenticator);
60      }
61  }