-
Notifications
You must be signed in to change notification settings - Fork 4
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
153 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2016 Cloudogu GmbH. All Rights Reserved. | ||
* | ||
* Copyright notice | ||
*/ | ||
package com.cloudogu.wiki; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author Michael Behlendorf | ||
*/ | ||
public class CasLogoutServlet extends HttpServlet { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(CasLogoutServlet.class); | ||
private final String logoutUrl; | ||
|
||
public CasLogoutServlet(Map<String,String> casSettings) { | ||
logoutUrl = casSettings.get("casServerUrlPrefix") + "/logout"; | ||
} | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) { | ||
request.getSession().invalidate(); | ||
try { | ||
response.sendRedirect(logoutUrl); | ||
} catch (IOException ex) { | ||
LOG.warn("Failed to send redirect.", ex); | ||
} | ||
} | ||
} |
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
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,66 @@ | ||
package com.cloudogu.wiki; | ||
|
||
import com.mashape.unirest.http.Unirest; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.handler.AbstractHandler; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class WikiServerTest { | ||
|
||
@Mock | ||
private WikiServerConfiguration serverConfiguration; | ||
|
||
@Test | ||
public void ensureCookiesAreDisabled() throws Exception { | ||
WikiServer.configureRestClient(serverConfiguration); | ||
|
||
Server server = new Server(0); | ||
server.setHandler(new SimpleHandler() { | ||
|
||
@Override | ||
protected void handle(HttpServletRequest request, HttpServletResponse response) { | ||
if (request.getCookies() == null) { | ||
response.addCookie(new Cookie("test", "value")); | ||
} | ||
} | ||
}); | ||
|
||
server.start(); | ||
try { | ||
String uri = server.getURI().toString(); | ||
|
||
List<String> cookies = Unirest.get(uri).asString().getHeaders().get("Set-Cookie"); | ||
assertEquals(1, cookies.size()); | ||
cookies = Unirest.get(uri).asString().getHeaders().get("Set-Cookie"); | ||
assertEquals(1, cookies.size()); | ||
|
||
} finally { | ||
server.stop(); | ||
} | ||
} | ||
|
||
private static abstract class SimpleHandler extends AbstractHandler { | ||
|
||
@Override | ||
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { | ||
handle(httpServletRequest, httpServletResponse); | ||
} | ||
|
||
protected abstract void handle(HttpServletRequest request, HttpServletResponse response); | ||
} | ||
|
||
} |