/*=============================================================================*
* Copyright 2006 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.muse.ws.resource.metadata.impl;
import javax.xml.namespace.QName;
import org.w3c.dom.Element;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
import org.apache.muse.ws.resource.basefaults.BaseFault;
import org.apache.muse.ws.resource.properties.listeners.AbstractChangeApprover;
import org.apache.muse.ws.resource.properties.listeners.PropertyChangeApprover;
import org.apache.muse.ws.resource.properties.set.faults.UnableToModifyResourcePropertyFault;
/**
*
* ExternalChangeApprover is a
* {@linkplain PropertyChangeApprover PropertyChangeApprover} that throws an
* exception if an external client tries to change a read-only property. This
* approver can enforce behavior such as read-only, mutable properties
* (properties that a user cannot change but which change on their own or
* through side effects); it also allows programmers to prevent the
* modification of properties through the generic WS-RP SetResourceProperties.
* <br><br>
* In this class, the concept of "read-only" is meant to imply external
* privileges - it may be the case that internal components can modify the
* property in order to reflect its actual value. An example of such a
* scenario would be free disk space - a user cannot just change the amount
* of free disk space directly, but it will change on its own as a result of
* operations on the file system.
*
* @author Dan Jemiolo (danj)
*
*/
public class ExternalChangeApprover extends AbstractChangeApprover
{
//
// Used to lookup all exception messages
//
private static Messages _MESSAGES =
MessagesFactory.get(ExternalChangeApprover.class);
//
// True if the property is read-only for EXTERNAL clients
//
private boolean _isReadOnly;
/**
*
* Creates a new approver for the property with the given name. The
* approver will throw an exception if the second parameter is "true"
* and the change request comes from an external client.
*
* @param qname
* The name of the property to monitor.
*
* @param isReadOnly
* True if the property cannot be modified by external clients.
*
*/
public ExternalChangeApprover(QName qname, boolean isReadOnly)
{
super(qname);
_isReadOnly = isReadOnly;
}
/**
*
* @return True if the property being monitored cannot be changed by
* external clients.
*
*/
public boolean isReadOnly()
{
return _isReadOnly;
}
/**
*
* Throws an exception if the property is read-only <b>and</b> the given
* security token does not match the one held by the approver.
*
*/
public void validateChange(Element oldValue, Element newValue, Object token)
throws BaseFault
{
if (isReadOnly() && !isSecure(token))
{
Object[] filler = { getPropertyName() };
throw new UnableToModifyResourcePropertyFault(_MESSAGES.get("NoExternalChanges", filler));
}
}
}