Expurgate vestiges of superannuated flow hierarchy

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135407546
This commit is contained in:
mcilwain 2016-10-06 14:46:31 -07:00 committed by Ben McIlwain
parent 179bd22531
commit 43c67403fa
6 changed files with 2 additions and 296 deletions

View file

@ -1,43 +0,0 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// 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 google.registry.flows;
import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
import google.registry.model.EppResource;
import google.registry.model.eppinput.ResourceCommand.SingleResourceCommand;
/**
* An EPP flow that mutates a single stored resource that is owned by the current registrar.
*
* @param <R> the resource type being changed
* @param <C> the command type, marshalled directly from the epp xml
*/
public abstract class OwnedResourceMutateFlow
<R extends EppResource, C extends SingleResourceCommand>
extends ResourceMutateFlow<R, C> {
/** Fail if the object doesn't exist or was deleted. */
@Override
protected final void verifyMutationAllowed() throws EppException {
if (!isSuperuser) {
verifyResourceOwnership(getClientId(), existingResource);
}
verifyMutationOnOwnedResourceAllowed();
}
/** Check invariants before allowing the command to proceed. */
@SuppressWarnings("unused")
protected void verifyMutationOnOwnedResourceAllowed() throws EppException {}
}

View file

@ -1,64 +0,0 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// 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 google.registry.flows;
import static google.registry.flows.ResourceFlowUtils.verifyAuthInfoForResource;
import google.registry.flows.EppException.ObjectDoesNotExistException;
import google.registry.model.EppResource;
import google.registry.model.eppinput.ResourceCommand.SingleResourceCommand;
import google.registry.util.TypeUtils.TypeInstantiator;
/**
* An EPP flow that mutates a single stored resource.
*
* @param <R> the resource type being changed
* @param <C> the command type, marshalled directly from the epp xml
*/
public abstract class ResourceMutateFlow<R extends EppResource, C extends SingleResourceCommand>
extends ResourceCreateOrMutateFlow<R, C> {
@Override
protected void initRepoId() {
// existingResource could be null here if the flow is being called to mutate a resource that
// does not exist, in which case don't throw NPE here and allow the non-existence to be handled
// later.
repoId = (existingResource == null) ? null : existingResource.getRepoId();
}
/** Fail if the object doesn't exist or was deleted. */
@Override
protected final void verifyIsAllowed() throws EppException {
if (existingResource == null) {
throw new ResourceDoesNotExistException(
new TypeInstantiator<R>(getClass()){}.getExactType(), targetId);
}
if (command.getAuthInfo() != null) {
verifyAuthInfoForResource(command.getAuthInfo(), existingResource);
}
verifyMutationAllowed();
}
/** Check invariants before allowing the command to proceed. */
@SuppressWarnings("unused")
protected void verifyMutationAllowed() throws EppException {}
/** Resource with this id does not exist. */
public static class ResourceDoesNotExistException extends ObjectDoesNotExistException {
public ResourceDoesNotExistException(Class<?> type, String targetId) {
super(type, targetId);
}
}
}

View file

@ -1,55 +0,0 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// 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 google.registry.flows;
import static google.registry.flows.ResourceFlowUtils.verifyAuthInfoForResource;
import google.registry.flows.EppException.ObjectDoesNotExistException;
import google.registry.model.EppResource;
import google.registry.model.eppinput.ResourceCommand.SingleResourceCommand;
import google.registry.util.TypeUtils.TypeInstantiator;
/**
* An EPP flow that queries a storable resource.
*
* @param <R> the resource type being queried
* @param <C> the command type, marshalled directly from the epp xml
*/
public abstract class ResourceQueryFlow<R extends EppResource, C extends SingleResourceCommand>
extends SingleResourceFlow<R, C> {
/** Fail if the object doesn't exist or was deleted. */
@Override
protected final void verifyIsAllowed() throws EppException {
if (existingResource == null) {
throw new ResourceDoesNotExistException(
new TypeInstantiator<R>(getClass()){}.getExactType(), targetId);
}
if (command.getAuthInfo() != null) {
verifyAuthInfoForResource(command.getAuthInfo(), existingResource);
}
verifyQueryIsAllowed();
}
/** Check command- and resource-specific invariants before allowing the query to proceed. */
@SuppressWarnings("unused")
protected void verifyQueryIsAllowed() throws EppException {}
/** Resource with this id does not exist. */
public static class ResourceDoesNotExistException extends ObjectDoesNotExistException {
public ResourceDoesNotExistException(Class<?> type, String targetId) {
super(type, targetId);
}
}
}

