001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.security.lifecycle;
009:
010: //base classes
011: import javax.servlet.http.HttpServletRequest;
012:
013: //project specific classes
014: import org.jfolder.common.UnexpectedSystemException;
015: import org.jfolder.common.utils.web.ParameterSet;
016: import org.jfolder.common.utils.xml.LinearXPath;
017: import org.jfolder.config.instance.ConfigInstance;
018: import org.jfolder.config.instance.ConfigInstanceConfig;
019: import org.jfolder.security.model.GroupHolder;
020: import org.jfolder.security.model.SimpleGroupHolder;
021: import org.jfolder.security.model.SimpleUserHolderContext;
022: import org.jfolder.security.model.UserHolderContext;
023: import org.jfolder.services.config.ConfigService;
024: import org.jfolder.services.config.ConfigServiceCaller;
025: import org.jfolder.services.config.ConfigServiceCallerFactory;
026:
027: //other classes
028:
029: public class SecurityLifecycleHelper {
030:
031: private final static LinearXPath XPATH_SECURITY_MANAGER = LinearXPath
032: .r("security").b("manager");
033: //
034: //public final static String JFOLDER_USER = "JFOLDER_USER";
035: public final static String USERNAME = "USERNAME";
036: public final static String PASSWORD = "PASSWORD";
037: public final static String DOMAIN = "DOMAIN";
038: public final static String SECURITY_CLASS = "SECURITY_CLASS";
039:
040: private static SecurityLifecycle cachedUaaac = null;
041: private static long cachedUaaacTime = 0;
042:
043: private final static String DEFAULT_MANAGER = GenericConfigLifecycleSecurityLifecycle.class
044: .getName();
045:
046: private SecurityLifecycleHelper() {
047: }
048:
049: public final static synchronized SecurityLifecycle getSecurityLifecycle() {
050:
051: SecurityLifecycle outValue = null;
052:
053: long delta = System.currentTimeMillis() - cachedUaaacTime;
054: if (cachedUaaac != null) {
055: if (delta > (1000 * 60 * 5)) {
056: outValue = getCachedSecurityLifecycle();
057: cachedUaaac = outValue;
058: cachedUaaacTime = System.currentTimeMillis();
059: } else {
060: outValue = cachedUaaac;
061: }
062: } else {
063: outValue = getCachedSecurityLifecycle();
064: cachedUaaac = outValue;
065: cachedUaaacTime = System.currentTimeMillis();
066: }
067:
068: return outValue;
069: }
070:
071: private final static SecurityLifecycle getCachedSecurityLifecycle() {
072:
073: try {
074: SecurityLifecycle outValue = null;
075:
076: ConfigService cs = ConfigServiceCallerFactory
077: .getConfigService();
078: //ConfigLifecycle cm = ConfigLifecycleFactory.getConfigLifecycle();
079: ConfigInstanceConfig cic = cs
080: .accessConfig(ConfigInstance.SECURITY);
081: String uaaac = cic.getProperty(
082: ConfigInstance.STANDARD_CONTENT,
083: XPATH_SECURITY_MANAGER, DEFAULT_MANAGER);
084: Object o = Class.forName(uaaac.trim()).newInstance();
085: outValue = (SecurityLifecycle) o;
086: //cm.close();
087:
088: return outValue;
089: } catch (ClassNotFoundException cnfe) {
090: throw new UnexpectedSystemException(cnfe);
091: } catch (InstantiationException ie) {
092: throw new UnexpectedSystemException(ie);
093: } catch (IllegalAccessException iae) {
094: throw new UnexpectedSystemException(iae);
095: }
096: }
097:
098: public final static GroupHolder getGroup(String inGroup) {
099:
100: SimpleGroupHolder outValue = null;
101:
102: SecurityLifecycle sl = getSecurityLifecycle();
103: outValue = SimpleGroupHolder.newInstance(inGroup, sl
104: .getSecurityType());
105: //outValue = new GenericGroupHolder(inGroup);
106: //outValue.setSecurityClass(
107: // getSecurityLifecycle().getClass().getName());
108:
109: return outValue;
110: }
111:
112: public final static UserHolderContext getUserHolderContext(
113: HttpServletRequest inRequest, ParameterSet inPs) {
114:
115: SimpleUserHolderContext outValue = new SimpleUserHolderContext();
116:
117: outValue.setRequest(inRequest);
118: outValue.setParameterSet(inPs);
119:
120: return outValue;
121: }
122:
123: public final static SimpleUserHolderContext getUserHolderContext(
124: HttpServletRequest inRequest) {
125:
126: SimpleUserHolderContext outValue = new SimpleUserHolderContext();
127:
128: outValue.setRequest(inRequest);
129:
130: return outValue;
131: }
132:
133: public final static SimpleUserHolderContext getUserHolderContext(
134: String inName, String inSecurityClass) {
135:
136: SimpleUserHolderContext outValue = new SimpleUserHolderContext();
137:
138: outValue.setName(inName);
139: if (inSecurityClass != null) {
140: outValue.setSecurityClass(inSecurityClass);
141: }
142:
143: return outValue;
144: }
145:
146: }
|