Mercurial > hg > digilib-old
changeset 71:d493563ef672
New servlet version 1.5b.
Mostly cleanup. Global parameters for digilib now in DigilibConfiguration,
per request parameters are now all in DigilibRequest. The DocuImage implementation
can be selected by the configuration docuimage-class.
Pixel-by-pixel view implemented with "mo=clip".
author | robcast |
---|---|
date | Fri, 24 Jan 2003 21:40:59 +0100 |
parents | a336f89a9fbf |
children | 300d5ba8b33b |
files | servlet/src/digilib/Utils.java servlet/src/digilib/auth/DBAuthOpsImpl.java servlet/src/digilib/auth/dlDataModule.java |
diffstat | 3 files changed, 1 insertions(+), 193 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/Utils.java Wed Jan 08 18:58:09 2003 +0100 +++ b/servlet/src/digilib/Utils.java Fri Jan 24 21:40:59 2003 +0100 @@ -42,7 +42,7 @@ * dprintln(1, "blabla"); * will be printed on stdout if debug >= 1 */ - public static void dprintln(int dbg, String s) { + public void dprintln(int dbg, String s) { if (debugLevel >= dbg) { String ind = ""; // indent by debuglevel
--- a/servlet/src/digilib/auth/DBAuthOpsImpl.java Wed Jan 08 18:58:09 2003 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -/* DBAuthOpsImpl -- Authentication class using database - - Digital Image Library servlet components - - Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - Please read license.txt for the full details. A copy of the GPL - may be found at http://www.gnu.org/copyleft/lgpl.html - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ - -package digilib.auth; - -import javax.servlet.http.*; -import java.util.*; -import com.borland.dx.dataset.*; - -import digilib.*; - -public class DBAuthOpsImpl implements AuthOps { - - private Utils util = null; - private dlDataModule dlDataModule1; - - public DBAuthOpsImpl() { - util = new Utils(); - dbInit(); - } - - public DBAuthOpsImpl(Utils u) { - util = u; - dbInit(); - } - - void dbInit() { - try { - dlDataModule1 = new dlDataModule(); - dlDataModule1.getAuthPathsQuery().open(); - } - catch(Exception e) { - e.printStackTrace(); - } - } - - public void setUtils(Utils u) { - util = u; - } - - public boolean isAuthRequired(String filepath, HttpServletRequest request) throws AuthOpException { - // check permissions - List rolesRequired = rolesForPath(filepath, request); - return (rolesRequired != null); - } - - public boolean isAuthorized(String filepath, HttpServletRequest request) throws AuthOpException { - List rolesAllowed = rolesForPath(filepath, request); - return isRoleAuthorized(rolesAllowed, request); - }; - - public List rolesForPath(String filepath, HttpServletRequest request) throws AuthOpException { - util.dprintln(4, "rolesForPath ("+filepath+")"); - String p = ""; - List r; - LinkedList roles = new LinkedList(); - - // split path in directories - StringTokenizer path = new StringTokenizer(filepath, "/"); - // walk directories and check with db - while (path.hasMoreTokens()) { - p += "/" + path.nextToken(); - r = dbRolesForPath(p); - if (r != null) { - roles.addAll(r); - } - } - if (roles.size() > 0) { - return roles; - } else { - return null; - } - } - - public boolean isRoleAuthorized(List roles, HttpServletRequest request) { - ListIterator r = roles.listIterator(); - String s = ""; - while (r.hasNext()) { - s = (String)r.next(); - util.dprintln(5, "Testing role: "+s); - if (request.isUserInRole(s)) { - util.dprintln(5, "Role Authorized"); - return true; - } - } - return false; - } - - private List dbRolesForPath(String filepath) throws AuthOpException { - util.dprintln(4, "dbRolesForPath ("+filepath+")"); - - LinkedList roles = new LinkedList(); - DataSet query = dlDataModule1.getAuthPathsQuery(); - if (query == null) { - throw new AuthOpException("Unable to access database!"); - } - // search for PATH_NAME == filepath - DataRow lookupRow = new DataRow(query, "PATH_NAME"); - lookupRow.setString("PATH_NAME", filepath); - - if (query.locate(lookupRow, Locate.FIRST)) { - roles.add(query.getString("ROLE_NAME")); - util.dprintln(5, "role found: "+query.getString("ROLE_NAME")); - // any more matches? - while (query.locate(lookupRow, Locate.NEXT_FAST)) { - roles.add(query.getString("ROLE_NAME")); - util.dprintln(5, "role found: "+query.getString("ROLE_NAME")); - } - } - if (roles.size() > 0) { - return roles; - } else { - return null; - } - } - -}
--- a/servlet/src/digilib/auth/dlDataModule.java Wed Jan 08 18:58:09 2003 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* dlDataModule -- Database access helper class - - Digital Image Library servlet components - - Copyright (C) 2001, 2002 Robert Casties (robcast@mail.berlios.de) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - Please read license.txt for the full details. A copy of the GPL - may be found at http://www.gnu.org/copyleft/lgpl.html - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ - -package digilib.auth; - -import com.borland.dx.dataset.*; -import com.borland.dx.sql.dataset.*; - - -public class dlDataModule implements DataModule { - private static dlDataModule myDM; - Database dlDatabase = new Database(); - QueryDataSet authPathsQuery = new QueryDataSet(); - - public dlDataModule() { - try { - jbInit(); - } - catch(Exception e) { - e.printStackTrace(); - } - } - private void jbInit() throws Exception { - authPathsQuery.setReadOnly(true); - authPathsQuery.setEditable(false); - authPathsQuery.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(dlDatabase, "select * from digilib_paths", null, true, Load.ALL)); - dlDatabase.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:oracle:thin:@penelope.unibe.ch:1521:WTWG", "digilib_auth", "allesmainz", false, "oracle.jdbc.driver.OracleDriver")); - } - public static dlDataModule getDataModule() { - if (myDM == null) { - myDM = new dlDataModule(); - } - return myDM; - } - public com.borland.dx.sql.dataset.Database getDlDatabase() { - return dlDatabase; - } - public com.borland.dx.sql.dataset.QueryDataSet getAuthPathsQuery() { - return authPathsQuery; - } -}