Skip to content

Commit

Permalink
0003733: Logging for authorization denied
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Sep 21, 2018
1 parent 180c7a6 commit 4826ff4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Expand Up @@ -57,6 +57,7 @@
import org.jumpmind.db.sql.Row;
import org.jumpmind.db.sql.SqlException;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.exception.HttpException;
import org.jumpmind.exception.InvalidRetryException;
import org.jumpmind.exception.IoException;
import org.jumpmind.symmetric.ISymmetricEngine;
Expand Down Expand Up @@ -649,6 +650,8 @@ protected void logOrRethrow(Throwable ex) throws IOException {
throw (AuthenticationException) ex;
} else if (ex instanceof SyncDisabledException) {
throw (SyncDisabledException) ex;
} else if (ex instanceof HttpException) {
throw (HttpException) ex;
} else if (ex instanceof IOException) {
throw (IOException) ex;
} else if (ex instanceof InvalidRetryException) {
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.jumpmind.exception.HttpException;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.symmetric.service.RegistrationNotOpenException;
Expand Down Expand Up @@ -98,8 +99,9 @@ public InputStream openStream() throws IOException {
if (manualRedirects) {
connection = this.openConnectionCheckRedirects(connection);
}

switch (connection.getResponseCode()) {

int code = connection.getResponseCode();
switch (code) {
case WebConstants.REGISTRATION_NOT_OPEN:
throw new RegistrationNotOpenException();
case WebConstants.REGISTRATION_REQUIRED:
Expand All @@ -109,14 +111,18 @@ public InputStream openStream() throws IOException {
case WebConstants.SC_SERVICE_BUSY:
throw new ConnectionRejectedException();
case WebConstants.SC_SERVICE_UNAVAILABLE:
throw new ServiceUnavailableException();
case WebConstants.SC_FORBIDDEN:
throw new ServiceUnavailableException();
// TODO: In 3.10, let's switch from 403 to 659
case WebConstants.SC_FORBIDDEN:
case 403:
throw new AuthenticationException();
case WebConstants.SC_NO_CONTENT:
throw new NoContentException();
default:
is = HttpTransportManager.getInputStreamFrom(connection);
return is;
throw new NoContentException();
case WebConstants.SC_OK:
is = HttpTransportManager.getInputStreamFrom(connection);
return is;
default:
throw new HttpException(code, "Received an unexpected response code of " + code + " from the server");
}
}

Expand Down
Expand Up @@ -290,13 +290,14 @@ private void analyzeResponseCode(int code) throws IOException {
throw new ConnectionRejectedException();
} else if (WebConstants.SC_SERVICE_UNAVAILABLE == code) {
throw new ServiceUnavailableException();
} else if (WebConstants.SC_FORBIDDEN == code) {
} else if (WebConstants.SC_FORBIDDEN == code || code == 403) {
// TODO: In 3.10, let's switch from 403 to 659
throw new AuthenticationException();
} else if (WebConstants.SYNC_DISABLED == code) {
throw new SyncDisabledException();
} else if (WebConstants.REGISTRATION_REQUIRED == code) {
throw new RegistrationRequiredException();
} else if (200 != code) {
} else if (code != WebConstants.SC_OK) {
throw new HttpException(code, "Received an unexpected response code of " + code + " from the server");
}
}
Expand Down
Expand Up @@ -60,6 +60,8 @@ public class WebConstants {
public static final int SC_SERVICE_BUSY = 670;

public static final int SC_NO_CONTENT = 204;

public static final int SC_OK = 200;

public static final String ACK_BATCH_NAME = "batch-";

Expand Down

0 comments on commit 4826ff4

Please sign in to comment.