Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
adding partial logout support
Browse files Browse the repository at this point in the history
  • Loading branch information
samithaliyanage committed Jun 10, 2015
1 parent 4844899 commit f0ff343
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion play-pac4j_java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>org.pac4j</groupId>
<artifactId>play-pac4j</artifactId>
<version>1.2.1.htrcv3</version>
<version>1.2.1.htrcv4</version>
</parent>

<artifactId>play-pac4j_java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.commons.lang3.StringUtils;
import org.pac4j.core.client.BaseClient;
import org.pac4j.core.client.Clients;
import org.pac4j.core.client.RedirectAction;
import org.pac4j.core.context.HttpConstants;
import org.pac4j.core.credentials.Credentials;
import org.pac4j.core.exception.RequiresHttpAction;
Expand Down Expand Up @@ -148,19 +149,50 @@ public static Result logoutAndOk() {
* @return the redirection to the "logout url"
*/
public static Result logoutAndRedirect() {
logout();
// parameters in url
final Map<String, String[]> parameters = request().queryString();
final String[] values = parameters.get(Constants.REDIRECT_URL_LOGOUT_PARAMETER_NAME);
String value = null;
if (values != null && values.length == 1) {
String value0 = values[0];
// check the url pattern
if (Config.getLogoutUrlPattern().matcher(value0).matches()) {
value = value0;
}
// get the session id
final String sessionId = session(Constants.SESSION_ID);
logger.debug("sessionId for logout : {}", sessionId);
if (StringUtils.isNotBlank(sessionId)) {
CommonProfile cp = StorageHelper.getProfile(sessionId);

// clients group from config
final Clients clientsGroup = Config.getClients();

// web context
final JavaWebContext context = new JavaWebContext(request(), response(), session(), Play.application().configuration().getString("saml.sso.logoutcallback", null));

// get the client from its type
final BaseClient client = (BaseClient) clientsGroup.findClient(context);

RedirectAction logoutRedirect = client.getLogoutRedirectAction(cp, context);
return ok(logoutRedirect.getContent());
}
return redirect(defaultUrl(value, Config.getDefaultLogoutUrl()));

// TODO: Show proper error page
logger.error("Cannot find session id.");
return ok("Cannot find session id.");
}

public static Result logoutCallback(){
// clients group from config
final Clients clientsGroup = Config.getClients();

// web context
final JavaWebContext context = new JavaWebContext(request(), response(), session(), Play.application().configuration().getString("saml.sso.callback", null));

// get the client from its type
final BaseClient client = (BaseClient) clientsGroup.findClient(context);
logger.debug("client : {}", client);

try {
client.logout(context);
} catch (Exception e){
return internalServerError("Logout Failed.");
}

logout();

return redirect(Config.getDefaultLogoutUrl());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion play-pac4j_scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.pac4j</groupId>
<artifactId>play-pac4j</artifactId>
<version>1.2.1.htrcv3</version>
<version>1.2.1.htrcv4</version>
</parent>

<artifactId>play-pac4j_scala</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<artifactId>play-pac4j</artifactId>
<packaging>pom</packaging>
<name>Play pac4j</name>
<version>1.2.1.htrcv3</version>
<version>1.2.1.htrcv4</version>
<description>Java and Scala multi protocols (CAS, OAuth, OpenID, HTTP...) client for Play 2.2 framework</description>
<url>https://github.com/leleuj/play-pac4j</url>

Expand Down Expand Up @@ -67,7 +67,7 @@
</modules>

<properties>
<pac4j.version>1.5.1.htrcv1</pac4j.version>
<pac4j.version>1.5.1.htrcv3</pac4j.version>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit f0ff343

Please sign in to comment.