wildfly ssl fixes
This commit is contained in:
parent
a180c6b896
commit
bb11165568
4 changed files with 20 additions and 5 deletions
|
@ -242,7 +242,8 @@ public abstract class OAuthRequestAuthenticator {
|
||||||
protected AuthChallenge resolveCode(String code) {
|
protected AuthChallenge resolveCode(String code) {
|
||||||
// abort if not HTTPS
|
// abort if not HTTPS
|
||||||
if (deployment.isSslRequired() && !isRequestSecure()) {
|
if (deployment.isSslRequired() && !isRequestSecure()) {
|
||||||
log.error("SSL is required");
|
|
||||||
|
log.error("Adapter requires SSL. Request: " + facade.getRequest().getURI());
|
||||||
return challenge(403);
|
return challenge(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,12 +51,22 @@ public class ServletKeycloakAuthMech implements AuthenticationMechanism {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServletRequestAuthenticator createRequestAuthenticator(KeycloakDeployment deployment, HttpServerExchange exchange, SecurityContext securityContext, UndertowHttpFacade facade) {
|
protected ServletRequestAuthenticator createRequestAuthenticator(KeycloakDeployment deployment, HttpServerExchange exchange, SecurityContext securityContext, UndertowHttpFacade facade) {
|
||||||
int confidentialPort = 8443;
|
|
||||||
if (portManager != null) confidentialPort = portManager.getConfidentialPort(exchange);
|
int confidentialPort = getConfidentilPort(exchange);
|
||||||
return new ServletRequestAuthenticator(facade, deployment,
|
return new ServletRequestAuthenticator(facade, deployment,
|
||||||
confidentialPort, securityContext, exchange, userSessionManagement);
|
confidentialPort, securityContext, exchange, userSessionManagement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getConfidentilPort(HttpServerExchange exchange) {
|
||||||
|
int confidentialPort = 8443;
|
||||||
|
if (exchange.getRequestScheme().equalsIgnoreCase("HTTPS")) {
|
||||||
|
confidentialPort = exchange.getHostPort();
|
||||||
|
} else if (portManager != null) {
|
||||||
|
confidentialPort = portManager.getConfidentialPort(exchange);
|
||||||
|
}
|
||||||
|
return confidentialPort;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChallengeResult sendChallenge(HttpServerExchange exchange, SecurityContext securityContext) {
|
public ChallengeResult sendChallenge(HttpServerExchange exchange, SecurityContext securityContext) {
|
||||||
AuthChallenge challenge = exchange.getAttachment(KEYCLOAK_CHALLENGE_ATTACHMENT_KEY);
|
AuthChallenge challenge = exchange.getAttachment(KEYCLOAK_CHALLENGE_ATTACHMENT_KEY);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import io.undertow.server.handlers.CookieImpl;
|
||||||
import io.undertow.util.AttachmentKey;
|
import io.undertow.util.AttachmentKey;
|
||||||
import io.undertow.util.Headers;
|
import io.undertow.util.Headers;
|
||||||
import io.undertow.util.HttpString;
|
import io.undertow.util.HttpString;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
import org.keycloak.KeycloakSecurityContext;
|
import org.keycloak.KeycloakSecurityContext;
|
||||||
import org.keycloak.adapters.AuthChallenge;
|
import org.keycloak.adapters.AuthChallenge;
|
||||||
import org.keycloak.adapters.HttpFacade;
|
import org.keycloak.adapters.HttpFacade;
|
||||||
|
@ -24,6 +25,7 @@ import java.util.Map;
|
||||||
* @version $Revision: 1 $
|
* @version $Revision: 1 $
|
||||||
*/
|
*/
|
||||||
public class UndertowHttpFacade implements HttpFacade {
|
public class UndertowHttpFacade implements HttpFacade {
|
||||||
|
private static final Logger log = Logger.getLogger(UndertowHttpFacade.class);
|
||||||
public static final AttachmentKey<KeycloakSecurityContext> KEYCLOAK_SECURITY_CONTEXT_KEY = AttachmentKey.create(KeycloakSecurityContext.class);
|
public static final AttachmentKey<KeycloakSecurityContext> KEYCLOAK_SECURITY_CONTEXT_KEY = AttachmentKey.create(KeycloakSecurityContext.class);
|
||||||
|
|
||||||
protected HttpServerExchange exchange;
|
protected HttpServerExchange exchange;
|
||||||
|
@ -41,7 +43,8 @@ public class UndertowHttpFacade implements HttpFacade {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSecure() {
|
public boolean isSecure() {
|
||||||
return exchange.getProtocol().toString().equalsIgnoreCase("https");
|
String protocol = exchange.getRequestScheme();
|
||||||
|
return protocol.equalsIgnoreCase("https");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,7 +24,8 @@ public class WildflyAuthenticationMechanism extends ServletKeycloakAuthMech {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ServletRequestAuthenticator createRequestAuthenticator(KeycloakDeployment deployment, HttpServerExchange exchange, SecurityContext securityContext, UndertowHttpFacade facade) {
|
protected ServletRequestAuthenticator createRequestAuthenticator(KeycloakDeployment deployment, HttpServerExchange exchange, SecurityContext securityContext, UndertowHttpFacade facade) {
|
||||||
|
int confidentialPort = getConfidentilPort(exchange);
|
||||||
return new WildflyRequestAuthenticator(facade, deployment,
|
return new WildflyRequestAuthenticator(facade, deployment,
|
||||||
portManager.getConfidentialPort(exchange), securityContext, exchange, userSessionManagement);
|
confidentialPort, securityContext, exchange, userSessionManagement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue