/* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.id.data; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map.Entry; import java.util.Set; import org.opensaml.common.xml.SAMLConstants; import org.opensaml.saml2.core.NameID; import org.opensaml.saml2.metadata.SingleLogoutService; import at.gv.egovernment.moa.id.commons.db.dao.session.InterfederationSessionStore; import at.gv.egovernment.moa.id.commons.db.dao.session.OASessionStore; import at.gv.egovernment.moa.id.protocols.pvp2x.PVP2XProtocol; import at.gv.egovernment.moa.id.protocols.pvp2x.PVPTargetConfiguration; import at.gv.egovernment.moa.id.protocols.pvp2x.builder.SingleLogOutBuilder; import at.gv.egovernment.moa.id.protocols.pvp2x.exceptions.NOSLOServiceDescriptorException; /** * @author tlenz * */ public class SLOInformationContainer implements Serializable { private static final long serialVersionUID = 7148730740582881862L; private PVPTargetConfiguration sloRequest = null; private LinkedHashMap activeFrontChannalOAs = null; private LinkedHashMap activeBackChannelOAs = null; private List sloFailedOAs = null; public void parseActiveOAs(List dbOAs, String removeOAID) { if (activeBackChannelOAs == null) activeBackChannelOAs = new LinkedHashMap(); if (activeFrontChannalOAs == null) activeFrontChannalOAs = new LinkedHashMap(); if (dbOAs != null) { for (OASessionStore oa : dbOAs) { if (!oa.getOaurlprefix().equals(removeOAID)) { //Actually only PVP 2.1 support Single LogOut if (PVP2XProtocol.PATH.equals(oa.getProtocolType())) { SingleLogoutService sloDesc; try { sloDesc = SingleLogOutBuilder.getRequestSLODescriptor(oa.getOaurlprefix()); if (sloDesc.getBinding().equals(SAMLConstants.SAML2_SOAP11_BINDING_URI)) activeBackChannelOAs.put(oa.getOaurlprefix(), new SLOInformationImpl( oa.getAuthURL(), oa.getAssertionSessionID(), oa.getUserNameID(), oa.getUserNameIDFormat(), oa.getProtocolType(), sloDesc)); else activeFrontChannalOAs.put(oa.getOaurlprefix(), new SLOInformationImpl( oa.getAuthURL(), oa.getAssertionSessionID(), oa.getUserNameID(), oa.getUserNameIDFormat(), oa.getProtocolType(), sloDesc)); } catch (NOSLOServiceDescriptorException e) { putFailedOA(oa.getOaurlprefix()); } } else putFailedOA(oa.getOaurlprefix()); } } } } /** * @param dbIDPs * @param value */ public void parseActiveIDPs(List dbIDPs, String removeIDP) { if (activeBackChannelOAs == null) activeBackChannelOAs = new LinkedHashMap(); if (activeFrontChannalOAs == null) activeFrontChannalOAs = new LinkedHashMap(); if (dbIDPs != null) { for (InterfederationSessionStore el : dbIDPs) { if (!el.getIdpurlprefix().equals(removeIDP)) { SingleLogoutService sloDesc; try { sloDesc = SingleLogOutBuilder.getRequestSLODescriptor(el.getIdpurlprefix()); activeFrontChannalOAs.put(el.getIdpurlprefix(), new SLOInformationImpl( el.getAuthURL(), el.getSessionIndex(), el.getUserNameID(), NameID.TRANSIENT, PVP2XProtocol.PATH, sloDesc)); } catch (NOSLOServiceDescriptorException e) { putFailedOA(el.getIdpurlprefix()); } } } } } public boolean hasFrontChannelOA() { return !activeFrontChannalOAs.isEmpty(); } public Set> getFrontChannelOASessionDescriptions() { return activeFrontChannalOAs.entrySet(); } public void removeFrontChannelOA(String oaID) { activeFrontChannalOAs.remove(oaID); } public Iterator getNextBackChannelOA() { return activeBackChannelOAs.keySet().iterator(); } public SLOInformationImpl getBackChannelOASessionDescripten(String oaID) { return activeBackChannelOAs.get(oaID); } public void removeBackChannelOA(String oaID) { activeBackChannelOAs.remove(oaID); } /** * @return the sloRequest */ public PVPTargetConfiguration getSloRequest() { return sloRequest; } /** * @param sloRequest the sloRequest to set */ public void setSloRequest(PVPTargetConfiguration sloRequest) { this.sloRequest = sloRequest; } /** * @return the sloFailedOAs */ public List getSloFailedOAs() { return sloFailedOAs; } public void putFailedOA(String oaID) { if (sloFailedOAs == null) sloFailedOAs = new ArrayList(); sloFailedOAs.add(oaID); } }