Search in sources :

Example 1 with ConfigurationSource

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();
}
Also used : H2DatabasePlatform(com.manydesigns.portofino.database.platforms.H2DatabasePlatform) ConfigurationSource(com.manydesigns.portofino.config.ConfigurationSource) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) DatabasePlatformsRegistry(com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry) CacheResetListenerRegistry(com.manydesigns.portofino.cache.CacheResetListenerRegistry) DatabaseModule(com.manydesigns.portofino.modules.DatabaseModule) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 2 with ConfigurationSource

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigurationSource(com.manydesigns.portofino.config.ConfigurationSource) AuthenticationException(org.apache.shiro.authc.AuthenticationException) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 3 with ConfigurationSource

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();
}
Also used : Persistence(com.manydesigns.portofino.persistence.Persistence) H2DatabasePlatform(com.manydesigns.portofino.database.platforms.H2DatabasePlatform) ConfigurationSource(com.manydesigns.portofino.config.ConfigurationSource) CrudConfiguration(com.manydesigns.portofino.resourceactions.crud.configuration.database.CrudConfiguration) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) DatabasePlatformsRegistry(com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 4 with ConfigurationSource

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;
}
Also used : ConfigurationSource(com.manydesigns.portofino.config.ConfigurationSource) Permissions(com.manydesigns.portofino.actions.Permissions) ServletContext(javax.servlet.ServletContext)

Example 5 with ConfigurationSource

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);
    }
}
Also used : ConfigurationSource(com.manydesigns.portofino.config.ConfigurationSource)

Aggregations

ConfigurationSource (com.manydesigns.portofino.config.ConfigurationSource)8 ServletContext (javax.servlet.ServletContext)3 H2DatabasePlatform (com.manydesigns.portofino.database.platforms.H2DatabasePlatform)2 DatabasePlatformsRegistry (com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry)2 Configuration (org.apache.commons.configuration2.Configuration)2 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)2 Permissions (com.manydesigns.portofino.actions.Permissions)1 CacheResetListenerRegistry (com.manydesigns.portofino.cache.CacheResetListenerRegistry)1 DatabaseModule (com.manydesigns.portofino.modules.DatabaseModule)1 Persistence (com.manydesigns.portofino.persistence.Persistence)1 CrudConfiguration (com.manydesigns.portofino.resourceactions.crud.configuration.database.CrudConfiguration)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 Subject (org.apache.shiro.subject.Subject)1 NotNull (org.jetbrains.annotations.NotNull)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 MutablePropertySources (org.springframework.core.env.MutablePropertySources)1