01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: generic.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.authentication.sessionvalidators.databasedrivers;
09:
10: import com.uwyn.rife.authentication.SessionAttributes;
11: import com.uwyn.rife.authentication.exceptions.SessionValidatorException;
12: import com.uwyn.rife.authentication.sessionvalidators.DatabaseSessionValidator;
13: import com.uwyn.rife.authentication.sessionvalidators.ProcessSessionValidityBasic;
14: import com.uwyn.rife.config.RifeConfig;
15: import com.uwyn.rife.database.Datasource;
16: import com.uwyn.rife.database.queries.Select;
17:
18: public class generic extends DatabaseSessionValidator {
19: protected Select mCheckValidityNoRole = null;
20: protected Select mCheckValidityNoRoleRestrictHostIp = null;
21: protected Select mCheckValidityRole = null;
22: protected Select mCheckValidityRoleRestrictHostIp = null;
23:
24: public generic(Datasource datasource) {
25: super (datasource);
26:
27: mCheckValidityNoRole = new Select(getDatasource()).from(
28: RifeConfig.Authentication.getTableAuthentication())
29: .field(
30: RifeConfig.Authentication
31: .getTableAuthentication()
32: + ".userId").whereParameter(
33: RifeConfig.Authentication
34: .getTableAuthentication()
35: + ".authId", "=").whereParameterAnd(
36: RifeConfig.Authentication
37: .getTableAuthentication()
38: + ".sessStart", ">");
39:
40: mCheckValidityNoRoleRestrictHostIp = mCheckValidityNoRole
41: .clone().whereParameterAnd(
42: RifeConfig.Authentication
43: .getTableAuthentication()
44: + ".hostIp", "=");
45:
46: mCheckValidityRole = new Select(getDatasource())
47: .from(
48: RifeConfig.Authentication
49: .getTableAuthentication())
50: .join(RifeConfig.Authentication.getTableRoleLink())
51: .join(RifeConfig.Authentication.getTableRole())
52: .field(
53: RifeConfig.Authentication
54: .getTableAuthentication()
55: + ".userId")
56: .whereParameter(
57: RifeConfig.Authentication
58: .getTableAuthentication()
59: + ".authId", "=")
60: .whereParameterAnd(
61: RifeConfig.Authentication
62: .getTableAuthentication()
63: + ".sessStart", ">")
64: .whereAnd(
65: RifeConfig.Authentication
66: .getTableAuthentication()
67: + ".userId = "
68: + RifeConfig.Authentication
69: .getTableRoleLink() + ".userId")
70: .whereParameterAnd(
71: RifeConfig.Authentication.getTableRole()
72: + ".name", "role", "=")
73: .whereAnd(
74: RifeConfig.Authentication.getTableRole()
75: + ".roleId = "
76: + RifeConfig.Authentication
77: .getTableRoleLink() + ".roleId");
78:
79: mCheckValidityRoleRestrictHostIp = mCheckValidityRole.clone()
80: .whereParameterAnd(
81: RifeConfig.Authentication
82: .getTableAuthentication()
83: + ".hostIp", "=");
84: }
85:
86: public int validateSession(String authId, String hostIp,
87: SessionAttributes attributes)
88: throws SessionValidatorException {
89: return _validateSession(mCheckValidityNoRole,
90: mCheckValidityNoRoleRestrictHostIp, mCheckValidityRole,
91: mCheckValidityRoleRestrictHostIp,
92: new ProcessSessionValidityBasic(), authId, hostIp,
93: attributes);
94: }
95: }
|