forked from jbufu/openid4java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenID4JavaUtils.java
More file actions
89 lines (79 loc) · 2.23 KB
/
OpenID4JavaUtils.java
File metadata and controls
89 lines (79 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright 2006-2008 Sxip Identity Corporation
*/
package org.openid4java.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openid4java.OpenIDException;
/**
* Load properties from classpath:<code>org.openid4java.util.openid4java-default.properties</code>,
* then load custom properties from classpath:<code>openid4java.properties</code>
* to replace the default if exists..
*
* @author Sutra Zhou
*
*/
public class OpenID4JavaUtils
{
private static Log _log = LogFactory.getLog(OpenID4JavaUtils.class);
private static final Properties _appProperties;
static
{
// Load default properties first, then use custom properties to replace
// the default.
_appProperties = new Properties();
_appProperties.putAll(loadProperties("openid4java-default.properties"));
Properties custom = loadProperties("/openid4java.properties");
if (custom != null)
{
_appProperties.putAll(custom);
}
}
private static Properties loadProperties(String name)
{
Properties p = null;
InputStream is = OpenIDException.class.getResourceAsStream(name);
if (is != null)
{
p = new Properties();
try
{
p.load(is);
}
catch (IOException e)
{
_log.error("Load properties from " + name + " failed.", e);
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
_log.warn("Error closing resource stream.", e);
}
}
}
else
{
_log.debug("Resource " + name + " not found.");
}
return p;
}
public static String getProperty(String key)
{
return _appProperties.getProperty(key);
}
public static String getProperty(String key, String defaultValue)
{
return _appProperties.getProperty(key, defaultValue);
}
private OpenID4JavaUtils()
{
}
}