ozeigermann 2005/02/09 11:16:28
Modified: wck/src/org/apache/slide/simple/store
WebdavStoreAdapter.java BasicWebdavStore.java
WebdavStoreMacroAdapter.java
wck/src/org/apache/slide/simple/reference
WebdavFileStore.java
Added: wck/src/org/apache/slide/simple/store
BasicWebdavStoreFactory.java
Log:
- Augmented BasicWebdavStore with authentication checking to allow forcing of
(re-)authentication from the store level
- Added option to use a factory for store instance creation
Revision Changes Path
1.4 +80 -19
jakarta-slide/wck/src/org/apache/slide/simple/store/WebdavStoreAdapter.java
Index: WebdavStoreAdapter.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/wck/src/org/apache/slide/simple/store/WebdavStoreAdapter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebdavStoreAdapter.java 5 Feb 2005 09:30:40 -0000 1.3
+++ WebdavStoreAdapter.java 9 Feb 2005 19:16:28 -0000 1.4
@@ -38,6 +38,7 @@
import org.apache.slide.lock.NodeLock;
import org.apache.slide.lock.ObjectLockedException;
import org.apache.slide.security.AccessDeniedException;
+import org.apache.slide.security.UnauthenticatedException;
import org.apache.slide.simple.authentication.JAASLoginModule;
import org.apache.slide.simple.reference.WebdavFileStore;
import org.apache.slide.store.*;
@@ -62,6 +63,7 @@
protected static final String LOG_CHANNEL =
WebdavStoreAdapter.class.getName();
protected static final String CALLBACK_PARAMETER = "callback-store";
+ protected static final String CALLBACK_FACTORY_PARAMETER =
"callback-factory";
protected static final String PROPERTIES_PARAMETER = "store-properties";
@@ -69,9 +71,9 @@
protected Hashtable parameters;
- protected String callBackClassName;
+ protected String callBackFactoryClassName;
- protected Class storeClass;
+ protected BasicWebdavStoreFactory storeFactory;
protected boolean isCopySupported, isMoveSupported, isDeleteSupported;
@@ -81,15 +83,39 @@
ServiceParameterMissingException {
log("setParameters(" + parameters + ")");
this.parameters = parameters;
- callBackClassName = (String) parameters.get(CALLBACK_PARAMETER);
- if (callBackClassName == null) {
- throw new ServiceParameterMissingException(this,
CALLBACK_PARAMETER);
- }
- try {
- storeClass = Class.forName(callBackClassName);
- } catch (Exception e) {
- getLogger().log("Initialize call back store " +
callBackClassName, e, LOG_CHANNEL, Logger.CRITICAL);
- throw new ServiceParameterErrorException(this,
CALLBACK_PARAMETER);
+
+ Class factoryClass;
+
+ String callBackClassName = (String)
parameters.get(CALLBACK_PARAMETER);
+ if (callBackClassName != null) {
+ try {
+ final Class storeClass = Class.forName(callBackClassName);
+ storeFactory = new BasicWebdavStoreFactory() {
+
+ public BasicWebdavStore newInstance() throws Exception {
+ return (BasicWebdavStore) storeClass.newInstance();
+ }
+
+ };
+ } catch (Exception e) {
+ getLogger().log("Initialize call back store " +
callBackClassName, e,
+ LOG_CHANNEL, Logger.CRITICAL);
+ throw new ServiceParameterErrorException(this,
CALLBACK_FACTORY_PARAMETER);
+ }
+
+ } else {
+ callBackFactoryClassName = (String)
parameters.get(CALLBACK_FACTORY_PARAMETER);
+ if (callBackFactoryClassName == null) {
+ throw new ServiceParameterMissingException(this,
CALLBACK_FACTORY_PARAMETER);
+ }
+ try {
+ factoryClass = Class.forName(callBackFactoryClassName);
+ storeFactory = (BasicWebdavStoreFactory)
factoryClass.newInstance();
+ } catch (Exception e) {
+ getLogger().log("Initialize call back store " +
callBackFactoryClassName, e,
+ LOG_CHANNEL, Logger.CRITICAL);
+ throw new ServiceParameterErrorException(this,
CALLBACK_FACTORY_PARAMETER);
+ }
}
}
@@ -337,11 +363,11 @@
Principal principal = null;
if (token != null)
principal = token.getPrincipal();
- return new TransactionId(xid, this, principal, storeClass,
parameters);
+ return new TransactionId(xid, this, principal, storeFactory,
parameters);
}
protected TransactionId createTransactionResource(Uri uri) throws
ServiceAccessException {
- return new TransactionId(null, this,
uri.getToken().getCredentialsToken().getPrincipal(), storeClass,
+ return new TransactionId(null, this,
uri.getToken().getCredentialsToken().getPrincipal(), storeFactory,
parameters);
}
@@ -368,14 +394,16 @@
protected Object connection;
- TransactionId(Xid xid, Service service, Principal principal, Class
storeClass, Hashtable parameters)
+ protected boolean authenticated = false;
+
+ TransactionId(Xid xid, Service service, Principal principal,
BasicWebdavStoreFactory storeFactory, Hashtable parameters)
throws ServiceAccessException {
super(xid);
this.service = service;
this.principal = principal;
readOnly = false;
try {
- store = (BasicWebdavStore) storeClass.newInstance();
+ store = storeFactory.newInstance();
if (store instanceof WebdavStoreLockExtension) {
lockStore = (WebdavStoreLockExtension) store;
}
@@ -465,6 +493,7 @@
public NodeRevisionContent retrieveRevisionContent(Uri uri,
NodeRevisionDescriptor revisionDescriptor)
throws ServiceAccessException, RevisionNotFoundException {
+ checkAuthentication();
if (!objectExists(uri)) {
throw new RevisionNotFoundException(uri.toString(),
revisionDescriptor.getRevisionNumber());
} else {
@@ -489,6 +518,7 @@
public void createRevisionContent(Uri uri, NodeRevisionDescriptor
revisionDescriptor,
NodeRevisionContent revisionContent) throws
ServiceAccessException, RevisionAlreadyExistException {
+ checkAuthentication();
try {
store.createResource(uri.toString());
storeRevisionContent(uri, revisionDescriptor,
revisionContent);
@@ -507,6 +537,7 @@
public void storeRevisionContent(Uri uri, NodeRevisionDescriptor
revisionDescriptor,
NodeRevisionContent revisionContent) throws
ServiceAccessException, RevisionNotFoundException {
+ checkAuthentication();
try {
String contentType = null;
String characterEncoding = null;
@@ -533,10 +564,13 @@
public void removeRevisionContent(Uri uri, NodeRevisionDescriptor
revisionDescriptor)
throws ServiceAccessException {
+ checkAuthentication();
+
// already done in removeObject
}
public ObjectNode retrieveObject(Uri uri) throws
ServiceAccessException, ObjectNotFoundException {
+ checkAuthentication();
if (!objectExists(uri)) {
throw new ObjectNotFoundException(uri.toString());
} else {
@@ -559,12 +593,14 @@
}
public void storeObject(Uri uri, ObjectNode object) throws
ServiceAccessException, ObjectNotFoundException {
+ checkAuthentication();
if (!objectExists(uri))
throw new ObjectNotFoundException(uri);
}
public void createObject(Uri uri, ObjectNode object) throws
ServiceAccessException,
ObjectAlreadyExistsException {
+ checkAuthentication();
try {
if (store.objectExists(uri.toString()))
throw new ObjectAlreadyExistsException(uri.toString());
@@ -579,6 +615,7 @@
}
public void removeObject(Uri uri, ObjectNode object) throws
ServiceAccessException, ObjectNotFoundException {
+ checkAuthentication();
try {
store.removeObject(uri.toString());
} catch (AccessDeniedException e) {
@@ -591,6 +628,7 @@
public NodeRevisionDescriptor retrieveRevisionDescriptor(Uri uri,
NodeRevisionNumber revisionNumber)
throws ServiceAccessException,
RevisionDescriptorNotFoundException {
+ checkAuthentication();
if (!objectExists(uri)) {
throw new
RevisionDescriptorNotFoundException(uri.toString());
} else {
@@ -668,11 +706,13 @@
public void createRevisionDescriptor(Uri uri, NodeRevisionDescriptor
revisionDescriptor)
throws ServiceAccessException {
+ checkAuthentication();
// already done in createObject
}
public void storeRevisionDescriptor(Uri uri, NodeRevisionDescriptor
revisionDescriptor)
throws ServiceAccessException,
RevisionDescriptorNotFoundException {
+ checkAuthentication();
try {
if (toBeCreated.remove(uri.toString())) {
if
(revisionDescriptor.getResourceType().equals(NodeRevisionDescriptor.COLLECTION_TYPE))
{
@@ -746,11 +786,13 @@
}
public void removeRevisionDescriptor(Uri uri, NodeRevisionNumber
revisionNumber) throws ServiceAccessException {
+ checkAuthentication();
// already done in removeObject
}
public NodeRevisionDescriptors retrieveRevisionDescriptors(Uri uri)
throws ServiceAccessException,
RevisionDescriptorNotFoundException {
+ checkAuthentication();
if (!objectExists(uri)) {
throw new
RevisionDescriptorNotFoundException(uri.toString());
} else {
@@ -772,16 +814,20 @@
public void createRevisionDescriptors(Uri uri,
NodeRevisionDescriptors revisionDescriptors)
throws ServiceAccessException {
+ checkAuthentication();
}
public void storeRevisionDescriptors(Uri uri,
NodeRevisionDescriptors revisionDescriptors)
throws ServiceAccessException,
RevisionDescriptorNotFoundException {
+ checkAuthentication();
}
public void removeRevisionDescriptors(Uri uri) throws
ServiceAccessException {
+ checkAuthentication();
}
public void putLock(Uri uri, NodeLock lock) throws
ServiceAccessException {
+ checkAuthentication();
if (lockStore != null) {
String lockId = lock.getLockId();
Date expiration = lock.getExpirationDate();
@@ -798,6 +844,7 @@
}
public void renewLock(Uri uri, NodeLock lock) throws
ServiceAccessException, LockTokenNotFoundException {
+ checkAuthentication();
if (lockStore != null) {
removeLock(uri, lock);
putLock(uri, lock);
@@ -805,6 +852,7 @@
}
public void removeLock(Uri uri, NodeLock lock) throws
ServiceAccessException, LockTokenNotFoundException {
+ checkAuthentication();
if (lockStore != null) {
try {
lockStore.unlockObject(uri.toString(), lock.getLockId());
@@ -815,10 +863,12 @@
}
public void killLock(Uri uri, NodeLock lock) throws
ServiceAccessException, LockTokenNotFoundException {
+ checkAuthentication();
removeLock(uri, lock);
}
public Enumeration enumerateLocks(Uri uri) throws
ServiceAccessException {
+ checkAuthentication();
if (lockStore != null) {
try {
WebdavStoreLockExtension.Lock[] ids =
lockStore.getLockInfo(uri.toString());
@@ -865,6 +915,17 @@
}
}
+ protected void checkAuthentication() throws ServiceAccessException {
+ if (!authenticated) {
+ try {
+ store.checkAuthentication();
+ authenticated = true;
+ } catch (UnauthenticatedException e) {
+ throw new ServiceAccessException(service, e);
+ }
+ }
+ }
+
protected Logger getLogger() {
return service.getLogger();
1.2 +13 -4
jakarta-slide/wck/src/org/apache/slide/simple/store/BasicWebdavStore.java
Index: BasicWebdavStore.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/wck/src/org/apache/slide/simple/store/BasicWebdavStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BasicWebdavStore.java 9 Dec 2004 12:17:09 -0000 1.1
+++ BasicWebdavStore.java 9 Feb 2005 19:16:28 -0000 1.2
@@ -35,6 +35,7 @@
import org.apache.slide.common.ServiceParameterMissingException;
import org.apache.slide.lock.ObjectLockedException;
import org.apache.slide.security.AccessDeniedException;
+import org.apache.slide.security.UnauthenticatedException;
import org.apache.slide.simple.reference.WebdavFileStore;
import org.apache.slide.structure.ObjectAlreadyExistsException;
import org.apache.slide.structure.ObjectNotFoundException;
@@ -132,6 +133,14 @@
throws ServiceAccessException, ServiceParameterErrorException,
ServiceParameterMissingException;
/**
+ * Checks if authentication information passed in [EMAIL PROTECTED]
#begin(Service, Principal, Object, LoggerFacade, Hashtable)}
+ * is valid. If not throws an exception.
+ *
+ * @throws UnauthenticatedException if authentication is not valid
+ */
+ void checkAuthentication() throws UnauthenticatedException;
+
+ /**
* Indicates that all changes done inside this request shall be made
* permanent and any transactions, connections and other temporary
resources
* shall be terminated.
1.2 +11 -11
jakarta-slide/wck/src/org/apache/slide/simple/store/WebdavStoreMacroAdapter.java
Index: WebdavStoreMacroAdapter.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/wck/src/org/apache/slide/simple/store/WebdavStoreMacroAdapter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebdavStoreMacroAdapter.java 9 Dec 2004 12:17:09 -0000 1.1
+++ WebdavStoreMacroAdapter.java 9 Feb 2005 19:16:28 -0000 1.2
@@ -63,13 +63,13 @@
ServiceParameterMissingException {
super.setParameters(parameters);
try {
- Object quickCheckObject = storeClass.newInstance();
+ Object quickCheckObject = storeFactory.newInstance();
isCopySupported = quickCheckObject instanceof
WebdavStoreMacroCopyExtension;
isMoveSupported = quickCheckObject instanceof
WebdavStoreMacroMoveExtension;
isDeleteSupported = quickCheckObject instanceof
WebdavStoreMacroDeleteExtension;
} catch (Exception e) {
- getLogger().log("Initialize call back store " +
callBackClassName, e, LOG_CHANNEL, Logger.CRITICAL);
- throw new ServiceParameterErrorException(this,
CALLBACK_PARAMETER);
+ getLogger().log("Initialize call back store " +
callBackFactoryClassName, e, LOG_CHANNEL, Logger.CRITICAL);
+ throw new ServiceParameterErrorException(this,
CALLBACK_FACTORY_PARAMETER);
}
}
@@ -109,11 +109,11 @@
Principal principal = null;
if (token != null)
principal = token.getPrincipal();
- return new MacroTransactionId(xid, this, principal, storeClass,
parameters);
+ return new MacroTransactionId(xid, this, principal, storeFactory,
parameters);
}
protected TransactionId createTransactionResource(Uri uri) throws
ServiceAccessException {
- return new MacroTransactionId(null, this,
uri.getToken().getCredentialsToken().getPrincipal(), storeClass,
+ return new MacroTransactionId(null, this,
uri.getToken().getCredentialsToken().getPrincipal(), storeFactory,
parameters);
}
@@ -125,9 +125,9 @@
protected WebdavStoreMacroMoveExtension moveStore;
- MacroTransactionId(Xid xid, Service service, Principal principal,
Class storeClass, Hashtable parameters)
+ MacroTransactionId(Xid xid, Service service, Principal principal,
BasicWebdavStoreFactory storeFactory, Hashtable parameters)
throws ServiceAccessException {
- super(xid, service, principal, storeClass, parameters);
+ super(xid, service, principal, storeFactory, parameters);
try {
if (store instanceof WebdavStoreMacroCopyExtension) {
copyStore = (WebdavStoreMacroCopyExtension) store;
1.1
jakarta-slide/wck/src/org/apache/slide/simple/store/BasicWebdavStoreFactory.java
Index: BasicWebdavStoreFactory.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/wck/src/org/apache/slide/simple/store/BasicWebdavStoreFactory.java,v
1.1 2005/02/09 19:16:28 ozeigermann Exp $
* $Revision: 1.1 $
* $Date: 2005/02/09 19:16:28 $
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.simple.store;
/**
* Factory for instances of [EMAIL PROTECTED]
org.apache.slide.simple.store.BasicWebdavStore}. Is used
* by [EMAIL PROTECTED] org.apache.slide.simple.store.WebdavStoreAdapter} to
create a store instance per
* request.
*
* @see org.apache.slide.simple.store.BasicWebdavStore
* @see org.apache.slide.simple.store.WebdavStoreAdapter
*
*/
public interface BasicWebdavStoreFactory
{
/**
* Creates a new instance of [EMAIL PROTECTED]
org.apache.slide.simple.store.BasicWebdavStore}. Will
* be called upon each reques from the WebDAV layer.
*
* @return a new instance of [EMAIL PROTECTED]
org.apache.slide.simple.store.BasicWebdavStore}
* @throws Exception in case anything went wrong
*/
BasicWebdavStore newInstance() throws Exception;
}
1.2 +8 -4
jakarta-slide/wck/src/org/apache/slide/simple/reference/WebdavFileStore.java
Index: WebdavFileStore.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/wck/src/org/apache/slide/simple/reference/WebdavFileStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebdavFileStore.java 9 Dec 2004 12:17:09 -0000 1.1
+++ WebdavFileStore.java 9 Feb 2005 19:16:28 -0000 1.2
@@ -48,6 +48,7 @@
import org.apache.slide.common.ServiceParameterErrorException;
import org.apache.slide.common.ServiceParameterMissingException;
import org.apache.slide.security.AccessDeniedException;
+import org.apache.slide.security.UnauthenticatedException;
import org.apache.slide.simple.store.BasicWebdavStore;
import org.apache.slide.simple.store.WebdavStoreAdapter;
import org.apache.slide.simple.store.WebdavStoreBulkPropertyExtension;
@@ -208,6 +209,9 @@
}
}
+ public void checkAuthentication() throws UnauthenticatedException {
+ }
+
public void commit() throws ServiceAccessException {
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]