001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.db;
007:
008: import com.sun.portal.search.soif.SOIF;
009:
010: /* XXX should eventually be moved to rdm package */
011: public class SToken {
012:
013: private boolean check_rdfilter = false; /* do result filtering */
014: private boolean check_query = false; /* do query qualification */
015: private boolean check_dbaccess = false; /* do database level security */
016: private String dbname = null;
017: private String pdbname = null;
018: private String vdbname = null;
019: private String readACL = null; /* it will be set by DataSecurityModule and used in RD insert*/
020:
021: private String vdbTagName = "virtual-db";
022: static public String Deliminator = ".";
023:
024: Object ssotoken = null; /* RDM Secuirty Token */
025: Object proxyTokenID = null; /* SSO Token for proxy search */
026: String proxyDN = null; /* DN being proxied searches for */
027:
028: /** Creates new SToken */
029: public SToken() {
030: }
031:
032: /**
033: * Create a search token
034: * @param stoken A native token
035: * @param do_check_rdfilter need a rd level filter
036: * @param do_check_query need a search level security
037: * @deprecated An database level security has been introduced.
038: * @see #SToken(Object, boolean, boolean, boolean)
039: */
040: public SToken(Object stoken, boolean do_check_rdfilter,
041: boolean do_check_query) {
042: ssotoken = stoken;
043: check_rdfilter = do_check_rdfilter;
044: check_query = do_check_query;
045: }
046:
047: /**
048: * Create a search token
049: * @param stoken A native token
050: * @param do_check_rdfilter need a rd level filter
051: * @param do_check_query need a search level security
052: * @param do_check_dbaccess need a database level security
053: */
054: public SToken(Object stoken, boolean do_check_rdfilter,
055: boolean do_check_query, boolean do_check_dbaccess) {
056: ssotoken = stoken;
057: check_rdfilter = do_check_rdfilter;
058: check_query = do_check_query;
059: check_dbaccess = do_check_dbaccess;
060: }
061:
062: public void setDatabaseName(String name) {
063: dbname = name;
064: if (dbname == null) {
065: pdbname = null;
066: vdbname = null;
067: } else {
068: int i = dbname.indexOf(Deliminator);
069: if (i < 0) {
070: pdbname = dbname;
071: vdbname = null;
072: } else {
073: pdbname = dbname.substring(0, i);
074: vdbname = dbname.substring(i + 1);
075: }
076: }
077: }
078:
079: public String getDatabaseName() {
080: return dbname;
081: }
082:
083: public void setCheckSearch(boolean enable) {
084: check_query = enable;
085: }
086:
087: public void setCheckRDFilter(boolean enable) {
088: check_rdfilter = enable;
089: }
090:
091: public void setCheckDatabaseAccess(boolean enable) {
092: check_dbaccess = enable;
093: }
094:
095: public boolean isCheckRDFilter() {
096: return check_rdfilter;
097: }
098:
099: /**
100: *
101: */
102: public boolean isCheckDatabaseAccess() {
103: return this .check_dbaccess;
104: }
105:
106: public boolean isCheckSearch() {
107: return check_query;
108: }
109:
110: public Object getNativeToken() {
111: return ssotoken;
112: }
113:
114: public String getProxyDN() {
115: return proxyDN;
116: }
117:
118: public void setProxyDN(String dn) {
119: proxyDN = dn;
120: }
121:
122: public boolean isProxy() {
123: return (getProxyDN() != null);
124: }
125:
126: /**
127: * Extract the real database name
128: * @return The physicial database name protion,
129: * return the value of defaultDB if not defined.
130: */
131: public String getPhysicalDBName() {
132: return pdbname;
133: }
134:
135: /**
136: * Extract the virtual database name
137: * @return The virtual database name protion,
138: * null if not defined.
139: */
140: public String getVirtualDBName() {
141: return vdbname;
142: }
143:
144: public String getVirtualDBTagName() {
145: return this .vdbTagName;
146: }
147:
148: public String appendVirtualDBQuery(String query) {
149: if (vdbname != null) {
150: return "(" + query + ") <AND> (" + this .vdbTagName
151: + " = \"" + vdbname + "\" <OR> " + this .vdbTagName
152: + " <starts> \"" + vdbname + Deliminator + "\")";
153: }
154: return query;
155: }
156:
157: public SOIF appendVirtualDBTag(SOIF s) {
158: if (vdbname != null) {
159: s.replace(vdbTagName, vdbname);
160: }
161: return s;
162: }
163:
164: public boolean validateVirtualDBTag(SOIF s) {
165: if (vdbname != null) {
166: String v = s.getValue(vdbTagName);
167: if (v == null
168: || !(v.equals(vdbname) || v.startsWith(vdbname
169: + Deliminator))) {
170: return false;
171: }
172: }
173: return true;
174: }
175:
176: public SOIF appendReadAcl(SOIF s) {
177: if (readACL != null) {
178: s.replace("ReadACL", readACL);
179: }
180: return s;
181: }
182:
183: public void setReadAcl(String readacl) {
184: this.readACL = readacl;
185: }
186:
187: }
|