Skip to content

Commit

Permalink
Got 401 returning from protected resource. Now just have to find out …
Browse files Browse the repository at this point in the history
…how to log in...
  • Loading branch information
ajs6f committed May 21, 2013
1 parent eca6d4a commit 51bac90
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 40 deletions.
Expand Up @@ -11,10 +11,11 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;

import org.slf4j.Logger;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.update.GraphStore;
import org.slf4j.Logger;

public class GraphStoreStreamingOutput implements StreamingOutput {

Expand Down
Expand Up @@ -14,7 +14,6 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
Expand All @@ -32,7 +31,6 @@
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;

import com.hp.hpl.jena.graph.Node;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
Expand All @@ -44,6 +42,7 @@
import org.springframework.stereotype.Component;

import com.google.common.collect.ImmutableMap.Builder;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.query.Dataset;

/**
Expand Down
Expand Up @@ -21,7 +21,6 @@
import org.springframework.stereotype.Component;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.sparql.modify.GraphStoreBasic;

@Provider
@Component
Expand Down
Expand Up @@ -13,14 +13,13 @@
import javax.jcr.RepositoryException;
import javax.ws.rs.WebApplicationException;

import com.hp.hpl.jena.query.DatasetFactory;
import org.junit.Test;
import org.slf4j.Logger;

import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.mem.GraphMem;
import com.hp.hpl.jena.sparql.core.DatasetImpl;
import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.sparql.modify.GraphStoreBasic;
import com.hp.hpl.jena.update.GraphStore;

Expand Down
16 changes: 14 additions & 2 deletions fcrepo-webapp/pom.xml
Expand Up @@ -9,7 +9,9 @@

<artifactId>fcrepo-webapp</artifactId>
<packaging>war</packaging>
<name>fcrepo webapp</name>
<name>fcrepo4 Basic Webapp</name>

<description>A basic packaging of fcrepo4 modules for deployment in a servlet container.</description>

<properties>
<!-- integration test properties -->
Expand Down Expand Up @@ -78,7 +80,17 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>1.0.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
11 changes: 10 additions & 1 deletion fcrepo-webapp/src/main/resources/logback.xml
Expand Up @@ -9,7 +9,16 @@
<logger name="org.fcrepo" additivity="false" level="TRACE">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.modeshape" additivity="false" level="INFO">
<!--<logger name="org.springframework.beans" additivity="false" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>-->
<logger name="org.springframework.security" additivity="false" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.modeshape" additivity="false" level="WARN">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.infinispan" additivity="false" level="WARN">
<appender-ref ref="STDOUT"/>
</logger>
<root additivity="false" level="INFO">
Expand Down
65 changes: 65 additions & 0 deletions fcrepo-webapp/src/main/resources/spring/security.xml
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

<http entry-point-ref="oauthAuthenticationEntryPoint"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false"/>
<intercept-url pattern="/rest/objects/test:oauth" access="ROLE_USER"/>
<custom-filter ref="oauthFilter" before="PRE_AUTH_FILTER"/>
</http>

<oauth:resource-server id="oauthFilter"/>

<bean id="oauthAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="fedora"/>
</bean>



<authentication-manager alias="authenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider>
<user-service id="userDetailsService">
<user name="ajs6f" password="fedora" authorities="ROLE_USER"/>
</user-service>
</authentication-provider>
</authentication-manager>

<!-- apparently the following stuff has to do with authenticating the identity of
OAuth clients for Fedora (as opposed to users) -->

<bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="fedora/client"/>
<property name="typeName" value="Basic"/>
</bean>

<authentication-manager id="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService"/>
</authentication-manager>

<bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetails"/>
</bean>

<client-details-service id="clientDetails"
xmlns="http://www.springframework.org/schema/security/oauth2">
<client client-id="ajs6f" authorized-grant-types="authorization_code"/>
</client-details-service>

<!-- other -->
<bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler"/>


</beans>
72 changes: 41 additions & 31 deletions fcrepo-webapp/src/main/webapp/WEB-INF/web.xml
@@ -1,35 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<display-name>Fedora-on-ModeShape</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/classes/spring/*.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.fcrepo</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<display-name>Fedora-on-ModeShape</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/classes/spring/*.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.fcrepo</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<!-- engaging the ModeShape REST API -->

Expand All @@ -48,13 +58,13 @@
<listener>
<listener-class>org.modeshape.web.jcr.ModeShapeJcrDeployer</listener-class>
</listener>

<!-- BASIC security parameters -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>fcrepo</realm-name>
</login-config>

<security-role>
<role-name>admin</role-name>
</security-role>
Expand Down

0 comments on commit 51bac90

Please sign in to comment.