Search in sources :

Example 1 with NullArgumentToken

use of org.structr.common.error.NullArgumentToken in project structr by structr.

the class AbstractNode method setPropertyInternal.

private <T> Object setPropertyInternal(final PropertyKey<T> key, final T value) throws FrameworkException {
    if (key == null) {
        logger.error("Tried to set property with null key (action was denied)");
        throw new FrameworkException(422, "Tried to set property with null key (action was denied)", new NullArgumentToken(getClass().getSimpleName(), base));
    }
    try {
        // check for system properties
        if (key.isSystemInternal() && !internalSystemPropertiesUnlocked) {
            throw new FrameworkException(422, "Property " + key.jsonName() + " is an internal system property", new InternalSystemPropertyToken(getClass().getSimpleName(), key));
        }
        // check for read-only properties
        if ((key.isReadOnly() || key.isWriteOnce()) && !readOnlyPropertiesUnlocked && !securityContext.isSuperUser()) {
            throw new FrameworkException(422, "Property " + key.jsonName() + " is read-only", new ReadOnlyPropertyToken(getClass().getSimpleName(), key));
        }
        return key.setProperty(securityContext, this, value);
    } finally {
        // unconditionally lock read-only properties after every write (attempt) to avoid security problems
        // since we made "unlock_readonly_properties_once" available through scripting
        internalSystemPropertiesUnlocked = false;
        readOnlyPropertiesUnlocked = false;
    }
}
Also used : ReadOnlyPropertyToken(org.structr.common.error.ReadOnlyPropertyToken) FrameworkException(org.structr.common.error.FrameworkException) NullArgumentToken(org.structr.common.error.NullArgumentToken) InternalSystemPropertyToken(org.structr.common.error.InternalSystemPropertyToken)

Example 2 with NullArgumentToken

use of org.structr.common.error.NullArgumentToken in project structr by structr.

the class AbstractRelationship method setProperty.

@Override
public final <T> Object setProperty(final PropertyKey<T> key, final T value) throws FrameworkException {
    if (key == null) {
        logger.error("Tried to set property with null key (action was denied)");
        throw new FrameworkException(422, "Tried to set property with null key (action was denied)", new NullArgumentToken(getClass().getSimpleName(), base));
    }
    try {
        if (dbRelationship != null && dbRelationship.hasProperty(key.dbName())) {
            // check for system properties
            if (key.isSystemInternal() && !internalSystemPropertiesUnlocked) {
                throw new FrameworkException(422, "Property " + key.jsonName() + " is an internal system property", new InternalSystemPropertyToken(getClass().getSimpleName(), key));
            }
            // check for read-only properties
            if ((key.isReadOnly() || key.isWriteOnce()) && !readOnlyPropertiesUnlocked && !securityContext.isSuperUser()) {
                throw new FrameworkException(422, "Property " + key.jsonName() + " is read-only", new ReadOnlyPropertyToken(getClass().getSimpleName(), key));
            }
        }
        return key.setProperty(securityContext, this, value);
    } finally {
        // unconditionally lock read-only properties after every write (attempt) to avoid security problems
        // since we made "unlock_readonly_properties_once" available through scripting
        internalSystemPropertiesUnlocked = false;
        readOnlyPropertiesUnlocked = false;
    }
}
Also used : ReadOnlyPropertyToken(org.structr.common.error.ReadOnlyPropertyToken) FrameworkException(org.structr.common.error.FrameworkException) NullArgumentToken(org.structr.common.error.NullArgumentToken) InternalSystemPropertyToken(org.structr.common.error.InternalSystemPropertyToken)

Aggregations

FrameworkException (org.structr.common.error.FrameworkException)2 InternalSystemPropertyToken (org.structr.common.error.InternalSystemPropertyToken)2 NullArgumentToken (org.structr.common.error.NullArgumentToken)2 ReadOnlyPropertyToken (org.structr.common.error.ReadOnlyPropertyToken)2