Repository navigation
more stuff #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
more stuff #3
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| <?xml version="1.0"?> | ||
| <project> | ||
| <parent> | ||
| <artifactId>keycloak-parent</artifactId> | ||
| <groupId>org.keycloak</groupId> | ||
| <version>1.0-alpha-1</version> | ||
| <relativePath>../../../pom.xml</relativePath> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>keycloak-as7-adapter</artifactId> | ||
| <name>Keycloak AS7 Integration</name> | ||
| <description/> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.jboss.logging</groupId> | ||
| <artifactId>jboss-logging</artifactId> | ||
| <version>3.1.2.GA</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.keycloak</groupId> | ||
| <artifactId>keycloak-core</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jboss.resteasy</groupId> | ||
| <artifactId>jose-jwt</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jboss.spec.javax.servlet</groupId> | ||
| <artifactId>jboss-servlet-api_3.0_spec</artifactId> | ||
| <scope>provided</scope> | ||
| <version>1.0.0.Final</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jboss.resteasy</groupId> | ||
| <artifactId>resteasy-jaxrs</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jboss.resteasy</groupId> | ||
| <artifactId>resteasy-client</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.jboss.web</groupId> | ||
| <artifactId>jbossweb</artifactId> | ||
| <version>7.0.17.Final</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jboss.as</groupId> | ||
| <artifactId>jboss-as-web</artifactId> | ||
| <version>7.1.2.Final</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.picketbox</groupId> | ||
| <artifactId>picketbox</artifactId> | ||
| <scope>provided</scope> | ||
| <version>4.0.7.Final</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>1.6</source> | ||
| <target>1.6</target> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
14 changes: 14 additions & 0 deletions
14
integration/as7-eap6/adapter/src/main/java/org/keycloak/adapters/as7/Actions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.keycloak.adapters.as7; | ||
|
|
||
| /** | ||
| * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> | ||
| * @version $Revision: 1 $ | ||
| */ | ||
| public interface Actions | ||
| { | ||
| public static final String J_OAUTH_ADMIN_FORCED_LOGOUT = "j_oauth_admin_forced_logout"; | ||
| public static final String J_OAUTH_LOGOUT = "j_oauth_logout"; | ||
| public static final String J_OAUTH_RESOLVE_ACCESS_CODE = "j_oauth_resolve_access_code"; | ||
| public static final String J_OAUTH_REMOTE_LOGOUT = "j_oauth_remote_logout"; | ||
| public static final String J_OAUTH_TOKEN_GRANT = "j_oauth_token_grant"; | ||
| } |
87 changes: 87 additions & 0 deletions
87
...7-eap6/adapter/src/main/java/org/keycloak/adapters/as7/BearerTokenAuthenticatorValve.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package org.keycloak.adapters.as7; | ||
|
|
||
| import org.apache.catalina.Lifecycle; | ||
| import org.apache.catalina.LifecycleEvent; | ||
| import org.apache.catalina.LifecycleException; | ||
| import org.apache.catalina.LifecycleListener; | ||
| import org.apache.catalina.authenticator.AuthenticatorBase; | ||
| import org.apache.catalina.connector.Request; | ||
| import org.apache.catalina.connector.Response; | ||
| import org.apache.catalina.core.StandardContext; | ||
| import org.apache.catalina.deploy.LoginConfig; | ||
| import org.jboss.logging.Logger; | ||
| import org.keycloak.ResourceMetadata; | ||
| import org.keycloak.adapters.as7.config.ManagedResourceConfig; | ||
| import org.keycloak.adapters.as7.config.ManagedResourceConfigLoader; | ||
| import org.jboss.resteasy.spi.ResteasyProviderFactory; | ||
|
|
||
| import javax.security.auth.login.LoginException; | ||
| import javax.servlet.ServletException; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Uses a configured remote auth server to do Bearer token authentication only. SkeletonKeyTokens are used | ||
| * to provide user data and role mappings. | ||
| * | ||
| * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> | ||
| * @version $Revision: 1 $ | ||
| */ | ||
| public class BearerTokenAuthenticatorValve extends AuthenticatorBase implements LifecycleListener | ||
| { | ||
| private static final Logger log = Logger.getLogger(BearerTokenAuthenticatorValve.class); | ||
| protected ManagedResourceConfig remoteSkeletonKeyConfig; | ||
| protected ResourceMetadata resourceMetadata; | ||
|
|
||
| @Override | ||
| public void start() throws LifecycleException | ||
| { | ||
| super.start(); | ||
| StandardContext standardContext = (StandardContext)context; | ||
| standardContext.addLifecycleListener(this); | ||
| } | ||
|
|
||
| @Override | ||
| public void lifecycleEvent(LifecycleEvent event) | ||
| { | ||
| if (event.getType() == Lifecycle.AFTER_START_EVENT) init(); | ||
| } | ||
|
|
||
| protected void init() | ||
| { | ||
| ManagedResourceConfigLoader managedResourceConfigLoader = new ManagedResourceConfigLoader(context); | ||
| resourceMetadata = managedResourceConfigLoader.getResourceMetadata(); | ||
| remoteSkeletonKeyConfig = managedResourceConfigLoader.getRemoteSkeletonKeyConfig(); | ||
| } | ||
|
|
||
| @Override | ||
| public void invoke(Request request, Response response) throws IOException, ServletException | ||
| { | ||
| try | ||
| { | ||
| super.invoke(request, response); | ||
| } | ||
| finally | ||
| { | ||
| ResteasyProviderFactory.clearContextData(); // to clear push of SkeletonKeySession | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean authenticate(Request request, HttpServletResponse response, LoginConfig config) throws IOException | ||
| { | ||
| try | ||
| { | ||
| CatalinaBearerTokenAuthenticator bearer = new CatalinaBearerTokenAuthenticator(resourceMetadata, !remoteSkeletonKeyConfig.isCancelPropagation(), true); | ||
| if (bearer.login(request, response)) | ||
| { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| catch (LoginException e) | ||
| { | ||
| } | ||
| return false; | ||
| } | ||
| } |
163 changes: 163 additions & 0 deletions
163
...ap6/adapter/src/main/java/org/keycloak/adapters/as7/CatalinaBearerTokenAuthenticator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| package org.keycloak.adapters.as7; | ||
|
|
||
| import org.apache.catalina.connector.Request; | ||
| import org.jboss.logging.Logger; | ||
| import org.keycloak.RSATokenVerifier; | ||
| import org.keycloak.ResourceMetadata; | ||
| import org.keycloak.SkeletonKeyPrincipal; | ||
| import org.keycloak.SkeletonKeySession; | ||
| import org.keycloak.VerificationException; | ||
| import org.keycloak.representations.SkeletonKeyToken; | ||
| import org.jboss.resteasy.spi.ResteasyProviderFactory; | ||
|
|
||
| import javax.security.auth.login.LoginException; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import java.io.IOException; | ||
| import java.security.Principal; | ||
| import java.security.cert.X509Certificate; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> | ||
| * @version $Revision: 1 $ | ||
| */ | ||
| public class CatalinaBearerTokenAuthenticator | ||
| { | ||
| protected ResourceMetadata resourceMetadata; | ||
| protected boolean challenge; | ||
| protected Logger log = Logger.getLogger(CatalinaBearerTokenAuthenticator.class); | ||
| protected String tokenString; | ||
| protected SkeletonKeyToken token; | ||
| private Principal principal; | ||
| protected boolean propagateToken; | ||
|
|
||
| public CatalinaBearerTokenAuthenticator(ResourceMetadata resourceMetadata, boolean propagateToken, boolean challenge) | ||
| { | ||
| this.resourceMetadata = resourceMetadata; | ||
| this.challenge = challenge; | ||
| this.propagateToken = propagateToken; | ||
| } | ||
|
|
||
| public ResourceMetadata getResourceMetadata() | ||
| { | ||
| return resourceMetadata; | ||
| } | ||
|
|
||
| public String getTokenString() | ||
| { | ||
| return tokenString; | ||
| } | ||
|
|
||
| public SkeletonKeyToken getToken() | ||
| { | ||
| return token; | ||
| } | ||
|
|
||
| public Principal getPrincipal() | ||
| { | ||
| return principal; | ||
| } | ||
|
|
||
| public boolean login(Request request, HttpServletResponse response) throws LoginException, IOException | ||
| { | ||
| String authHeader = request.getHeader("Authorization"); | ||
| if (authHeader == null) | ||
| { | ||
| if (challenge) | ||
| { | ||
| challengeResponse(response, null, null); | ||
| return false; | ||
| } | ||
| else | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| String[] split = authHeader.trim().split("\\s+"); | ||
| if (split == null || split.length != 2) challengeResponse(response, null, null); | ||
| if (!split[0].equalsIgnoreCase("Bearer")) challengeResponse(response, null, null); | ||
|
|
||
|
|
||
| tokenString = split[1]; | ||
|
|
||
| try | ||
| { | ||
| token = RSATokenVerifier.verifyToken(tokenString, resourceMetadata); | ||
| } | ||
| catch (VerificationException e) | ||
| { | ||
| log.error("Failed to verify token", e); | ||
| challengeResponse(response, "invalid_token", e.getMessage()); | ||
| } | ||
| boolean verifyCaller = false; | ||
| Set<String> roles = null; | ||
| if (resourceMetadata.getResourceName() != null) | ||
| { | ||
| SkeletonKeyToken.Access access = token.getResourceAccess(resourceMetadata.getResourceName()); | ||
| if (access != null) roles = access.getRoles(); | ||
| verifyCaller = token.isVerifyCaller(resourceMetadata.getResourceName()); | ||
| } | ||
| else | ||
| { | ||
| verifyCaller = token.isVerifyCaller(); | ||
| SkeletonKeyToken.Access access = token.getRealmAccess(); | ||
| if (access != null) roles = access.getRoles(); | ||
| } | ||
| String surrogate = null; | ||
| if (verifyCaller) | ||
| { | ||
| if (token.getTrustedCertificates() == null || token.getTrustedCertificates().size() == 0) | ||
| { | ||
| response.sendError(400); | ||
| throw new LoginException("No trusted certificates in token"); | ||
| } | ||
| // for now, we just make sure JBoss Web did two-way SSL | ||
| // assume JBoss Web verifies the client cert | ||
| X509Certificate[] chain = request.getCertificateChain(); | ||
| if (chain == null || chain.length == 0) | ||
| { | ||
| response.sendError(400); | ||
| throw new LoginException("No certificates provided by jboss web to verify the caller"); | ||
| } | ||
| surrogate = chain[0].getSubjectX500Principal().getName(); | ||
| } | ||
| SkeletonKeyPrincipal skeletonKeyPrincipal = new SkeletonKeyPrincipal(token.getPrincipal(), surrogate); | ||
| principal = new CatalinaSecurityContextHelper().createPrincipal(request.getContext().getRealm(), skeletonKeyPrincipal, roles); | ||
| request.setUserPrincipal(principal); | ||
| request.setAuthType("OAUTH_BEARER"); | ||
| if (propagateToken) | ||
| { | ||
| SkeletonKeySession skSession = new SkeletonKeySession(tokenString, resourceMetadata); | ||
| request.setAttribute(SkeletonKeySession.class.getName(), skSession); | ||
| ResteasyProviderFactory.pushContext(SkeletonKeySession.class, skSession); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
| protected void challengeResponse(HttpServletResponse response, String error, String description) throws LoginException | ||
| { | ||
| StringBuilder header = new StringBuilder("Bearer realm=\""); | ||
| header.append(resourceMetadata.getRealm()).append("\""); | ||
| if (error != null) | ||
| { | ||
| header.append(", error=\"").append(error).append("\""); | ||
| } | ||
| if (description != null) | ||
| { | ||
| header.append(", error_description=\"").append(description).append("\""); | ||
| } | ||
| response.setHeader("WWW-Authenticate", header.toString()); | ||
| try | ||
| { | ||
| response.sendError(401); | ||
| } | ||
| catch (IOException e) | ||
| { | ||
| throw new RuntimeException(e); | ||
| } | ||
| throw new LoginException("Challenged"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.