Skip to content

Commit

Permalink
feat: correct spi implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime1907 authored Jan 18, 2023
1 parent 1f376df commit 57c8644
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ mvn clean verify
```

## Deploy the example
Copy to the `standalone/deployments` directory in Keycloak.
### Wildfly
Copy the `.jar` into the keycloak directory `standalone/deployments`
### Quarkus
Copy the `.jar` into the keycloak directory `providers`

## Routes

Expand Down
9 changes: 1 addition & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
<artifactId>actions-token</artifactId>
<groupId>org.jboss.aerogear</groupId>
<packaging>jar</packaging>
<version>0.0.6</version>
<version>0.0.7</version>

<properties>
<java.version>11</java.version>
<keycloak.version>15.0.2</keycloak.version>
<version.compiler.maven.plugin>3.5.1</version.compiler.maven.plugin>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<lombok.version>1.18.16</lombok.version>
<gson.version>2.9.0</gson.version>
</properties>

Expand All @@ -26,12 +25,6 @@
<version>${gson.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi-private</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache;
import org.keycloak.TokenCategory;
import org.keycloak.authentication.actiontoken.execactions.ExecuteActionsActionToken;
Expand All @@ -44,13 +45,12 @@

import com.google.gson.Gson;

import lombok.extern.jbosslog.JBossLog;

@JBossLog
public class ActionsTokenResource {

private final KeycloakSession session;

private final static Logger logger = Logger.getLogger(ActionsTokenResource.class);

private AdminPermissionEvaluator realmAuth;

public ActionsTokenResource(KeycloakSession session) {
Expand Down Expand Up @@ -182,12 +182,12 @@ private void assertValidRedirectUri(String redirectUri, ClientModel client) {
private ClientModel assertValidClient(String clientId) {
ClientModel client = session.getContext().getRealm().getClientByClientId(clientId);
if (client == null) {
log.debugf("Client %s doesn't exist", clientId);
logger.debugf("Client %s doesn't exist", clientId);
throw new WebApplicationException(
ErrorResponse.error("Client doesn't exist", Status.BAD_REQUEST));
}
if (!client.isEnabled()) {
log.debugf("Client %s is not enabled", clientId);
logger.debugf("Client %s is not enabled", clientId);
throw new WebApplicationException(
ErrorResponse.error("Client is not enabled", Status.BAD_REQUEST));
}
Expand Down Expand Up @@ -219,7 +219,7 @@ protected AdminAuth authenticateRealmAdminRequest(HttpHeaders headers) {
.authenticate();

if (authResult == null) {
log.debug("Token not valid");
logger.debug("Token not valid");
throw new NotAuthorizedException("Bearer");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.maxime1907.keycloak.actions.token;

import org.keycloak.provider.Provider;
import org.keycloak.provider.ProviderFactory;
import org.keycloak.services.resource.RealmResourceProvider;
import org.keycloak.services.resource.RealmResourceProviderFactory;
import org.keycloak.services.resource.RealmResourceSPI;

public class ActionsTokenResourceProviderSPI extends RealmResourceSPI {

@Override
public boolean isInternal() {
return false;
}

@Override
public String getName() {
return "Action Token Provider";
}

@Override
public Class<? extends Provider> getProviderClass() {
return RealmResourceProvider.class;
}

@Override
public Class<? extends ProviderFactory> getProviderFactoryClass() {
return RealmResourceProviderFactory.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.keycloak.keycloak-server-spi" />
<module name="org.keycloak.keycloak-server-spi-private" />
<module name="org.keycloak.keycloak-services" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.github.maxime1907.keycloak.actions.token.ActionsTokenResourceProviderSPI

0 comments on commit 57c8644

Please sign in to comment.