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
3 changed files
with
157 additions
and
89 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
75 changes: 75 additions & 0 deletions
75
src/test/java/org/fcrepo/auth/oauth/test/filter/AuthenticatedRequestWrappingFilter.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,75 @@ | ||
|
||
package org.fcrepo.auth.oauth.test.filter; | ||
|
||
import static java.lang.reflect.Proxy.newProxyInstance; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.slf4j.Logger; | ||
|
||
public class AuthenticatedRequestWrappingFilter implements Filter { | ||
|
||
private static final Logger LOGGER = | ||
getLogger(AuthenticatedRequestWrappingFilter.class); | ||
|
||
@Override | ||
public void init(final FilterConfig filterConfig) throws ServletException { | ||
init(); | ||
} | ||
|
||
// used by Spring | ||
public void init() { | ||
LOGGER.debug("Initialized {}", this.getClass().getName()); | ||
} | ||
|
||
@Override | ||
public void doFilter(final ServletRequest request, | ||
final ServletResponse response, final FilterChain chain) | ||
throws IOException, ServletException { | ||
HttpServletRequest req = (HttpServletRequest) request; | ||
|
||
try { | ||
req.isUserInRole(""); | ||
} catch (final IllegalStateException e) { | ||
// stupid grizzly doesn't impl isUserInRole(), so we have to stub it out | ||
req = | ||
(HttpServletRequest) newProxyInstance(req.getClass() | ||
.getClassLoader(), | ||
new Class[] {HttpServletRequest.class}, | ||
new InvocationHandler() { | ||
|
||
@Override | ||
public Object | ||
invoke(final Object proxy, | ||
final Method method, | ||
final Object[] args) | ||
throws Throwable { | ||
if (method.getName().equals("isUserInRole")) { | ||
return true; | ||
} | ||
return method.invoke(request, args); | ||
|
||
} | ||
}); | ||
} | ||
|
||
chain.doFilter(req, response); | ||
|
||
} | ||
|
||
@Override | ||
public void destroy() { | ||
LOGGER.debug("Destroyed {}", this.getClass().getName()); | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,34 +1,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation=" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> | ||
|
||
<!-- Context that supports the actual ModeShape JCR itself --> | ||
<!-- Context that supports the actual ModeShape JCR itself --> | ||
|
||
<context:annotation-config/> | ||
<context:annotation-config/> | ||
|
||
<bean name="oauthFilter" class="org.fcrepo.auth.oauth.filter.OAuthFilter" | ||
init-method="init"> | ||
<property name="realm" value="fedora"/> | ||
<property name="provider"> | ||
<bean class="org.fcrepo.auth.oauth.DefaultOAuthResourceProvider"> | ||
<property name="sessionFactory"> | ||
<!-- mints JCR Sessions : needs to reappear here because it can't be autowired from the enclosed contexts--> | ||
<ref bean="org.fcrepo.session.SessionFactory"/> | ||
</property> | ||
</bean> | ||
</property> | ||
<property name="parameterStyles"> | ||
<set | ||
value-type="org.apache.oltu.oauth2.common.message.types.ParameterStyle"> | ||
<value>QUERY</value> | ||
<value>HEADER</value> | ||
</set> | ||
</property> | ||
</bean> | ||
|
||
<bean name="wrapFilter" | ||
class="org.fcrepo.auth.oauth.test.filter.AuthenticatedRequestWrappingFilter" | ||
init-method="init"/> | ||
|
||
|
||
<bean name="authNFilter" | ||
class="org.fcrepo.auth.oauth.filter.RestrictToAuthNFilter" | ||
init-method="init"/> | ||
|
||
<bean name="oauthFilter" class="org.fcrepo.auth.oauth.filter.OAuthFilter" init-method="init"> | ||
<property name="realm" value="fedora"/> | ||
<property name="provider"> | ||
<bean class="org.fcrepo.auth.oauth.DefaultOAuthResourceProvider"> | ||
<property name="sessionFactory"> | ||
<!-- mints JCR Sessions : needs to reappear here because it can't be autowired from the enclosed contexts--> | ||
<ref bean="org.fcrepo.session.SessionFactory"/> | ||
</property> | ||
</bean> | ||
</property> | ||
<property name="parameterStyles"> | ||
<set | ||
value-type="org.apache.oltu.oauth2.common.message.types.ParameterStyle"> | ||
<value>QUERY</value> | ||
<value>HEADER</value> | ||
</set> | ||
</property> | ||
</bean> | ||
|
||
<bean name="authNFilter" class="org.fcrepo.auth.oauth.filter.RestrictToAuthNFilter" init-method="init" /> | ||
|
||
</beans> |