Search in sources :

Example 1 with ShinyApp

use of eu.openanalytics.shinyproxy.services.AppService.ShinyApp in project shinyproxy by openanalytics.

the class BaseController method getAppTitle.

protected String getAppTitle(HttpServletRequest request) {
    String appName = getAppName(request);
    if (appName == null || appName.isEmpty())
        return "";
    ShinyApp app = appService.getApp(appName);
    if (app == null || app.getDisplayName() == null || app.getDisplayName().isEmpty())
        return appName;
    else
        return app.getDisplayName();
}
Also used : ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp)

Example 2 with ShinyApp

use of eu.openanalytics.shinyproxy.services.AppService.ShinyApp in project shinyproxy by openanalytics.

the class IndexController method index.

@RequestMapping("/")
String index(ModelMap map, HttpServletRequest request) {
    prepareMap(map, request);
    List<ShinyApp> apps = userService.getAccessibleApps(SecurityContextHolder.getContext().getAuthentication());
    map.put("apps", apps.toArray());
    Map<ShinyApp, String> appLogos = new HashMap<>();
    map.put("appLogos", appLogos);
    boolean displayAppLogos = false;
    for (ShinyApp app : apps) {
        if (app.getLogoUrl() != null) {
            displayAppLogos = true;
            appLogos.put(app, resolveImageURI(app.getLogoUrl()));
        }
    }
    map.put("displayAppLogos", displayAppLogos);
    return "index";
}
Also used : HashMap(java.util.HashMap) ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ShinyApp

use of eu.openanalytics.shinyproxy.services.AppService.ShinyApp in project shinyproxy by openanalytics.

the class WebSecurityConfig method configure.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable().headers().frameOptions().disable();
    if (auth.hasAuthorization()) {
        // Limit access to the app pages
        http.authorizeRequests().antMatchers("/login", "/signin/**", "/signup").permitAll();
        for (ShinyApp app : appService.getApps()) {
            String[] groups = app.getGroups();
            if (groups == null || groups.length == 0)
                continue;
            String[] appGroups = Arrays.stream(groups).map(s -> s.toUpperCase()).toArray(i -> new String[i]);
            http.authorizeRequests().antMatchers("/app/" + app.getName()).hasAnyRole(appGroups);
        }
        // Limit access to the admin pages
        http.authorizeRequests().antMatchers("/admin").hasAnyRole(userService.getAdminGroups());
        // All other pages are available to authenticated users
        http.authorizeRequests().anyRequest().fullyAuthenticated();
        http.formLogin().loginPage("/login").and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessHandler(logoutHandler).logoutSuccessUrl("/login");
    }
    auth.configureHttpSecurity(http);
}
Also used : Arrays(java.util.Arrays) AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) WebSecurity(org.springframework.security.config.annotation.web.builders.WebSecurity) ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) IAuthenticationBackend(eu.openanalytics.shinyproxy.auth.IAuthenticationBackend) GlobalAuthenticationConfigurerAdapter(org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter) Inject(javax.inject.Inject) Configuration(org.springframework.context.annotation.Configuration) WebSecurityConfigurerAdapter(org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter) AppService(eu.openanalytics.shinyproxy.services.AppService) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) UserService(eu.openanalytics.shinyproxy.services.UserService) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) Bean(org.springframework.context.annotation.Bean) AuthenticationEventPublisher(org.springframework.security.authentication.AuthenticationEventPublisher) LogoutHandler(eu.openanalytics.shinyproxy.auth.LogoutHandler) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp)

Example 4 with ShinyApp

use of eu.openanalytics.shinyproxy.services.AppService.ShinyApp in project shinyproxy by openanalytics.

the class ProxyService method startProxy.

private IContainerProxy startProxy(String userName, String appName) {
    ShinyApp app = appService.getApp(appName);
    if (app == null) {
        throw new ShinyProxyException("Cannot start container: unknown application: " + appName);
    }
    if (findProxy(userName, appName) != null) {
        throw new ShinyProxyException("Cannot start container: user " + userName + " already has an active proxy for " + appName);
    }
    ContainerProxyRequest request = new ContainerProxyRequest();
    request.userId = userName;
    request.app = app;
    IContainerProxy proxy = backend.createProxy(request);
    activeProxies.add(proxy);
    try {
        backend.startProxy(proxy);
    } finally {
        if (proxy.getStatus() != ContainerProxyStatus.Up)
            activeProxies.remove(proxy);
    }
    try {
        URI target = new URI(proxy.getTarget());
        synchronized (mappingListeners) {
            for (MappingListener listener : mappingListeners) {
                listener.mappingAdded(proxy.getName(), target);
            }
        }
    } catch (URISyntaxException ignore) {
    }
    if (logService.isContainerLoggingEnabled()) {
        BiConsumer<File, File> outputAttacher = backend.getOutputAttacher(proxy);
        if (outputAttacher == null) {
            log.warn("Cannot log container output: " + backend.getClass() + " does not support output attaching.");
        } else {
            logService.attachToOutput(proxy, outputAttacher);
        }
    }
    log.info(String.format("Proxy activated [user: %s] [app: %s]", userName, appName));
    eventService.post(EventType.AppStart.toString(), userName, appName);
    return proxy;
}
Also used : ContainerProxyRequest(eu.openanalytics.shinyproxy.container.ContainerProxyRequest) IContainerProxy(eu.openanalytics.shinyproxy.container.IContainerProxy) ShinyProxyException(eu.openanalytics.shinyproxy.ShinyProxyException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp)

Example 5 with ShinyApp

use of eu.openanalytics.shinyproxy.services.AppService.ShinyApp in project shinyproxy by openanalytics.

the class UserService method canAccess.

private boolean canAccess(Authentication principalAuth, String appName) {
    ShinyApp app = appService.getApp(appName);
    if (app == null)
        return false;
    String[] groups = app.getGroups();
    if (groups == null || groups.length == 0)
        return true;
    if (principalAuth == null || principalAuth instanceof AnonymousAuthenticationToken)
        return true;
    for (String group : groups) {
        if (isMember(principalAuth, group))
            return true;
    }
    return false;
}
Also used : AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) ShinyApp(eu.openanalytics.shinyproxy.services.AppService.ShinyApp)

Aggregations

ShinyApp (eu.openanalytics.shinyproxy.services.AppService.ShinyApp)5 ShinyProxyException (eu.openanalytics.shinyproxy.ShinyProxyException)1 IAuthenticationBackend (eu.openanalytics.shinyproxy.auth.IAuthenticationBackend)1 LogoutHandler (eu.openanalytics.shinyproxy.auth.LogoutHandler)1 ContainerProxyRequest (eu.openanalytics.shinyproxy.container.ContainerProxyRequest)1 IContainerProxy (eu.openanalytics.shinyproxy.container.IContainerProxy)1 AppService (eu.openanalytics.shinyproxy.services.AppService)1 UserService (eu.openanalytics.shinyproxy.services.UserService)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Inject (javax.inject.Inject)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 AuthenticationEventPublisher (org.springframework.security.authentication.AuthenticationEventPublisher)1 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 AuthenticationManagerBuilder (org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder)1