Skip to content

Commit

Permalink
Migrate to latest Play version - addresses #92
Browse files Browse the repository at this point in the history
Moves session storage to cookie instead of cache.
  • Loading branch information
resamsel committed Sep 20, 2020
1 parent e119513 commit 60fd014
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/auth/CustomCodeVerifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package auth;

import com.nimbusds.oauth2.sdk.pkce.CodeVerifier;

import java.io.Serializable;

public class CustomCodeVerifier extends CodeVerifier implements Serializable {
public CustomCodeVerifier(String value) {
super(value);
}

public static CustomCodeVerifier from(CodeVerifier codeVerifier) {
return new CustomCodeVerifier(codeVerifier.getValue());
}
}
26 changes: 26 additions & 0 deletions app/auth/CustomCookieSessionStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package auth;

import com.nimbusds.oauth2.sdk.pkce.CodeVerifier;
import org.pac4j.play.PlayWebContext;
import org.pac4j.play.store.NoOpDataEncrypter;
import org.pac4j.play.store.PlayCookieSessionStore;

import javax.inject.Singleton;

@Singleton
public class CustomCookieSessionStore extends PlayCookieSessionStore {

public CustomCookieSessionStore() {
super(new NoOpDataEncrypter());
}

@Override
public void set(PlayWebContext context, String key, Object value) {
Object cleanedValue = value;
if (key.endsWith("$codeVerifierSessionParameter") && value instanceof CodeVerifier) {
cleanedValue = CustomCodeVerifier.from((CodeVerifier) value);
}

super.set(context, key, cleanedValue);
}
}
1 change: 0 additions & 1 deletion app/mappers/ActivityMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static LogEntry toModel(Activity in, LogEntry out) {
out = out != null ? out : new LogEntry();

out.id = in.id;
// TODO

return out;
}
Expand Down
7 changes: 4 additions & 3 deletions app/modules/SecurityModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import auth.ClientName;
import auth.CustomAuthorizer;
import auth.CustomCallbackLogic;
import auth.CustomCookieSessionStore;
import be.objectify.deadbolt.java.cache.HandlerCache;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
Expand All @@ -31,7 +32,6 @@
import org.pac4j.play.deadbolt2.Pac4jHandlerCache;
import org.pac4j.play.deadbolt2.Pac4jRoleHandler;
import org.pac4j.play.http.PlayHttpActionAdapter;
import org.pac4j.play.store.PlayCacheSessionStore;
import org.pac4j.play.store.PlayCookieSessionStore;
import org.pac4j.play.store.PlaySessionStore;
import play.Environment;
Expand Down Expand Up @@ -74,9 +74,9 @@ protected void configure() {
bind(HandlerCache.class).to(Pac4jHandlerCache.class);

bind(Pac4jRoleHandler.class).to(MyPac4jRoleHandler.class);
bind(PlaySessionStore.class).to(PlayCacheSessionStore.class);
// bind(PlaySessionStore.class).to(PlayCacheSessionStore.class);
// com.nimbusds.oauth2.sdk.pkce.CodeVerifier cannot be cast to java.io.Serializable
// bind(PlaySessionStore.class).to(PlayCookieSessionStore.class);
bind(PlaySessionStore.class).to(CustomCookieSessionStore.class);

// callback
final CallbackController callbackController = new CallbackController();
Expand Down Expand Up @@ -171,6 +171,7 @@ protected KeycloakOidcClient provideKeycloakClient() {
config.setBaseUri(KeycloakBaseUri.get(configuration));
config.setRealm(KeycloakRealm.get(configuration));
config.setWithState(false);
config.setDisablePkce(true);

return new KeycloakOidcClient(config);
});
Expand Down

0 comments on commit 60fd014

Please sign in to comment.