Skip to content
Permalink
Browse files

Further thrashing...

  • Loading branch information...
ajs6f committed Jun 6, 2013
1 parent bbe3179 commit 6c51414abaf7aab46f469d348c679b66a1da32b7
@@ -0,0 +1 @@
/target
@@ -4,7 +4,6 @@
import static org.slf4j.LoggerFactory.getLogger;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -13,12 +12,15 @@

import org.modeshape.jcr.api.ServletCredentials;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


public class SessionFactory {

private static final Logger logger = getLogger(SessionFactory.class);

@Inject
@Autowired
private Repository repo;

public SessionFactory() {
@@ -40,36 +42,43 @@ public void setRepository(final Repository repo) {
public Session getSession() throws RepositoryException {
return repo.login();
}

private static ServletCredentials getCredentials(final SecurityContext securityContext,
final HttpServletRequest servletRequest) {
if (securityContext.getUserPrincipal() != null) {
logger.debug("Authenticated user: " +
securityContext.getUserPrincipal().getName());
return new ServletCredentials(servletRequest);
} else {
logger.debug("No authenticated user found!");
return null;
}

public Session getSession(final String workspace)
throws RepositoryException {
return repo.login(workspace);
}

private static ServletCredentials getCredentials(
final SecurityContext securityContext,
final HttpServletRequest servletRequest) {
if (securityContext.getUserPrincipal() != null) {
logger.debug("Authenticated user: " +
securityContext.getUserPrincipal().getName());
return new ServletCredentials(servletRequest);
} else {
logger.debug("No authenticated user found!");
return null;
}
}

public Session getSession(final SecurityContext securityContext,
final HttpServletRequest servletRequest) {

try {
ServletCredentials creds = getCredentials(securityContext, servletRequest);
return (creds != null) ? repo.login(creds) : repo.login();
final ServletCredentials creds =
getCredentials(securityContext, servletRequest);
return (creds != null) ? repo.login(creds) : repo.login();
} catch (final RepositoryException e) {
throw new IllegalStateException(e);
}
}


public AuthenticatedSessionProvider getSessionProvider(
final SecurityContext securityContext,
final SecurityContext securityContext,
final HttpServletRequest servletRequest) {

ServletCredentials creds = getCredentials(securityContext, servletRequest);
return new AuthenticatedSessionProviderImpl(repo, creds);
final ServletCredentials creds =
getCredentials(securityContext, servletRequest);
return new AuthenticatedSessionProviderImpl(repo, creds);
}
}
@@ -4,4 +4,12 @@
@SuppressWarnings("serial")
public class ServletException extends Exception {

public ServletException(final String mesg) {
super(mesg);
}

public ServletException(final Exception mesg) {
super(mesg);
}

}
@@ -1,35 +1,40 @@

package org.fcrepo.test.util;

import static java.util.Collections.emptyList;
import static org.slf4j.LoggerFactory.getLogger;

import java.net.URI;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Filter;

import org.slf4j.Logger;
import com.sun.grizzly.http.SelectorThread;
import com.sun.grizzly.http.servlet.ServletAdapter;
import com.sun.jersey.api.container.grizzly.GrizzlyServerFactory;
import com.sun.jersey.spi.spring.container.servlet.SpringServlet;

public class ContainerWrapper {

private static final Logger logger = LoggerFactory
.getLogger(ContainerWrapper.class);
private static final Logger logger = getLogger(ContainerWrapper.class);

private String contextConfigLocations;
private String contextConfigLocation = null;

private int port;

private SelectorThread server;

private String packagesToScan;
private String packagesToScan = null;

private List<Filter> filters = emptyList();

public void setPackagesToScan(final String packagesToScan) {
this.packagesToScan = packagesToScan;
}

public void setContextConfigLocations(final String contextConfigLocations) {
this.contextConfigLocations = contextConfigLocations;
public void setContextConfigLocation(final String contextConfigLocation) {
this.contextConfigLocation = contextConfigLocation;
}

public void setPort(final int port) {
@@ -39,12 +44,20 @@ public void setPort(final int port) {
public void start() throws Exception {
final URI uri = URI.create("http://localhost:" + port + "/");
final ServletAdapter adapter = new ServletAdapter();
adapter.addInitParameter("com.sun.jersey.config.property.packages",
packagesToScan);
if (packagesToScan != null) {
adapter.addInitParameter("com.sun.jersey.config.property.packages",
packagesToScan);
}
adapter.addInitParameter("com.sun.jersey.api.json.POJOMappingFeature",
"true");
adapter.addContextParameter("contextConfigLocation",
contextConfigLocations);
if (contextConfigLocation != null) {
adapter.addContextParameter("contextConfigLocation",
contextConfigLocation);
}
for (final Filter filter : filters) {
adapter.addFilter(filter, filter.getClass().getName() + "-" +
filter.hashCode(), null);
}
adapter.addServletListener("org.springframework.web.context.ContextLoaderListener");
adapter.setServletInstance(new SpringServlet());
adapter.setContextPath(uri.getPath());
@@ -58,4 +71,8 @@ public void stop() throws Exception {
server.stopEndpoint();
}

public void setFilters(final List<Filter> filters) {
this.filters = filters;
}

}

0 comments on commit 6c51414

Please sign in to comment.
You can’t perform that action at this time.