rename some classes
This commit is contained in:
1 parent
4b1fc788cf
commit
9442601e42
37 files changed
+227
-235
No files matched your search
+9
-9
@@ -5,10 +5,10 @@ import io.undertow.server.HttpServerExchange;
|
||||
import io.undertow.util.Headers;
|
||||
import io.undertow.util.StatusCodes;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.SkeletonKeySession;
|
||||
import org.keycloak.KeycloakAuthenticatedSession;
|
||||
import org.keycloak.adapters.AdapterConstants;
|
||||
import org.keycloak.representations.AccessToken;
|
||||
import org.keycloak.representations.adapters.config.AdapterConfig;
|
||||
import org.keycloak.representations.SkeletonKeyToken;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
@@ -38,7 +38,7 @@ public class AuthenticatedActionsHandler implements HttpHandler {
|
||||
@Override
|
||||
public void handleRequest(HttpServerExchange exchange) throws Exception {
|
||||
log.debugv("AuthenticatedActionsValve.invoke {0}", exchange.getRequestURI());
|
||||
SkeletonKeySession session = getSkeletonKeySession(exchange);
|
||||
KeycloakAuthenticatedSession session = getSkeletonKeySession(exchange);
|
||||
if (corsRequest(exchange, session)) return;
|
||||
String requestUri = exchange.getRequestURI();
|
||||
if (requestUri.endsWith(AdapterConstants.K_QUERY_BEARER_TOKEN)) {
|
||||
@@ -48,13 +48,13 @@ public class AuthenticatedActionsHandler implements HttpHandler {
|
||||
next.handleRequest(exchange);
|
||||
}
|
||||
|
||||
public SkeletonKeySession getSkeletonKeySession(HttpServerExchange exchange) {
|
||||
SkeletonKeySession skSession = exchange.getAttachment(KeycloakAuthenticationMechanism.SKELETON_KEY_SESSION_ATTACHMENT_KEY);
|
||||
public KeycloakAuthenticatedSession getSkeletonKeySession(HttpServerExchange exchange) {
|
||||
KeycloakAuthenticatedSession skSession = exchange.getAttachment(KeycloakAuthenticationMechanism.SKELETON_KEY_SESSION_ATTACHMENT_KEY);
|
||||
if (skSession != null) return skSession;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void queryBearerToken(HttpServerExchange exchange, SkeletonKeySession session) throws IOException, ServletException {
|
||||
protected void queryBearerToken(HttpServerExchange exchange, KeycloakAuthenticatedSession session) throws IOException, ServletException {
|
||||
log.debugv("queryBearerToken {0}",exchange.getRequestURI());
|
||||
if (abortTokenResponse(exchange, session)) return;
|
||||
exchange.setResponseCode(StatusCodes.OK);
|
||||
@@ -63,7 +63,7 @@ public class AuthenticatedActionsHandler implements HttpHandler {
|
||||
exchange.endExchange();
|
||||
}
|
||||
|
||||
protected boolean abortTokenResponse(HttpServerExchange exchange, SkeletonKeySession session) throws IOException {
|
||||
protected boolean abortTokenResponse(HttpServerExchange exchange, KeycloakAuthenticatedSession session) throws IOException {
|
||||
if (session == null) {
|
||||
log.debugv("session was null, sending back 401: {0}",exchange.getRequestURI());
|
||||
exchange.setResponseCode(StatusCodes.UNAUTHORIZED);
|
||||
@@ -83,13 +83,13 @@ public class AuthenticatedActionsHandler implements HttpHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean corsRequest(HttpServerExchange exchange, SkeletonKeySession session) throws IOException {
|
||||
protected boolean corsRequest(HttpServerExchange exchange, KeycloakAuthenticatedSession session) throws IOException {
|
||||
if (!adapterConfig.isCors()) return false;
|
||||
log.debugv("CORS enabled + request.getRequestURI()");
|
||||
String origin = exchange.getRequestHeaders().getFirst("Origin");
|
||||
log.debugv("Origin: {0} uri: {1}", origin, exchange.getRequestURI());
|
||||
if (session != null && origin != null) {
|
||||
SkeletonKeyToken token = session.getToken();
|
||||
AccessToken token = session.getToken();
|
||||
Set<String> allowedOrigins = token.getAllowedOrigins();
|
||||
if (log.isDebugEnabled()) {
|
||||
for (String a : allowedOrigins) log.debug(" " + a);
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ import org.jboss.logging.Logger;
|
||||
import org.keycloak.RSATokenVerifier;
|
||||
import org.keycloak.adapters.ResourceMetadata;
|
||||
import org.keycloak.VerificationException;
|
||||
import org.keycloak.representations.SkeletonKeyToken;
|
||||
import org.keycloak.representations.AccessToken;
|
||||
|
||||
import javax.security.cert.X509Certificate;
|
||||
import java.util.HashSet;
|
||||
@@ -26,7 +26,7 @@ public class BearerTokenAuthenticator {
|
||||
protected ResourceMetadata resourceMetadata;
|
||||
protected Logger log = Logger.getLogger(BearerTokenAuthenticator.class);
|
||||
protected String tokenString;
|
||||
protected SkeletonKeyToken token;
|
||||
protected AccessToken token;
|
||||
protected boolean useResourceRoleMappings;
|
||||
protected String surrogate;
|
||||
protected KeycloakChallenge challenge;
|
||||
@@ -48,7 +48,7 @@ public class BearerTokenAuthenticator {
|
||||
return tokenString;
|
||||
}
|
||||
|
||||
public SkeletonKeyToken getToken() {
|
||||
public AccessToken getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -6,12 +6,12 @@ import io.undertow.security.idm.Account;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import io.undertow.util.AttachmentKey;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.KeycloakAuthenticatedSession;
|
||||
import org.keycloak.KeycloakPrincipal;
|
||||
import org.keycloak.adapters.config.RealmConfiguration;
|
||||
import org.keycloak.adapters.ResourceMetadata;
|
||||
import org.keycloak.SkeletonKeyPrincipal;
|
||||
import org.keycloak.SkeletonKeySession;
|
||||
import org.keycloak.representations.AccessToken;
|
||||
import org.keycloak.representations.adapters.config.AdapterConfig;
|
||||
import org.keycloak.representations.SkeletonKeyToken;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Collections;
|
||||
@@ -25,7 +25,7 @@ public class KeycloakAuthenticationMechanism implements AuthenticationMechanism
|
||||
protected Logger log = Logger.getLogger(KeycloakAuthenticationMechanism.class);
|
||||
|
||||
public static final AttachmentKey<KeycloakChallenge> KEYCLOAK_CHALLENGE_ATTACHMENT_KEY = AttachmentKey.create(KeycloakChallenge.class);
|
||||
public static final AttachmentKey<SkeletonKeySession> SKELETON_KEY_SESSION_ATTACHMENT_KEY = AttachmentKey.create(SkeletonKeySession.class);
|
||||
public static final AttachmentKey<KeycloakAuthenticatedSession> SKELETON_KEY_SESSION_ATTACHMENT_KEY = AttachmentKey.create(KeycloakAuthenticatedSession.class);
|
||||
|
||||
protected ResourceMetadata resourceMetadata;
|
||||
protected AdapterConfig adapterConfig;
|
||||
@@ -59,10 +59,10 @@ public class KeycloakAuthenticationMechanism implements AuthenticationMechanism
|
||||
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
|
||||
}
|
||||
else if (outcome == AuthenticationMechanismOutcome.AUTHENTICATED) {
|
||||
final SkeletonKeyToken token = bearer.getToken();
|
||||
final AccessToken token = bearer.getToken();
|
||||
String surrogate = bearer.getSurrogate();
|
||||
SkeletonKeySession session = new SkeletonKeySession(bearer.getTokenString(), token, resourceMetadata);
|
||||
SkeletonKeyPrincipal principal = completeAuthentication(securityContext, token, surrogate);
|
||||
KeycloakAuthenticatedSession session = new KeycloakAuthenticatedSession(bearer.getTokenString(), token, resourceMetadata);
|
||||
KeycloakPrincipal principal = completeAuthentication(securityContext, token, surrogate);
|
||||
propagateBearer(exchange, session, principal);
|
||||
return AuthenticationMechanismOutcome.AUTHENTICATED;
|
||||
}
|
||||
@@ -82,8 +82,8 @@ public class KeycloakAuthenticationMechanism implements AuthenticationMechanism
|
||||
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
|
||||
|
||||
}
|
||||
SkeletonKeySession session = new SkeletonKeySession(oauth.getTokenString(), oauth.getToken(), resourceMetadata);
|
||||
SkeletonKeyPrincipal principal = completeAuthentication(securityContext, oauth.getToken(), null);
|
||||
KeycloakAuthenticatedSession session = new KeycloakAuthenticatedSession(oauth.getTokenString(), oauth.getToken(), resourceMetadata);
|
||||
KeycloakPrincipal principal = completeAuthentication(securityContext, oauth.getToken(), null);
|
||||
propagateOauth(exchange, session, principal);
|
||||
log.info("AUTHENTICATED");
|
||||
return AuthenticationMechanismOutcome.AUTHENTICATED;
|
||||
@@ -97,14 +97,14 @@ public class KeycloakAuthenticationMechanism implements AuthenticationMechanism
|
||||
return new BearerTokenAuthenticator(resourceMetadata, adapterConfig.isUseResourceRoleMappings());
|
||||
}
|
||||
|
||||
protected SkeletonKeyPrincipal completeAuthentication(SecurityContext securityContext, SkeletonKeyToken token, String surrogate) {
|
||||
final SkeletonKeyPrincipal skeletonKeyPrincipal = new SkeletonKeyPrincipal(token.getSubject(), surrogate);
|
||||
protected KeycloakPrincipal completeAuthentication(SecurityContext securityContext, AccessToken token, String surrogate) {
|
||||
final KeycloakPrincipal skeletonKeyPrincipal = new KeycloakPrincipal(token.getSubject(), surrogate);
|
||||
Set<String> roles = null;
|
||||
if (adapterConfig.isUseResourceRoleMappings()) {
|
||||
SkeletonKeyToken.Access access = token.getResourceAccess(resourceMetadata.getResourceName());
|
||||
AccessToken.Access access = token.getResourceAccess(resourceMetadata.getResourceName());
|
||||
if (access != null) roles = access.getRoles();
|
||||
} else {
|
||||
SkeletonKeyToken.Access access = token.getRealmAccess();
|
||||
AccessToken.Access access = token.getRealmAccess();
|
||||
if (access != null) roles = access.getRoles();
|
||||
}
|
||||
if (roles == null) roles = Collections.emptySet();
|
||||
@@ -124,12 +124,12 @@ public class KeycloakAuthenticationMechanism implements AuthenticationMechanism
|
||||
return skeletonKeyPrincipal;
|
||||
}
|
||||
|
||||
protected void propagateBearer(HttpServerExchange exchange, SkeletonKeySession session, SkeletonKeyPrincipal principal) {
|
||||
protected void propagateBearer(HttpServerExchange exchange, KeycloakAuthenticatedSession session, KeycloakPrincipal principal) {
|
||||
exchange.putAttachment(SKELETON_KEY_SESSION_ATTACHMENT_KEY, session);
|
||||
|
||||
}
|
||||
|
||||
protected void propagateOauth(HttpServerExchange exchange, SkeletonKeySession session, SkeletonKeyPrincipal principal) {
|
||||
protected void propagateOauth(HttpServerExchange exchange, KeycloakAuthenticatedSession session, KeycloakPrincipal principal) {
|
||||
exchange.putAttachment(SKELETON_KEY_SESSION_ATTACHMENT_KEY, session);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -12,8 +12,8 @@ import org.keycloak.RSATokenVerifier;
|
||||
import org.keycloak.adapters.config.RealmConfiguration;
|
||||
import org.keycloak.VerificationException;
|
||||
import org.keycloak.adapters.TokenGrantRequest;
|
||||
import org.keycloak.representations.AccessToken;
|
||||
import org.keycloak.representations.AccessTokenResponse;
|
||||
import org.keycloak.representations.SkeletonKeyToken;
|
||||
import org.keycloak.util.KeycloakUriBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -31,7 +31,7 @@ public class OAuthAuthenticator {
|
||||
protected RealmConfiguration realmInfo;
|
||||
protected int sslRedirectPort;
|
||||
protected String tokenString;
|
||||
protected SkeletonKeyToken token;
|
||||
protected AccessToken token;
|
||||
protected HttpServerExchange exchange;
|
||||
protected KeycloakChallenge challenge;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class OAuthAuthenticator {
|
||||
return tokenString;
|
||||
}
|
||||
|
||||
public SkeletonKeyToken getToken() {
|
||||
public AccessToken getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -4,7 +4,7 @@ import io.undertow.server.HandlerWrapper;
|
||||
import io.undertow.server.HttpHandler;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import io.undertow.servlet.handlers.ServletRequestContext;
|
||||
import org.keycloak.SkeletonKeySession;
|
||||
import org.keycloak.KeycloakAuthenticatedSession;
|
||||
import org.keycloak.representations.adapters.config.AdapterConfig;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -34,15 +34,15 @@ public class ServletAuthenticatedActionsHandler extends AuthenticatedActionsHand
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkeletonKeySession getSkeletonKeySession(HttpServerExchange exchange) {
|
||||
SkeletonKeySession skSession = super.getSkeletonKeySession(exchange);
|
||||
public KeycloakAuthenticatedSession getSkeletonKeySession(HttpServerExchange exchange) {
|
||||
KeycloakAuthenticatedSession skSession = super.getSkeletonKeySession(exchange);
|
||||
if (skSession != null) return skSession;
|
||||
|
||||
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
|
||||
HttpServletRequest req = (HttpServletRequest) servletRequestContext.getServletRequest();
|
||||
HttpSession session = req.getSession(false);
|
||||
if (session == null) return null;
|
||||
return (SkeletonKeySession)session.getAttribute(SkeletonKeySession.class.getName());
|
||||
return (KeycloakAuthenticatedSession)session.getAttribute(KeycloakAuthenticatedSession.class.getName());
|
||||
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -3,10 +3,10 @@ package org.keycloak.adapters.undertow;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import io.undertow.servlet.api.ConfidentialPortManager;
|
||||
import io.undertow.servlet.handlers.ServletRequestContext;
|
||||
import org.keycloak.SkeletonKeyPrincipal;
|
||||
import org.keycloak.KeycloakAuthenticatedSession;
|
||||
import org.keycloak.KeycloakPrincipal;
|
||||
import org.keycloak.adapters.config.RealmConfiguration;
|
||||
import org.keycloak.adapters.ResourceMetadata;
|
||||
import org.keycloak.SkeletonKeySession;
|
||||
import org.keycloak.representations.adapters.config.AdapterConfig;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -39,21 +39,21 @@ public class ServletKeycloakAuthenticationMechanism extends KeycloakAuthenticati
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void propagateBearer(HttpServerExchange exchange, SkeletonKeySession skSession, SkeletonKeyPrincipal principal) {
|
||||
protected void propagateBearer(HttpServerExchange exchange, KeycloakAuthenticatedSession skSession, KeycloakPrincipal principal) {
|
||||
super.propagateBearer(exchange, skSession, principal);
|
||||
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
|
||||
HttpServletRequest req = (HttpServletRequest) servletRequestContext.getServletRequest();
|
||||
req.setAttribute(SkeletonKeySession.class.getName(), skSession);
|
||||
req.setAttribute(KeycloakAuthenticatedSession.class.getName(), skSession);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void propagateOauth(HttpServerExchange exchange, SkeletonKeySession skSession, SkeletonKeyPrincipal principal) {
|
||||
protected void propagateOauth(HttpServerExchange exchange, KeycloakAuthenticatedSession skSession, KeycloakPrincipal principal) {
|
||||
super.propagateBearer(exchange, skSession, principal);
|
||||
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
|
||||
HttpServletRequest req = (HttpServletRequest) servletRequestContext.getServletRequest();
|
||||
req.setAttribute(SkeletonKeySession.class.getName(), skSession);
|
||||
req.setAttribute(KeycloakAuthenticatedSession.class.getName(), skSession);
|
||||
HttpSession session = req.getSession(true);
|
||||
session.setAttribute(SkeletonKeySession.class.getName(), skSession);
|
||||
session.setAttribute(KeycloakAuthenticatedSession.class.getName(), skSession);
|
||||
userSessionManagement.login(servletRequestContext.getDeployment().getSessionManager(), session, principal.getName());
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -5,7 +5,7 @@ import io.undertow.server.HttpHandler;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import io.undertow.servlet.handlers.ServletRequestContext;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.SkeletonKeySession;
|
||||
import org.keycloak.KeycloakAuthenticatedSession;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
@@ -36,7 +36,7 @@ public class ServletPropagateSessionHandler implements HttpHandler {
|
||||
log.info("handleRequest");
|
||||
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
|
||||
HttpServletRequest req = (HttpServletRequest) servletRequestContext.getServletRequest();
|
||||
SkeletonKeySession skSession = (SkeletonKeySession)req.getAttribute(SkeletonKeySession.class.getName());
|
||||
KeycloakAuthenticatedSession skSession = (KeycloakAuthenticatedSession)req.getAttribute(KeycloakAuthenticatedSession.class.getName());
|
||||
if (skSession != null) {
|
||||
log.info("skSession is in request");
|
||||
next.handleRequest(exchange);
|
||||
@@ -49,14 +49,14 @@ public class ServletPropagateSessionHandler implements HttpHandler {
|
||||
next.handleRequest(exchange);
|
||||
return;
|
||||
}
|
||||
skSession = (SkeletonKeySession)session.getAttribute(SkeletonKeySession.class.getName());
|
||||
skSession = (KeycloakAuthenticatedSession)session.getAttribute(KeycloakAuthenticatedSession.class.getName());
|
||||
if (skSession == null) {
|
||||
log.info("skSession not in http session, nothing to propagate");
|
||||
next.handleRequest(exchange);
|
||||
return;
|
||||
}
|
||||
log.info("propagating");
|
||||
req.setAttribute(SkeletonKeySession.class.getName(), skSession);
|
||||
req.setAttribute(KeycloakAuthenticatedSession.class.getName(), skSession);
|
||||
exchange.putAttachment(KeycloakAuthenticationMechanism.SKELETON_KEY_SESSION_ATTACHMENT_KEY, skSession);
|
||||
next.handleRequest(exchange);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user