001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nelson Silva <nelson.silva@inevo.pt>
016 */
017
018package org.nuxeo.ecm.platform.auth.saml;
019
020import org.opensaml.saml2.core.Attribute;
021import org.opensaml.saml2.core.NameID;
022
023import java.io.Serializable;
024import java.util.List;
025
026/**
027 * @since 6.0
028 */
029public class SAMLCredential {
030    private final NameID nameID;
031
032    private final List<String> sessionIndexes;
033
034    private String remoteEntityID;
035
036    private String relayState;
037
038    private List<Attribute> attributes;
039
040    private String localEntityID;
041
042    private Serializable additionalData;
043
044    public SAMLCredential(NameID nameID, List<String> sessionIndexes) {
045        this.nameID = nameID;
046        this.sessionIndexes = sessionIndexes;
047    }
048
049    public SAMLCredential(NameID nameID, List<String> sessionIndexes, String remoteEntityID, String relayState,
050            List<Attribute> attributes, String localEntityID, Serializable additionalData) {
051        this.nameID = nameID;
052        this.sessionIndexes = sessionIndexes;
053        this.remoteEntityID = remoteEntityID;
054        this.relayState = relayState;
055        this.attributes = attributes;
056        this.localEntityID = localEntityID;
057        this.additionalData = additionalData;
058    }
059
060    public NameID getNameID() {
061        return nameID;
062    }
063
064    public List<String> getSessionIndexes() {
065        return sessionIndexes;
066    }
067
068    public String getRemoteEntityID() {
069        return remoteEntityID;
070    }
071
072    public Attribute getAttributeByName(String name) {
073        for (Attribute attribute : getAttributes()) {
074            if (name.equalsIgnoreCase(attribute.getName())) {
075                return attribute;
076            }
077        }
078        return null;
079    }
080
081    public List<Attribute> getAttributes() {
082        return attributes;
083    }
084
085    public String getRelayState() {
086        return relayState;
087    }
088
089    public String getLocalEntityID() {
090        return localEntityID;
091    }
092
093    public Serializable getAdditionalData() {
094        return additionalData;
095    }
096}