001/** 002 * Copyright 2014 Tampere University of Technology, Pori Department 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 core.tut.pori.properties; 017 018import java.util.Properties; 019 020import org.apache.log4j.Logger; 021 022/** 023 * System property file, which contains the default settings for creating nonce (short-lived unique random string). 024 * 025 */ 026public class NonceProperties extends SystemProperty{ 027 /* properties */ 028 private static final String PROPERTY_CORE_PORI_UTILS_NONCE_LENGH = PROPERTY_CORE_PORI_UTILS+".nonce_length"; 029 private static final String PROPERTY_CORE_PORI_UTILS_NONCE_EXPIRES_IN = PROPERTY_CORE_PORI_UTILS+".nonce_expires_in"; 030 private long _nonceExpiresIn = -1; 031 private int _nonceLength = -1; 032 033 @Override 034 public void initialize(Properties properties) throws IllegalArgumentException{ 035 try{ 036 _nonceLength = Integer.parseInt(properties.getProperty(PROPERTY_CORE_PORI_UTILS_NONCE_LENGH)); 037 _nonceExpiresIn = Long.parseLong(properties.getProperty(PROPERTY_CORE_PORI_UTILS_NONCE_EXPIRES_IN)); 038 }catch (NumberFormatException ex){ 039 Logger.getLogger(getClass()).error(ex, ex); 040 throw new IllegalArgumentException("Bad "+PROPERTY_CORE_PORI_UTILS_NONCE_LENGH+" OR "+PROPERTY_CORE_PORI_UTILS_NONCE_EXPIRES_IN); 041 } 042 } 043 044 /** 045 * @return the nonceLength 046 */ 047 public int getNonceLength() { 048 return _nonceLength; 049 } 050 051 /** 052 * @return the maximum time to live for nonce, in ms 053 */ 054 public long getNonceExpiresIn() { 055 return _nonceExpiresIn; 056 } 057}