001/* 002 * Copyright 2017 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.extrausermgt.authentication.cas; 017 018import java.util.HashMap; 019import java.util.Map; 020 021import org.apache.avalon.framework.component.Component; 022import org.jasig.cas.client.proxy.ProxyGrantingTicketStorage; 023import org.slf4j.LoggerFactory; 024 025import org.ametys.runtime.plugin.component.AbstractLogEnabled; 026 027/** 028 * CAS Proxy Granting Ticket manager, correlating PGTIOU with PGT 029 */ 030public class CasProxyGrantingTicketManager extends AbstractLogEnabled implements ProxyGrantingTicketStorage, Component 031{ 032 /** Avalon role */ 033 public static final String ROLE = CasProxyGrantingTicketManager.class.getName(); 034 035 private static Map<String, String> _internalMap = new HashMap<>(); 036 037 /** 038 * Constructor for the instance not created by Avalon, but by AmetysCas20ProxyReceivingTicketValidationFilter 039 */ 040 public CasProxyGrantingTicketManager() 041 { 042 setLogger(LoggerFactory.getLogger(getClass())); 043 } 044 045 @Override 046 public void save(String proxyGrantingTicketIou, String proxyGrantingTicket) 047 { 048 getLogger().debug("Save proxyGrantingTicket '{}' for proxyGrantingTicketIou '{}'", proxyGrantingTicket, proxyGrantingTicketIou); 049 _internalMap.put(proxyGrantingTicketIou, proxyGrantingTicket); 050 } 051 052 @Override 053 public String retrieve(String proxyGrantingTicketIou) 054 { 055 String proxyGrantingTicket = _internalMap.get(proxyGrantingTicketIou); 056 getLogger().debug("Retrieve proxyGrantingTicket for proxyGrantingTicketIou '{}'. Its returned value is '{}'", proxyGrantingTicketIou, proxyGrantingTicket); 057 return proxyGrantingTicket; 058 } 059 060 @Override 061 public void cleanUp() 062 { 063 getLogger().debug("Cleaning up"); 064 _internalMap.clear(); 065 } 066}