Package org.olat.shibboleth.util

Source Code of org.olat.shibboleth.util.UniqueIdentifierMapper

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.shibboleth.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.olat.core.logging.StartupException;

import com.anthonyeden.lib.config.Configuration;

public class UniqueIdentifierMapper {

  private static final String CONF_UNIQUEIDENTIFIERS_DEFAULT = "Default";
  private static final String CONF_UNIQUEIDENTIFIERS_SITENAME = "siteName";
  private static final String CONF_UNIQUEIDENTIFIERS_ORIGINSITE = "OriginSite";
  private static final String CONF_UNIQUEIDENTIFIERS_UIDATTRIBUTE = "uidAttribute";

  private static String defaultUniqueIdentifier;
  private static Map uniqueIdentifierMap;

  public UniqueIdentifierMapper(Configuration uidConfig) {
    uniqueIdentifierMap = new HashMap();
    Configuration defaultUidConfig = uidConfig.getChild(CONF_UNIQUEIDENTIFIERS_DEFAULT);
    if (defaultUidConfig == null)
      throw new StartupException("Missing default unique identifier. Please fix!");
    defaultUniqueIdentifier = defaultUidConfig.getAttribute(CONF_UNIQUEIDENTIFIERS_UIDATTRIBUTE);
    List originUidConfig = uidConfig.getChildren(CONF_UNIQUEIDENTIFIERS_ORIGINSITE);
    if (originUidConfig != null) { // fetch origin specific uidAttributes
      for (Iterator iter = originUidConfig.iterator(); iter.hasNext();) {
        Configuration originSite = (Configuration) iter.next();
        uniqueIdentifierMap.put(originSite.getAttribute(CONF_UNIQUEIDENTIFIERS_SITENAME), originSite.getAttribute(CONF_UNIQUEIDENTIFIERS_UIDATTRIBUTE));
      }
    }
  }
 
  /**
   * Return the shibboleth attribute name which uniquely identifies a shibboleth identity.
   * @param originSiteName
   * @return unique identifier.
   */
  public String resolveUIDAttribute(String originSiteName) {
    if (originSiteName == null) return defaultUniqueIdentifier;
    else {
      String uidAttr = (String)uniqueIdentifierMap.get(originSiteName);
      return uidAttr == null ? defaultUniqueIdentifier : uidAttr;
    }
  }
 
  public String getDefaultUIDAttribute() {
    return defaultUniqueIdentifier;
  }
 
}
TOP

Related Classes of org.olat.shibboleth.util.UniqueIdentifierMapper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.