use of com.manydesigns.portofino.config.ConfigurationSource in project Portofino by ManyDesigns.
the class PersistenceTest method setup.
protected void setup(FileObject appDir) throws Exception {
Configuration configuration = new PropertiesConfiguration();
final DatabasePlatformsRegistry databasePlatformsRegistry = new DatabasePlatformsRegistry(configuration);
databasePlatformsRegistry.addDatabasePlatform(new H2DatabasePlatform());
databaseModule = new DatabaseModule() {
@Override
public void destroy() {
if (subscription != null) {
subscription.dispose();
subscription = null;
}
}
};
databaseModule.applicationDirectory = appDir;
databaseModule.configuration = new ConfigurationSource(configuration, null);
persistence = databaseModule.getPersistence(databasePlatformsRegistry, new CacheResetListenerRegistry());
databaseModule.init();
persistence.start();
setupJPetStore();
setupHibernateTest();
persistence.initModel();
}
use of com.manydesigns.portofino.config.ConfigurationSource in project Portofino by ManyDesigns.
the class HttpBasicAuthenticationFilter method onPreHandle.
@Override
protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
Subject subject = SecurityUtils.getSubject();
if (!subject.isAuthenticated()) {
HttpServletRequest httpRequest = WebUtils.toHttp(request);
String authorizationHeader = httpRequest.getHeader(AUTHORIZATION_HEADER);
if (!StringUtils.isEmpty(authorizationHeader)) {
String[] prinCred = getPrincipalsAndCredentials(authorizationHeader);
UsernamePasswordToken token;
String host = getHost(request);
if (prinCred == null || prinCred.length < 2) {
// Create an authentication token with an empty password,
// since one hasn't been provided in the request.
String username = prinCred == null || prinCred.length == 0 ? "" : prinCred[0];
token = new UsernamePasswordToken(username, "", false, host);
} else {
String username = prinCred[0];
String password = prinCred[1];
token = new UsernamePasswordToken(username, password, false, host);
}
try {
subject.login(token);
} catch (AuthenticationException e) {
logger.warn("Failed HTTP basic authentication to " + httpRequest.getRequestURL(), e);
HttpServletResponse httpResponse = WebUtils.toHttp(response);
httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
ServletContext ctx = request.getServletContext();
ConfigurationSource config = (ConfigurationSource) ctx.getAttribute(PortofinoSpringConfiguration.CONFIGURATION_SOURCE);
String authcHeader = HttpServletRequest.BASIC_AUTH + " realm=\"" + config.getProperties().getString(PortofinoProperties.APP_NAME) + "\"";
httpResponse.setHeader("WWW-Authenticate", authcHeader);
return false;
}
}
}
return true;
}
use of com.manydesigns.portofino.config.ConfigurationSource in project Portofino by ManyDesigns.
the class CrudActionTest method setup.
protected void setup(FileObject appDir) throws Exception {
Configuration configuration = new PropertiesConfiguration();
DatabasePlatformsRegistry databasePlatformsRegistry = new DatabasePlatformsRegistry(configuration);
databasePlatformsRegistry.addDatabasePlatform(new H2DatabasePlatform());
persistence = new Persistence(appDir, new ConfigurationSource(configuration, null), databasePlatformsRegistry);
persistence.start();
setupJPetStore();
persistence.initModel();
}
use of com.manydesigns.portofino.config.ConfigurationSource in project Portofino by ManyDesigns.
the class SecurityFacade method isOperationAllowed.
public boolean isOperationAllowed(HttpServletRequest request, ActionInstance actionInstance, ResourceAction resourceAction, Method handler) {
if (!satisfiesRequiresAdministrator(resourceAction, handler, isAdministrator(request))) {
return false;
}
logger.debug("Checking actionDescriptor permissions");
boolean isNotAdmin = !isAdministrator(request);
if (isNotAdmin) {
ServletContext servletContext = request.getServletContext();
ConfigurationSource configuration = (ConfigurationSource) servletContext.getAttribute(PortofinoSpringConfiguration.CONFIGURATION_SOURCE);
Permissions permissions;
String resource;
boolean allowed;
if (actionInstance != null) {
logger.debug("The protected resource is a actionDescriptor action");
resource = actionInstance.getPath();
allowed = hasPermissions(configuration.getProperties(), actionInstance, handler);
} else {
logger.debug("The protected resource is a regular JAX-RS resource");
resource = request.getRequestURI();
permissions = new Permissions();
allowed = hasPermissions(configuration.getProperties(), permissions, handler, resourceAction.getClass());
}
if (!allowed) {
logger.info("Access to {} is forbidden", resource);
return false;
}
}
return true;
}
use of com.manydesigns.portofino.config.ConfigurationSource in project Portofino by ManyDesigns.
the class PortofinoDispatcherInitializer method initWithServletContext.
// **************************************************************************
// ServletContextListener implementation
// **************************************************************************
@Override
public void initWithServletContext(ServletContext servletContext) {
// clear the Mapping Diagnostic Context for logging
MDC.clear();
serverInfo = new ServerInfo(servletContext);
super.initWithServletContext(servletContext);
servletContext.setAttribute(PortofinoSpringConfiguration.APPLICATION_DIRECTORY, applicationRoot);
servletContext.setAttribute(PortofinoSpringConfiguration.PORTOFINO_CONFIGURATION, configuration);
servletContext.setAttribute(PortofinoSpringConfiguration.PORTOFINO_CONFIGURATION_FILE, configurationFile);
servletContext.setAttribute(PortofinoSpringConfiguration.CONFIGURATION_SOURCE, new ConfigurationSource(configuration, configurationFile));
logger.info("Servlet API version is " + serverInfo.getServletApiVersion());
if (serverInfo.getServletApiMajor() < 3) {
String msg = "Servlet API version should be >= 3.0.";
logger.warn(msg);
}
}
Aggregations