-
Notifications
You must be signed in to change notification settings - Fork 26
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
pavel.stastny
committed
Jun 29, 2020
1 parent
036e4ab
commit 82a48a6
Showing
38 changed files
with
1,350 additions
and
832 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...ters/src/main/java/cz/incad/kramerius/auth/mochshib/MockHTTPServletInvocationHandler.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,58 @@ | ||
package cz.incad.kramerius.auth.mochshib; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import java.util.*; | ||
|
||
public class MockHTTPServletInvocationHandler implements InvocationHandler{ | ||
|
||
public static class EmbeddedEnumeration implements Enumeration<String>{ | ||
private HttpServletRequest request; | ||
private Hashtable<String,String> table; | ||
|
||
private List<String> list = new ArrayList<>(); | ||
public EmbeddedEnumeration(HttpServletRequest request, Hashtable<String, String> table) { | ||
this.request = request; | ||
this.table = table; | ||
Enumeration headerNames = request.getHeaderNames(); | ||
while(headerNames.hasMoreElements()) list.add((String) headerNames.nextElement()); | ||
Enumeration tableKeys = table.keys(); | ||
while(tableKeys.hasMoreElements()) list.add((String) tableKeys.nextElement()); | ||
} | ||
|
||
@Override | ||
public boolean hasMoreElements() { | ||
return !this.list.isEmpty(); | ||
} | ||
|
||
@Override | ||
public String nextElement() { | ||
return this.list.remove(0); | ||
} | ||
} | ||
|
||
private Hashtable<String, String> attributes = new Hashtable<>(); | ||
private HttpServletRequest request; | ||
|
||
public MockHTTPServletInvocationHandler(Hashtable<String, String> attributes, HttpServletRequest request) { | ||
this.attributes = attributes; | ||
this.request = request; | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
|
||
String methodName = method.getName(); | ||
if (methodName.equals("getHeaderNames")) { | ||
return new EmbeddedEnumeration(this.request, this.attributes); | ||
} | ||
if (methodName.equals("getHeader")) { | ||
String param = (String) args[0]; | ||
String header = this.request.getHeader(param); | ||
if (header != null && !header.trim().equals("")) return header; | ||
else return this.attributes.get(param); | ||
} | ||
return method.invoke(this.request, args); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
authfilters/src/main/java/cz/incad/kramerius/auth/mochshib/MockShibFilter.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,54 @@ | ||
package cz.incad.kramerius.auth.mochshib; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
import java.lang.reflect.Proxy; | ||
import java.util.Hashtable; | ||
import java.util.logging.Level; | ||
|
||
public class MockShibFilter implements Filter { | ||
|
||
public static boolean ENABLED = true; | ||
|
||
public static final Hashtable<String,String> shibTable = new Hashtable<>(); | ||
static { | ||
shibTable.put("shib-session-id", "_dd68cbd66641c9b647b05509ac0241f7"); | ||
shibTable.put("shib-session-index", "_36e3755e67acdeaf1b8b6f7ebebecdeb3abd6ddc98"); | ||
shibTable.put("shib-session-expires", "1592847906"); | ||
shibTable.put("shib-identity-provider", "https://shibboleth.mzk.cz/simplesaml/metadata.xml"); | ||
shibTable.put("shib-authentication-method", "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); | ||
shibTable.put("shib-handler", "https://dnnt.mzk.cz/Shibboleth.sso"); | ||
//remote_user = [email protected] | ||
shibTable.put("remote_user", "[email protected]"); | ||
//affiliation = [email protected];[email protected];[email protected] | ||
shibTable.put("affilation","[email protected];[email protected];[email protected]"); | ||
shibTable.put("edupersonuniqueid","[email protected]"); | ||
} | ||
|
||
|
||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
|
||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | ||
String shib = servletRequest.getParameter("shib"); | ||
if (shib != null && !shib.trim().equals("")) { | ||
ENABLED = false; | ||
} | ||
if (ENABLED) { | ||
HttpServletRequest httpReq = (HttpServletRequest) servletRequest; | ||
Object o = Proxy.newProxyInstance(servletRequest.getClass().getClassLoader(), new Class[]{HttpServletRequest.class}, new MockHTTPServletInvocationHandler(shibTable, httpReq)); | ||
filterChain.doFilter((ServletRequest) o, servletResponse); | ||
} else { | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void destroy() { } | ||
} |
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
Oops, something went wrong.