Merge pull request #1797 from raehalme/KEYCLOAK-2041
KEYCLOAK-2041 Use sendError instead of setStatus to report errors
This commit is contained in:
commit
ac1baa059f
9 changed files with 55 additions and 20 deletions
|
@ -57,7 +57,7 @@ public class AuthenticatedActionsHandler {
|
|||
protected boolean abortTokenResponse() {
|
||||
if (facade.getSecurityContext() == null) {
|
||||
log.debugv("Not logged in, sending back 401: {0}",facade.getRequest().getURI());
|
||||
facade.getResponse().setStatus(401);
|
||||
facade.getResponse().sendError(401);
|
||||
facade.getResponse().end();
|
||||
return true;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public class AuthenticatedActionsHandler {
|
|||
log.debugv("allowedOrigins did not contain origin");
|
||||
|
||||
}
|
||||
facade.getResponse().setStatus(403);
|
||||
facade.getResponse().sendError(403);
|
||||
facade.getResponse().end();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -174,23 +174,7 @@ public class OAuthRequestAuthenticator {
|
|||
final String state = getStateCode();
|
||||
final String redirect = getRedirectUri(state);
|
||||
if (redirect == null) {
|
||||
return new AuthChallenge() {
|
||||
@Override
|
||||
public boolean challenge(HttpFacade exchange) {
|
||||
exchange.getResponse().setStatus(403);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean errorPage() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResponseCode() {
|
||||
return 403;
|
||||
}
|
||||
};
|
||||
return challenge(403);
|
||||
}
|
||||
return new AuthChallenge() {
|
||||
|
||||
|
@ -283,7 +267,7 @@ public class OAuthRequestAuthenticator {
|
|||
|
||||
@Override
|
||||
public boolean challenge(HttpFacade exchange) {
|
||||
exchange.getResponse().setStatus(code);
|
||||
exchange.getResponse().sendError(code);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -56,6 +56,7 @@ public interface HttpFacade {
|
|||
void resetCookie(String name, String path);
|
||||
void setCookie(String name, String value, String path, String domain, int maxAge, boolean secure, boolean httpOnly);
|
||||
OutputStream getOutputStream();
|
||||
void sendError(int code);
|
||||
void sendError(int code, String message);
|
||||
|
||||
/**
|
||||
|
|
|
@ -132,6 +132,13 @@ public class JaxrsHttpFacade implements OIDCHttpFacade {
|
|||
throw new IllegalStateException("Not supported yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code) {
|
||||
javax.ws.rs.core.Response response = responseBuilder.status(code).build();
|
||||
requestContext.abortWith(response);
|
||||
responseFinished = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code, String message) {
|
||||
javax.ws.rs.core.Response response = responseBuilder.status(code).entity(message).build();
|
||||
|
|
|
@ -170,6 +170,15 @@ public class JettyHttpFacade implements HttpFacade {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code) {
|
||||
try {
|
||||
response.sendError(code);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code, String message) {
|
||||
try {
|
||||
|
|
|
@ -156,6 +156,15 @@ public class ServletHttpFacade implements HttpFacade {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code) {
|
||||
try {
|
||||
response.sendError(code);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code, String message) {
|
||||
try {
|
||||
|
|
|
@ -95,6 +95,15 @@ class WrappedHttpServletResponse implements Response {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code) {
|
||||
try {
|
||||
response.sendError(code);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to set HTTP status", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code, String message) {
|
||||
try {
|
||||
|
|
|
@ -167,6 +167,15 @@ public class CatalinaHttpFacade implements HttpFacade {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code) {
|
||||
try {
|
||||
response.sendError(code);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code, String message) {
|
||||
try {
|
||||
|
@ -176,6 +185,7 @@ public class CatalinaHttpFacade implements HttpFacade {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
ended = true;
|
||||
|
|
|
@ -170,6 +170,12 @@ public class UndertowHttpFacade implements HttpFacade {
|
|||
return exchange.getOutputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code) {
|
||||
exchange.setResponseCode(code);
|
||||
exchange.endExchange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int code, String message) {
|
||||
exchange.setResponseCode(code);
|
||||
|
|
Loading…
Reference in a new issue