-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* provid login and logout servlets
- Loading branch information
Showing
9 changed files
with
133 additions
and
64 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
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
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
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
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
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
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
53 changes: 53 additions & 0 deletions
53
pantheon-bundle/src/main/java/com/redhat/pantheon/auth/sso/LoginServlet.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,53 @@ | ||
package com.redhat.pantheon.auth.sso; | ||
|
||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.SlingHttpServletResponse; | ||
import org.apache.sling.api.servlets.SlingAllMethodsServlet; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.servlet.Servlet; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A login servlet that handles Keycloak or basic auth request | ||
* | ||
* @author Lisa Davidson | ||
*/ | ||
@Component( | ||
service = Servlet.class, | ||
property = { | ||
"sling.servlet.methods={GET, POST}", | ||
"sling.servlet.paths=" + LoginServlet.PATH_PATTERN | ||
}, | ||
immediate = true) | ||
public class LoginServlet extends SlingAllMethodsServlet { | ||
private static final Logger log = LoggerFactory.getLogger(LoginServlet.class.getName()); | ||
private static final String BASIC_AUTH_LOGIN_URI = "/pantheon/#/login"; | ||
static final String PATH_PATTERN = "/auth/login"; | ||
|
||
@Override | ||
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { | ||
String uri = ""; | ||
if (System.getenv("AUTH_SERVER_URL") != null) { | ||
try { | ||
uri = System.getenv("SSO_LOGIN_URL") != null ? System.getenv("SSO_LOGIN_URL") : ""; | ||
|
||
if (uri.length() > 0) { | ||
response.setStatus(302); | ||
response.setHeader("Location", uri); | ||
} else { | ||
log.error("Error occurred while creating the Authentication request."); | ||
} | ||
|
||
} catch (Exception e) { | ||
log.error("Error occurred while creating the Authentication request."); | ||
} | ||
} else { | ||
log.debug("SSO is not enabled."); | ||
response.setStatus(302); | ||
response.setHeader("Location", BASIC_AUTH_LOGIN_URI); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
pantheon-bundle/src/main/java/com/redhat/pantheon/auth/sso/LogoutFilter.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,49 @@ | ||
package com.redhat.pantheon.auth.sso; | ||
|
||
import org.apache.sling.servlets.annotations.SlingServletFilter; | ||
import org.apache.sling.servlets.annotations.SlingServletFilterScope; | ||
import org.osgi.framework.Constants; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A Filter that handles logout request for Keycloak Integration | ||
* | ||
* * @author Lisa Davidson | ||
*/ | ||
@Component( | ||
service = Filter.class, | ||
property = { | ||
Constants.SERVICE_DESCRIPTION + "=Filter for keycloak logout request", | ||
Constants.SERVICE_VENDOR + "=Red Hat Content Tooling team" | ||
}) | ||
@SlingServletFilter(scope = {SlingServletFilterScope.REQUEST}, | ||
pattern = "/system/sling/logout", | ||
methods = {"GET"}) | ||
public class LogoutFilter implements Filter { | ||
private static final Logger log = LoggerFactory.getLogger(LogoutFilter.class.getName()); | ||
private static final String REDIRECT_URI = "/pantheon/"; | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
} | ||
|
||
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, | ||
ServletException { | ||
final HttpServletRequest request = (HttpServletRequest) req; | ||
final HttpServletResponse response = (HttpServletResponse) res; | ||
|
||
if (System.getenv("AUTH_SERVER_URL") != null) { | ||
// Invalidate keycloak session | ||
request.getSession().invalidate(); | ||
} | ||
chain.doFilter(request, response); | ||
} | ||
|
||
public void destroy() { | ||
} | ||
} |