// 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 com.google.domain.registry.request; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.net.HttpHeaders.LOCATION; import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8; import static com.google.domain.registry.security.XsrfTokenManager.X_CSRF_TOKEN; import static com.google.domain.registry.security.XsrfTokenManager.validateToken; import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; import static javax.servlet.http.HttpServletResponse.SC_METHOD_NOT_ALLOWED; import static javax.servlet.http.HttpServletResponse.SC_MOVED_TEMPORARILY; import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; import com.google.appengine.api.users.UserService; import com.google.appengine.api.users.UserServiceFactory; import com.google.common.base.Optional; import com.google.domain.registry.util.FormattingLogger; import com.google.domain.registry.util.NonFinalForTesting; import org.joda.time.Duration; import java.io.IOException; import java.lang.reflect.Method; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Dagger request processor for Domain Registry. * *
This class creates an HTTP request processor from a Dagger component. It routes requests from * your servlet to an {@link Action @Action} annotated handler class. * *
Action instances are supplied on a per-request basis by invoking the methods on {@code C}. * For example: *
* {@literal @Component} * interface ServerComponent { * HelloAction helloAction(); * }* *
The rules for component methods are as follows: *
XSRF protection is built into this class. It can be enabled or disabled on individual actions * using {@link Action#xsrfProtection() xsrfProtection} setting. * *
This class also enforces the {@link Action#requireLogin() requireLogin} setting.
*
* @param Warning: When using the App Engine platform, you must call
* {@link Method#setAccessible(boolean) setAccessible(true)} on all your component {@link Method}
* instances, from within the same package as the component. This is due to cross-package
* reflection restrictions.
*
* @param methods is the result of calling {@link Class#getMethods()} on {@code component}, which
* are filtered to only include those with no arguments returning a {@link Runnable} with an
* {@link Action} annotation
*/
public static