/******************************************************************************* * 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.config.auth; import java.util.Date; import at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead; import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils; import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration; import at.gv.egovernment.moa.id.protocols.pvp2x.metadata.MOAMetadataProvider; import at.gv.egovernment.moa.logging.Logger; public class AuthConfigLoader implements Runnable { private static final long INTERVAL = 60; // 60 sec public void run() { while (true) { try { Thread.sleep(INTERVAL * 1000); Logger.info("check for new config."); MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); if (moaidconfig != null) { Date dbdate = moaidconfig.getTimestampItem(); Date pvprefresh = moaidconfig.getPvp2RefreshItem(); Date date = AuthConfigurationProvider.getTimeStamp(); if (dbdate != null && dbdate.after(date)) { AuthConfigurationProvider instance = AuthConfigurationProvider.getInstance(); instance.reloadDataBaseConfig(); } Date pvpdate = MOAMetadataProvider.getTimeStamp(); if (pvprefresh != null && pvpdate != null && pvprefresh.after(pvpdate)) { MOAMetadataProvider.reInitialize(); } } else { Logger.warn("MOA-ID Configuration is actually not found. Reuse old configuration."); } } catch (Throwable e) { Logger.warn("MOA-ID Configuration is actually not loadable. Reuse old configuration.", e); } finally { ConfigurationDBUtils.closeSession(); } } } public static void start() { // start the session cleanup thread Thread configLoader = new Thread(new AuthConfigLoader()); configLoader.setName("ConfigurationLoader"); configLoader.setDaemon(true); configLoader.setPriority(Thread.MIN_PRIORITY); configLoader.start(); } }