Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.request.Action.Method.DELETE;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.HEAD;
Expand All @@ -36,6 +37,7 @@
import google.registry.config.RegistryConfig;
import google.registry.export.sheet.SyncRegistrarsSheetAction;
import google.registry.model.console.ConsolePermission;
import google.registry.model.console.ConsoleUpdateHistory;
import google.registry.model.console.User;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarPoc;
Expand Down Expand Up @@ -260,6 +262,14 @@ public static EmailInfo create(
}
}

protected void finishAndPersistConsoleUpdateHistory(ConsoleUpdateHistory.Builder<?, ?> builder) {
builder.setActingUser(consoleApiParams.authResult().user().get());
builder.setUrl(consoleApiParams.request().getRequestURI());
builder.setMethod(consoleApiParams.request().getMethod());
builder.setModificationTime(tm().getTransactionTime());
tm().put(builder.build());
}

/** Specialized exception class used for failure when a user doesn't have the right permission. */
private static class ConsolePermissionForbiddenException extends RuntimeException {
private ConsolePermissionForbiddenException(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package google.registry.ui.server.console;

import com.google.gson.Gson;
import google.registry.request.Response;
import google.registry.request.auth.AuthResult;
import google.registry.security.XsrfTokenManager;
Expand All @@ -26,13 +27,16 @@ public record ConsoleApiParams(
Response response,
AuthResult authResult,
SendEmailUtils sendEmailUtils,
XsrfTokenManager xsrfTokenManager) {
XsrfTokenManager xsrfTokenManager,
Gson gson) {
public static ConsoleApiParams create(
HttpServletRequest request,
Response response,
AuthResult authResult,
SendEmailUtils sendEmailUtils,
XsrfTokenManager xsrfTokenManager) {
return new ConsoleApiParams(request, response, authResult, sendEmailUtils, xsrfTokenManager);
XsrfTokenManager xsrfTokenManager,
Gson gson) {
return new ConsoleApiParams(
request, response, authResult, sendEmailUtils, xsrfTokenManager, gson);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import static jakarta.servlet.http.HttpServletResponse.SC_OK;

import com.google.gson.Gson;
import google.registry.model.EppResourceUtils;
import google.registry.model.console.ConsolePermission;
import google.registry.model.console.User;
Expand All @@ -41,17 +40,14 @@ public class ConsoleDomainGetAction extends ConsoleApiAction {

public static final String PATH = "/console-api/domain";

private final Gson gson;
private final String paramDomain;

@Inject
public ConsoleDomainGetAction(
ConsoleApiParams consoleApiParams,
Gson gson,
@Parameter("consoleDomain") String paramDomain) {
super(consoleApiParams);
this.paramDomain = paramDomain;
this.gson = gson;
}

@Override
Expand All @@ -72,6 +68,6 @@ protected void getHandler(User user) {
return;
}
consoleApiParams.response().setStatus(SC_OK);
consoleApiParams.response().setPayload(gson.toJson(domain));
consoleApiParams.response().setPayload(consoleApiParams.gson().toJson(domain));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ascii;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import google.registry.model.CreateAutoTimestamp;
import google.registry.model.console.User;
Expand Down Expand Up @@ -55,7 +54,6 @@ public class ConsoleDomainListAction extends ConsoleApiAction {
private static final String SEARCH_TERM_QUERY = " AND LOWER(domainName) LIKE :searchTerm";
private static final String ORDER_BY_STATEMENT = " ORDER BY creationTime DESC";

private final Gson gson;
private final String registrarId;
private final Optional<DateTime> checkpointTime;
private final int pageNumber;
Expand All @@ -66,15 +64,13 @@ public class ConsoleDomainListAction extends ConsoleApiAction {
@Inject
public ConsoleDomainListAction(
ConsoleApiParams consoleApiParams,
Gson gson,
@Parameter("registrarId") String registrarId,
@Parameter("checkpointTime") Optional<DateTime> checkpointTime,
@Parameter("pageNumber") Optional<Integer> pageNumber,
@Parameter("resultsPerPage") Optional<Integer> resultsPerPage,
@Parameter("totalResults") Optional<Long> totalResults,
@Parameter("searchTerm") Optional<String> searchTerm) {
super(consoleApiParams);
this.gson = gson;
this.registrarId = registrarId;
this.checkpointTime = checkpointTime;
this.pageNumber = pageNumber.orElse(0);
Expand Down Expand Up @@ -120,7 +116,10 @@ private void runInTransaction() {

consoleApiParams
.response()
.setPayload(gson.toJson(new DomainListResult(domains, checkpoint, actualTotalResults)));
.setPayload(
consoleApiParams
.gson()
.toJson(new DomainListResult(domains, checkpoint, actualTotalResults)));
consoleApiParams.response().setStatus(SC_OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.google.gson.annotations.Expose;
import google.registry.flows.EppException.AuthenticationErrorException;
import google.registry.flows.PasswordOnlyTransportCredentials;
import google.registry.model.console.ConsoleUpdateHistory;
import google.registry.model.console.RegistrarUpdateHistory;
import google.registry.model.console.User;
import google.registry.model.registrar.Registrar;
import google.registry.request.Action;
Expand All @@ -53,7 +55,6 @@ public class ConsoleEppPasswordAction extends ConsoleApiAction {
private final PasswordOnlyTransportCredentials credentials =
new PasswordOnlyTransportCredentials();
private final AuthenticatedRegistrarAccessor registrarAccessor;

private final Optional<EppPasswordData> eppPasswordChangeRequest;

@Inject
Expand Down Expand Up @@ -106,6 +107,14 @@ protected void postHandler(User user) {
Registrar updatedRegistrar =
registrar.asBuilder().setPassword(eppRequestBody.newPassword()).build();
tm().put(updatedRegistrar);
EppPasswordData sanitizedData =
new EppPasswordData(
eppRequestBody.registrarId, "********", "••••••••", "••••••••");
finishAndPersistConsoleUpdateHistory(
new RegistrarUpdateHistory.Builder()
.setType(ConsoleUpdateHistory.Type.REGISTRAR_UPDATE)
.setRegistrar(updatedRegistrar)
.setRequestBody(consoleApiParams.gson().toJson(sanitizedData)));
sendExternalUpdates(
ImmutableMap.of("password", new DiffUtils.DiffPair("********", "••••••••")),
registrar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ ConsoleApiParams provideConsoleApiParams(
Response response,
AuthResult authResult,
SendEmailUtils sendEmailUtils,
XsrfTokenManager xsrfTokenManager) {
return ConsoleApiParams.create(request, response, authResult, sendEmailUtils, xsrfTokenManager);
XsrfTokenManager xsrfTokenManager,
Gson gson) {
return ConsoleApiParams.create(
request, response, authResult, sendEmailUtils, xsrfTokenManager, gson);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import google.registry.config.RegistryConfig.Config;
import google.registry.model.OteAccountBuilder;
Expand Down Expand Up @@ -62,7 +61,6 @@ public class ConsoleOteAction extends ConsoleApiAction {
private static final String STAT_TYPE_DESCRIPTION_PARAM = "description";
private static final String STAT_TYPE_REQUIREMENT_PARAM = "requirement";
private static final String STAT_TYPE_TIMES_PERFORMED_PARAM = "timesPerformed";
private final Gson gson;
private final StringGenerator passwordGenerator;
private final Optional<OteCreateData> oteCreateData;
private final Optional<String> maybeGroupEmailAddress;
Expand All @@ -72,14 +70,12 @@ public class ConsoleOteAction extends ConsoleApiAction {
@Inject
public ConsoleOteAction(
ConsoleApiParams consoleApiParams,
Gson gson,
IamClient iamClient,
@Parameter("registrarId") String registrarId, // Get request param
@Config("gSuiteConsoleUserGroupEmailAddress") Optional<String> maybeGroupEmailAddress,
@Named("base58StringGenerator") StringGenerator passwordGenerator,
@Parameter("oteCreateData") Optional<OteCreateData> oteCreateData) {
super(consoleApiParams);
this.gson = gson;
this.passwordGenerator = passwordGenerator;
this.oteCreateData = oteCreateData;
this.maybeGroupEmailAddress = maybeGroupEmailAddress;
Expand Down Expand Up @@ -116,8 +112,13 @@ protected void postHandler(User user) {
consoleApiParams
.response()
.setPayload(
gson.toJson(
ImmutableMap.builder().putAll(registrarIdToTld).put("password", password).build()));
consoleApiParams
.gson()
.toJson(
ImmutableMap.builder()
.putAll(registrarIdToTld)
.put("password", password)
.build()));
}

@Override
Expand Down Expand Up @@ -153,7 +154,7 @@ protected void getHandler(User user) {
convertSingleRequirement(statType, oteStats.getCount(statType)))
.collect(toImmutableList());
consoleApiParams.response().setStatus(SC_OK);
consoleApiParams.response().setPayload(gson.toJson(stats));
consoleApiParams.response().setPayload(consoleApiParams.gson().toJson(stats));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static jakarta.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;

import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import google.registry.flows.EppException;
import google.registry.flows.domain.DomainFlowUtils;
Expand Down Expand Up @@ -72,7 +71,6 @@ public class ConsoleRegistryLockAction extends ConsoleApiAction {

private final DomainLockUtils domainLockUtils;
private final GmailClient gmailClient;
private final Gson gson;
private final Optional<ConsoleRegistryLockPostInput> optionalPostInput;
private final String registrarId;

Expand All @@ -81,22 +79,20 @@ public ConsoleRegistryLockAction(
ConsoleApiParams consoleApiParams,
DomainLockUtils domainLockUtils,
GmailClient gmailClient,
Gson gson,
@Parameter("consoleRegistryLockPostInput")
Optional<ConsoleRegistryLockPostInput> optionalPostInput,
@Parameter("registrarId") String registrarId) {
super(consoleApiParams);
this.domainLockUtils = domainLockUtils;
this.gmailClient = gmailClient;
this.gson = gson;
this.optionalPostInput = optionalPostInput;
this.registrarId = registrarId;
}

@Override
protected void getHandler(User user) {
checkPermission(user, registrarId, ConsolePermission.REGISTRY_LOCK);
consoleApiParams.response().setPayload(gson.toJson(getLockedDomains()));
consoleApiParams.response().setPayload(consoleApiParams.gson().toJson(getLockedDomains()));
consoleApiParams.response().setStatus(SC_OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static google.registry.request.Action.Method.GET;

import com.google.common.base.Ascii;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import google.registry.model.console.User;
import google.registry.model.domain.RegistryLock;
Expand All @@ -42,18 +41,15 @@ public class ConsoleRegistryLockVerifyAction extends ConsoleApiAction {
static final String PATH = "/console-api/registry-lock-verify";

private final DomainLockUtils domainLockUtils;
private final Gson gson;
private final String lockVerificationCode;

@Inject
public ConsoleRegistryLockVerifyAction(
ConsoleApiParams consoleApiParams,
DomainLockUtils domainLockUtils,
Gson gson,
@Parameter("lockVerificationCode") String lockVerificationCode) {
super(consoleApiParams);
this.domainLockUtils = domainLockUtils;
this.gson = gson;
this.lockVerificationCode = lockVerificationCode;
}

Expand All @@ -68,7 +64,7 @@ protected void getHandler(User user) {
RegistryLockVerificationResponse lockResponse =
new RegistryLockVerificationResponse(
Ascii.toLowerCase(action.toString()), lock.getDomainName(), lock.getRegistrarId());
consoleApiParams.response().setPayload(gson.toJson(lockResponse));
consoleApiParams.response().setPayload(consoleApiParams.gson().toJson(lockResponse));
consoleApiParams.response().setStatus(HttpServletResponse.SC_OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import google.registry.model.console.ConsolePermission;
import google.registry.model.console.ConsoleUpdateHistory;
import google.registry.model.console.RegistrarUpdateHistory;
import google.registry.model.console.User;
import google.registry.model.registrar.Registrar;
import google.registry.request.Action;
Expand Down Expand Up @@ -99,6 +101,11 @@ protected void postHandler(User user) {
.build();

tm().put(updatedRegistrar);
finishAndPersistConsoleUpdateHistory(
new RegistrarUpdateHistory.Builder()
.setType(ConsoleUpdateHistory.Type.REGISTRAR_UPDATE)
.setRegistrar(updatedRegistrar)
.setRequestBody(consoleApiParams.gson().toJson(registrarParam)));
sendExternalUpdatesIfNecessary(
EmailInfo.create(
existingRegistrar.get(),
Expand Down
Loading