View file

@ -1,132 +0,0 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// 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 google.registry.flows;
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import google.registry.flows.EppException.ParameterValuePolicyErrorException;
import google.registry.flows.EppException.ParameterValueRangeErrorException;
import google.registry.flows.EppException.StatusProhibitsOperationException;
import google.registry.model.EppResource;
import google.registry.model.EppResource.Builder;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppinput.ResourceCommand.AddRemoveSameValueException;
import google.registry.model.eppinput.ResourceCommand.ResourceUpdate;
import google.registry.model.eppoutput.EppOutput;
import java.util.Set;
/**
* An EPP flow that mutates a single stored resource.
*
* @param <R> the resource type being changed
* @param <B> a builder for the resource
* @param <C> the command type, marshalled directly from the epp xml
*/
public abstract class ResourceUpdateFlow
<R extends EppResource, B extends Builder<R, ?>, C extends ResourceUpdate<?, ? super B, ?>>
extends OwnedResourceMutateFlow<R, C> {
/**
* Note that CLIENT_UPDATE_PROHIBITED is intentionally not in this list. This is because it
* requires special checking, since you must be able to clear the status off the object with an
* update.
*/
private static final Set<StatusValue> UPDATE_DISALLOWED_STATUSES = ImmutableSet.of(
StatusValue.PENDING_DELETE,
StatusValue.SERVER_UPDATE_PROHIBITED);
@Override
protected Set<StatusValue> getDisallowedStatuses() {
return UPDATE_DISALLOWED_STATUSES;
}
@Override
protected final void verifyMutationOnOwnedResourceAllowed() throws EppException {
for (StatusValue statusValue : Sets.union(
command.getInnerAdd().getStatusValues(),
command.getInnerRemove().getStatusValues())) {
if (!isSuperuser && !statusValue.isClientSettable()) { // The superuser can set any status.
throw new StatusNotClientSettableException(statusValue.getXmlName());
}
}
verifyUpdateIsAllowed();
}
@Override
protected final R createOrMutateResource() throws EppException {
@SuppressWarnings("unchecked")
B builder = (B) existingResource.asBuilder();
try {
command.applyTo(builder);
} catch (AddRemoveSameValueException e) {
throw new AddRemoveSameValueEppException();
}
builder.setLastEppUpdateTime(now).setLastEppUpdateClientId(getClientId());
return setUpdateProperties(builder).build();
}
@Override
protected final void verifyNewStateIsAllowed() throws EppException {
// If the resource is marked with clientUpdateProhibited, and this update did not clear that
// status, then the update must be disallowed (unless a superuser is requesting the change).
if (!isSuperuser
&& existingResource.getStatusValues().contains(StatusValue.CLIENT_UPDATE_PROHIBITED)
&& newResource.getStatusValues().contains(StatusValue.CLIENT_UPDATE_PROHIBITED)) {
throw new ResourceHasClientUpdateProhibitedException();
}
verifyNewUpdatedStateIsAllowed();
}
/** Subclasses may override this to do more specific checks on the new state after the update. */
@SuppressWarnings("unused")
protected void verifyNewUpdatedStateIsAllowed() throws EppException {}
@SuppressWarnings("unused")
protected void verifyUpdateIsAllowed() throws EppException {}
@SuppressWarnings("unused")
protected B setUpdateProperties(B builder) throws EppException {
return builder;
}
@Override
protected final EppOutput getOutput() {
return createOutput(SUCCESS);
}
/** The specified status value cannot be set by clients. */
public static class StatusNotClientSettableException extends ParameterValueRangeErrorException {
public StatusNotClientSettableException(String statusValue) {
super(String.format("Status value %s cannot be set by clients", statusValue));
}
}
/** This resource has clientUpdateProhibited on it, and the update does not clear that status. */
public static class ResourceHasClientUpdateProhibitedException
extends StatusProhibitsOperationException {
public ResourceHasClientUpdateProhibitedException() {
super("Operation disallowed by status: clientUpdateProhibited");
}
}
/** Cannot add and remove the same value. */
public static class AddRemoveSameValueEppException extends ParameterValuePolicyErrorException {
public AddRemoveSameValueEppException() {
super("Cannot add and remove the same value");
}
}
}

View file

@ -25,7 +25,7 @@ import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.ResourceMutateFlow.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainCommand.Create;
import google.registry.model.domain.DomainResource;

View file

@ -26,7 +26,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Range;
import com.googlecode.objectify.Key;
import google.registry.flows.ResourceMutateFlow.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.TestExtraLogicManager;