mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 20:17:51 +02:00
Refactor SessionMetadata and TransportCredentials toString() methods
This cleanups up the toString() methods of all implementations of these interfaces, as pre-work for adding tests against the legacy logging statement in FlowRunner used for ICANN reporting, so that we can validate against any changes to that log statement in the future. It removes system hash codes since those aren't really safe to rely on in test code and they really don't help with debugging anyway. It also standardizes SessionMetadata.toString() a bit and regroups methods on that interface so all the getters are together. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125686039
This commit is contained in:
parent
84eb3c8666
commit
6fa1c2d91c
6 changed files with 26 additions and 20 deletions
|
@ -15,8 +15,8 @@
|
||||||
package google.registry.flows;
|
package google.registry.flows;
|
||||||
|
|
||||||
import static com.google.appengine.api.users.UserServiceFactory.getUserService;
|
import static com.google.appengine.api.users.UserServiceFactory.getUserService;
|
||||||
|
import static com.google.common.base.MoreObjects.toStringHelper;
|
||||||
import static com.google.common.base.Strings.nullToEmpty;
|
import static com.google.common.base.Strings.nullToEmpty;
|
||||||
import static java.lang.System.identityHashCode;
|
|
||||||
|
|
||||||
import com.google.appengine.api.users.User;
|
import com.google.appengine.api.users.User;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
@ -59,7 +59,9 @@ public class GaeUserCredentials implements TransportCredentials {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("GaeUserCredentials@%s{gaeUser: %s}", identityHashCode(this), gaeUser);
|
return toStringHelper(getClass())
|
||||||
|
.add("gaeUser", gaeUser)
|
||||||
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** User is not logged in as a GAE user. */
|
/** User is not logged in as a GAE user. */
|
||||||
|
|
|
@ -53,6 +53,11 @@ public class HttpSessionMetadata implements SessionMetadata {
|
||||||
return (Set<String>) session.getAttribute(SERVICE_EXTENSIONS);
|
return (Set<String>) session.getAttribute(SERVICE_EXTENSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFailedLoginAttempts() {
|
||||||
|
return Optional.fromNullable((Integer) session.getAttribute(FAILED_LOGIN_ATTEMPTS)).or(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setClientId(String clientId) {
|
public void setClientId(String clientId) {
|
||||||
session.setAttribute(CLIENT_ID, clientId);
|
session.setAttribute(CLIENT_ID, clientId);
|
||||||
|
@ -63,11 +68,6 @@ public class HttpSessionMetadata implements SessionMetadata {
|
||||||
session.setAttribute(SERVICE_EXTENSIONS, serviceExtensionUris);
|
session.setAttribute(SERVICE_EXTENSIONS, serviceExtensionUris);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getFailedLoginAttempts() {
|
|
||||||
return Optional.fromNullable((Integer) session.getAttribute(FAILED_LOGIN_ATTEMPTS)).or(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incrementFailedLoginAttempts() {
|
public void incrementFailedLoginAttempts() {
|
||||||
session.setAttribute(FAILED_LOGIN_ATTEMPTS, getFailedLoginAttempts() + 1);
|
session.setAttribute(FAILED_LOGIN_ATTEMPTS, getFailedLoginAttempts() + 1);
|
||||||
|
@ -81,7 +81,6 @@ public class HttpSessionMetadata implements SessionMetadata {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toStringHelper(getClass())
|
return toStringHelper(getClass())
|
||||||
.add("system hash code", System.identityHashCode(this))
|
|
||||||
.add("clientId", getClientId())
|
.add("clientId", getClientId())
|
||||||
.add("failedLoginAttempts", getFailedLoginAttempts())
|
.add("failedLoginAttempts", getFailedLoginAttempts())
|
||||||
.add("serviceExtensionUris", Joiner.on('.').join(nullToEmpty(getServiceExtensionUris())))
|
.add("serviceExtensionUris", Joiner.on('.').join(nullToEmpty(getServiceExtensionUris())))
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
package google.registry.flows;
|
package google.registry.flows;
|
||||||
|
|
||||||
|
import static com.google.common.base.MoreObjects.toStringHelper;
|
||||||
|
|
||||||
import google.registry.flows.EppException.AuthenticationErrorException;
|
import google.registry.flows.EppException.AuthenticationErrorException;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
|
|
||||||
|
@ -25,4 +27,9 @@ public class PasswordOnlyTransportCredentials implements TransportCredentials {
|
||||||
throw new BadRegistrarPasswordException();
|
throw new BadRegistrarPasswordException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return toStringHelper(getClass()).toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,12 @@ public interface SessionMetadata {
|
||||||
|
|
||||||
Set<String> getServiceExtensionUris();
|
Set<String> getServiceExtensionUris();
|
||||||
|
|
||||||
|
int getFailedLoginAttempts();
|
||||||
|
|
||||||
void setClientId(String clientId);
|
void setClientId(String clientId);
|
||||||
|
|
||||||
void setServiceExtensionUris(Set<String> serviceExtensionUris);
|
void setServiceExtensionUris(Set<String> serviceExtensionUris);
|
||||||
|
|
||||||
int getFailedLoginAttempts();
|
|
||||||
|
|
||||||
void incrementFailedLoginAttempts();
|
void incrementFailedLoginAttempts();
|
||||||
|
|
||||||
void resetFailedLoginAttempts();
|
void resetFailedLoginAttempts();
|
||||||
|
|
|
@ -35,6 +35,11 @@ public class StatelessRequestSessionMetadata implements SessionMetadata {
|
||||||
this.serviceExtensionUris = checkNotNull(serviceExtensionUris);
|
this.serviceExtensionUris = checkNotNull(serviceExtensionUris);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getClientId() {
|
public String getClientId() {
|
||||||
return clientId;
|
return clientId;
|
||||||
|
@ -46,8 +51,8 @@ public class StatelessRequestSessionMetadata implements SessionMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate() {
|
public int getFailedLoginAttempts() {
|
||||||
throw new UnsupportedOperationException();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,11 +65,6 @@ public class StatelessRequestSessionMetadata implements SessionMetadata {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getFailedLoginAttempts() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incrementFailedLoginAttempts() {
|
public void incrementFailedLoginAttempts() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
@ -75,12 +75,11 @@ public class StatelessRequestSessionMetadata implements SessionMetadata {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toStringHelper(getClass())
|
return toStringHelper(getClass())
|
||||||
.add("system hash code", System.identityHashCode(this))
|
|
||||||
.add("clientId", getClientId())
|
.add("clientId", getClientId())
|
||||||
|
.add("failedLoginAttempts", getFailedLoginAttempts())
|
||||||
.add("serviceExtensionUris", Joiner.on('.').join(nullToEmpty(getServiceExtensionUris())))
|
.add("serviceExtensionUris", Joiner.on('.').join(nullToEmpty(getServiceExtensionUris())))
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,6 @@ public class TlsCredentials implements TransportCredentials {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toStringHelper(getClass())
|
return toStringHelper(getClass())
|
||||||
.add("system hash code", System.identityHashCode(this))
|
|
||||||
.add("clientCertificateHash", clientCertificateHash)
|
.add("clientCertificateHash", clientCertificateHash)
|
||||||
.add("clientAddress", clientInetAddr)
|
.add("clientAddress", clientInetAddr)
|
||||||
.add("sni", sni)
|
.add("sni", sni)
|
||||||
|
|
Loading…
Add table
Reference in a new issue