-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,361 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>ro.pippo</groupId> | ||
<artifactId>pippo-security-parent</artifactId> | ||
<version>1.7.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>jar</packaging> | ||
<artifactId>pippo-pac4j</artifactId> | ||
<name>Pippo Pac4j</name> | ||
<description>Pac4j integration</description> | ||
|
||
<properties> | ||
<pac4j.version>2.2.0</pac4j.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>${servlet.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ro.pippo</groupId> | ||
<artifactId>pippo-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.pac4j</groupId> | ||
<artifactId>pac4j-core</artifactId> | ||
<version>${pac4j.version}</version> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>${mockito.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
106 changes: 106 additions & 0 deletions
106
pippo-security-parent/pippo-pac4j/src/main/java/ro/pippo/pac4j/Pac4jCallbackHandler.java
This file contains 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,106 @@ | ||
/* | ||
* Copyright (C) 2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ro.pippo.pac4j; | ||
|
||
import org.pac4j.core.config.Config; | ||
import org.pac4j.core.engine.CallbackLogic; | ||
import org.pac4j.core.engine.DefaultCallbackLogic; | ||
import ro.pippo.core.route.RouteContext; | ||
import ro.pippo.core.route.RouteHandler; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* This handler finishes the login process for an indirect client, based on the {@link #callbackLogic}. | ||
* | ||
* The configuration can be provided via the following parameters: | ||
* {@code config} (security configuration), | ||
* {@code defaultUrl} (default url after login if none was requested), | ||
* {@code multiProfile} (whether multiple profiles should be kept) and | ||
* {@code renewSession} (whether the session must be renewed after login). | ||
* | ||
* @author Decebal Suiu | ||
*/ | ||
public class Pac4jCallbackHandler implements RouteHandler { | ||
|
||
private CallbackLogic<Object, PippoWebContext> callbackLogic = new DefaultCallbackLogic<>(); | ||
private Config config; | ||
private String defaultUrl; | ||
private Boolean multiProfile; | ||
private Boolean renewSession; | ||
|
||
public Pac4jCallbackHandler(Config config) { | ||
this(config, null); | ||
} | ||
|
||
public Pac4jCallbackHandler(Config config, String defaultUrl) { | ||
this(config, defaultUrl, null); | ||
} | ||
|
||
public Pac4jCallbackHandler(Config config, String defaultUrl, Boolean multiProfile) { | ||
this(config, defaultUrl, multiProfile, null); | ||
} | ||
|
||
public Pac4jCallbackHandler(Config config, String defaultUrl, Boolean multiProfile, Boolean renewSession) { | ||
this.config = config; | ||
this.defaultUrl = defaultUrl; | ||
this.multiProfile = multiProfile; | ||
this.renewSession = renewSession; | ||
} | ||
|
||
@Override | ||
public void handle(RouteContext routeContext) { | ||
Objects.requireNonNull(callbackLogic); | ||
Objects.requireNonNull(config); | ||
|
||
PippoWebContext webContext = new PippoWebContext(routeContext, config.getSessionStore()); | ||
|
||
callbackLogic.perform(webContext, config, config.getHttpActionAdapter(), defaultUrl, multiProfile, renewSession); | ||
} | ||
|
||
public CallbackLogic<Object, PippoWebContext> getCallbackLogic() { | ||
return callbackLogic; | ||
} | ||
|
||
public void setCallbackLogic(CallbackLogic<Object, PippoWebContext> callbackLogic) { | ||
this.callbackLogic = callbackLogic; | ||
} | ||
|
||
public String getDefaultUrl() { | ||
return this.defaultUrl; | ||
} | ||
|
||
public void setDefaultUrl(String defaultUrl) { | ||
this.defaultUrl = defaultUrl; | ||
} | ||
|
||
public Boolean getMultiProfile() { | ||
return multiProfile; | ||
} | ||
|
||
public void setMultiProfile(Boolean multiProfile) { | ||
this.multiProfile = multiProfile; | ||
} | ||
|
||
public Boolean getRenewSession() { | ||
return renewSession; | ||
} | ||
|
||
public void setRenewSession(Boolean renewSession) { | ||
this.renewSession = renewSession; | ||
} | ||
|
||
} |
121 changes: 121 additions & 0 deletions
121
pippo-security-parent/pippo-pac4j/src/main/java/ro/pippo/pac4j/Pac4jLogoutHandler.java
This file contains 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,121 @@ | ||
/* | ||
* Copyright (C) 2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ro.pippo.pac4j; | ||
|
||
import org.pac4j.core.config.Config; | ||
import org.pac4j.core.engine.DefaultLogoutLogic; | ||
import org.pac4j.core.engine.LogoutLogic; | ||
import ro.pippo.core.route.RouteContext; | ||
import ro.pippo.core.route.RouteHandler; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* This handler handles the (application + identity provider) logout process, based on the {@link #logoutLogic}. | ||
* | ||
* The configuration can be provided via the following parameters: | ||
* {@code config} (the security configuration), | ||
* {@code defaultUrl} (default logout url), | ||
* {@code logoutUrlPattern} (pattern that logout urls must match), | ||
* {@code localLogout} (whether the application logout must be performed), | ||
* {@code destroySession} (whether we must destroy the web session during the local logout) and | ||
* {@code centralLogout} (whether the centralLogout must be performed). | ||
* | ||
* @author Decebal Suiu | ||
*/ | ||
public class Pac4jLogoutHandler implements RouteHandler { | ||
|
||
private LogoutLogic<Object, PippoWebContext> logoutLogic = new DefaultLogoutLogic<>(); | ||
private Config config; | ||
private String defaultUrl; | ||
private String logoutUrlPattern; | ||
private Boolean localLogout; | ||
private Boolean destroySession; | ||
private Boolean centralLogout; | ||
|
||
public Pac4jLogoutHandler(Config config) { | ||
this(config, null); | ||
} | ||
|
||
public Pac4jLogoutHandler(Config config, String defaultUrl) { | ||
this(config, defaultUrl, null); | ||
} | ||
|
||
public Pac4jLogoutHandler(Config config, String defaultUrl, String logoutUrlPattern) { | ||
this.config = config; | ||
this.defaultUrl = defaultUrl; | ||
this.logoutUrlPattern = logoutUrlPattern; | ||
} | ||
|
||
@Override | ||
public void handle(RouteContext routeContext) { | ||
Objects.requireNonNull(logoutLogic); | ||
Objects.requireNonNull(config); | ||
|
||
PippoWebContext webContext = new PippoWebContext(routeContext, config.getSessionStore()); | ||
|
||
logoutLogic.perform(webContext, config, config.getHttpActionAdapter(), defaultUrl, logoutUrlPattern, localLogout, destroySession, centralLogout); | ||
} | ||
|
||
public LogoutLogic<Object, PippoWebContext> getLogoutLogic() { | ||
return logoutLogic; | ||
} | ||
|
||
public void setLogoutLogic(LogoutLogic<Object, PippoWebContext> logoutLogic) { | ||
this.logoutLogic = logoutLogic; | ||
} | ||
|
||
public String getDefaultUrl() { | ||
return this.defaultUrl; | ||
} | ||
|
||
public void setDefaultUrl(String defaultUrl) { | ||
this.defaultUrl = defaultUrl; | ||
} | ||
|
||
public String getLogoutUrlPattern() { | ||
return logoutUrlPattern; | ||
} | ||
|
||
public void setLogoutUrlPattern(String logoutUrlPattern) { | ||
this.logoutUrlPattern = logoutUrlPattern; | ||
} | ||
|
||
public Boolean getLocalLogout() { | ||
return localLogout; | ||
} | ||
|
||
public void setLocalLogout(Boolean localLogout) { | ||
this.localLogout = localLogout; | ||
} | ||
|
||
public Boolean getDestroySession() { | ||
return destroySession; | ||
} | ||
|
||
public void setDestroySession(Boolean destroySession) { | ||
this.destroySession = destroySession; | ||
} | ||
|
||
public Boolean getCentralLogout() { | ||
return centralLogout; | ||
} | ||
|
||
public void setCentralLogout(Boolean centralLogout) { | ||
this.centralLogout = centralLogout; | ||
} | ||
|
||
} |
Oops, something went wrong.