diff --git a/java/google/registry/flows/OwnedResourceMutateFlow.java b/java/google/registry/flows/OwnedResourceMutateFlow.java deleted file mode 100644 index c6352270b..000000000 --- a/java/google/registry/flows/OwnedResourceMutateFlow.java +++ /dev/null @@ -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 the resource type being changed - * @param the command type, marshalled directly from the epp xml - */ -public abstract class OwnedResourceMutateFlow - - extends ResourceMutateFlow { - /** 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 {} -} diff --git a/java/google/registry/flows/ResourceMutateFlow.java b/java/google/registry/flows/ResourceMutateFlow.java deleted file mode 100644 index cc4a9bdfc..000000000 --- a/java/google/registry/flows/ResourceMutateFlow.java +++ /dev/null @@ -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 the resource type being changed - * @param the command type, marshalled directly from the epp xml - */ -public abstract class ResourceMutateFlow - extends ResourceCreateOrMutateFlow { - - @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(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); - } - } -} diff --git a/java/google/registry/flows/ResourceQueryFlow.java b/java/google/registry/flows/ResourceQueryFlow.java deleted file mode 100644 index 8747823e5..000000000 --- a/java/google/registry/flows/ResourceQueryFlow.java +++ /dev/null @@ -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 the resource type being queried - * @param the command type, marshalled directly from the epp xml - */ -public abstract class ResourceQueryFlow - extends SingleResourceFlow { - /** 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(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); - } - } -} diff --git a/java/google/registry/flows/ResourceUpdateFlow.java b/java/google/registry/flows/ResourceUpdateFlow.java deleted file mode 100644 index e3bac686c..000000000 --- a/java/google/registry/flows/ResourceUpdateFlow.java +++ /dev/null @@ -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 the resource type being changed - * @param a builder for the resource - * @param the command type, marshalled directly from the epp xml - */ -public abstract class ResourceUpdateFlow - , C extends ResourceUpdate> - extends OwnedResourceMutateFlow { - - /** - * 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 UPDATE_DISALLOWED_STATUSES = ImmutableSet.of( - StatusValue.PENDING_DELETE, - StatusValue.SERVER_UPDATE_PROHIBITED); - - @Override - protected Set 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"); - } - } -} diff --git a/java/google/registry/flows/domain/TldSpecificLogicProxy.java b/java/google/registry/flows/domain/TldSpecificLogicProxy.java index aab432831..36aa71d90 100644 --- a/java/google/registry/flows/domain/TldSpecificLogicProxy.java +++ b/java/google/registry/flows/domain/TldSpecificLogicProxy.java @@ -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; diff --git a/javatests/google/registry/flows/domain/TldSpecificLogicProxyTest.java b/javatests/google/registry/flows/domain/TldSpecificLogicProxyTest.java index 04d9cc9ac..d369ac001 100644 --- a/javatests/google/registry/flows/domain/TldSpecificLogicProxyTest.java +++ b/javatests/google/registry/flows/domain/TldSpecificLogicProxyTest.java @@ -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;