Package com.adito.policyframework

Examples of com.adito.policyframework.LaunchSession


        Policy policy = LaunchSessionManager.getLaunchRequestPolicy(null, agent.getSession(), resource);
        if (resource.sessionPasswordRequired(agent.getSession())) {
          // TODO: prompt user for credentials through agent!
          return true;
        } else {
          LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(agent.getSession(),
            resource,
            policy);
          launchSession.checkAccessRights(null, agent.getSession());
                  if (resource.getType() == TransportType.LOCAL_TUNNEL_ID) {
                      try {
                          Request req = buildLocalTunnel(resource, launchSession);
                          request.setRequestData(req.getRequestData());
                        return true;
View Full Code Here


            List<BundleActionMessage> tunnelFailures = new ArrayList<BundleActionMessage>();
            for (Tunnel tunnel : tunnels) {
                if (tunnel.isAutoStart()) {
                    try {
                        Policy policy = PolicyDatabaseFactory.getInstance().getGrantingPolicyForUser(session.getUser(), tunnel);
                        LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(session, tunnel, policy);
                        startTunnel(launchSession);
                    } catch (TunnelException tne) {
                        log.error("failed to start tunnel: '" + tunnel + "'", tne);
                        tunnelFailures.add(tne.getBundleActionMessage());
                    }
View Full Code Here

      ByteArrayReader reader = new ByteArrayReader(data);
      name = reader.readString();
      launchId = reader.readString();
      filename = reader.readString();

      LaunchSession launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchId);
      if (launchSession == null) {
        throw new ChannelOpenException(ChannelOpenException.CHANNEL_REFUSED, "No launch session with ID " + launchId + ", cannot read file " + filename + " for " + name);
      }

      launchSession.checkAccessRights(null, agent.getSession());

      ExtensionDescriptor descriptor = ExtensionStore.getInstance().getExtensionDescriptor(name);
      if (!descriptor.containsFile(filename))
        throw new ChannelOpenException(ChannelOpenException.CHANNEL_REFUSED, "Application does not contain file " + filename + " in extension " + name);
View Full Code Here

        }
        String returnTo = request.getParameter("returnTo");
        if (Util.isNullOrTrimmedBlank(returnTo)) {
            throw new Exception("No returnTo parameter supplied.");
        }
        LaunchSession launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchId);
        if (launchSession == null) {
            throw new Exception("Invalid launchId parameter supplied.");
        }
        try {
            launchSession.checkAccessRights(null, getSessionInfo(request));
            ((TunnelingService) DefaultAgentManager.getInstance().getService(TunnelingService.class))
                            .startTunnel(launchSession);
            ActionMessages msgs = new ActionMessages();
            msgs.add(Globals.MESSAGE_KEY, new BundleActionMessage(TunnelPlugin.MESSAGE_RESOURCES_KEY, "tunnels.started", launchSession.getResource().getResourceName()));
            saveMessages(request, msgs);
            if (!Util.isNullOrTrimmedBlank(request.getParameter("returnTo"))) {
                return new RedirectWithMessages(request.getParameter("returnTo"), request);
            }
        } catch (CoreException ce) {
            ActionMessages msgs = new ActionMessages();
            msgs.add(Globals.ERROR_KEY, ce.getBundleActionMessage());
            saveErrors(request, msgs);
        } catch (NoPermissionException e) {
            ActionMessages msgs = new ActionMessages();
            msgs.add(Globals.ERROR_KEY, new ActionMessage("tunnels.noPermission", launchSession.getResource().getResourceName()));
            saveErrors(request, msgs);
        }
        return new RedirectWithMessages(returnTo, request);

    }
View Full Code Here

    public ActionForward stop(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        String launchId = request.getParameter(LaunchSession.LAUNCH_ID);
        if (launchId == null)
            throw new PolicyException(PolicyException.INTERNAL_ERROR, "No launchId parameter.");
        LaunchSession launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchId);
        if (launchSession != null) {
          try {
              ((TunnelingService) DefaultAgentManager.getInstance().getService(TunnelingService.class)).stopTunnels(launchSession);
              ActionMessages msgs = new ActionMessages();
              msgs.add(Globals.MESSAGE_KEY, new BundleActionMessage(TunnelPlugin.MESSAGE_RESOURCES_KEY, "tunnels.stopped", launchSession.getResource().getResourceName()));
              saveMessages(request, msgs);
              if (!Util.isNullOrTrimmedBlank(request.getParameter("returnTo"))) {
                  return new RedirectWithMessages(request.getParameter("returnTo"), request);
              }
              return new RedirectWithMessages(mapping.findForward("refresh"), request);
          } catch (CoreException ce) {
              ActionMessages msgs = new ActionMessages();
              msgs.add(Globals.ERROR_KEY, ce.getBundleActionMessage());
              saveErrors(request, msgs);
              return mapping.findForward("display");
 
          } catch (NoPermissionException e) {
              ActionMessages msgs = new ActionMessages();
              msgs.add(Globals.ERROR_KEY, new ActionMessage("tunnels.noPermission", launchSession.getResource().getResourceName()));
              saveErrors(request, msgs);
          }
        }
        else {
          log.warn("No launch value ID, user probably double clicked tunnel.");
View Full Code Here

        Policy policy = LaunchSessionManager.getLaunchRequestPolicy(null, agent.getSession(), resource);
        if (resource.sessionPasswordRequired(agent.getSession())) {
          // TODO: prompt user for credentials through agent!
          return true;
        } else {
          LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(agent.getSession(),
            resource,
            policy);
          launchSession.checkAccessRights(null, agent.getSession());

          ApplicationShortcut shortcut = (ApplicationShortcut) launchSession.getResource();
          ExtensionDescriptor descriptor = ExtensionStore.getInstance().getExtensionDescriptor(shortcut.getApplication());

          Request newRequest = launchApplication(launchSession);
          request.setRequestData(newRequest.getRequestData());

          CoreServlet.getServlet().fireCoreEvent(new ResourceAccessEvent(this,
              ApplicationShortcutEventConstants.APPLICATION_SHORTCUT_LAUNCHED,
                  launchSession.getResource(),
                  launchSession.getPolicy(),
                  launchSession.getSession(),
                  CoreEvent.STATE_SUCCESSFUL).addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_NAME,
            descriptor.getName()).addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_ID, descriptor.getId()));

        }
        return true;
View Full Code Here

     * @see com.adito.core.actions.AuthenticatedAction#onExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        String launchSessionId = request.getParameter(LaunchSession.LAUNCH_ID);
        LaunchSession launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchSessionId);
        if (launchSession == null) {
            throw new Exception("No launch session id " + launchSessionId);
        }
        final ApplicationShortcut shortcut = (ApplicationShortcut)launchSession.getResource();
        launchSession.checkAccessRights(null, getSessionInfo(request));
        ExtensionDescriptor app = ExtensionStore.getInstance().getExtensionDescriptor(shortcut.getApplication());
        if (app == null) {
            throw new Exception("No application named " + shortcut.getApplication() + ".");
        }

        if (!(app.getExtensionType() instanceof HtmlType)) {
            throw new Exception(getClass().getName() + " only supports applications of type " + HtmlType.class + ".");
        }

        // Get the primary VPN client ticket

        HtmlType type = (HtmlType) app.getExtensionType();
        File file = new File(app.getApplicationBundle().getBaseDir(), type.getTemplate());
        if (log.isDebugEnabled())
          log.debug("Loading template " + file.getAbsolutePath());

        InputStream in = null;
        StringBuffer template = new StringBuffer((int) file.length());
        try {
            in = new FileInputStream(file);
            String line = null;
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            while ((line = reader.readLine()) != null) {
                if (template.length() != 0) {
                    template.append("\n");
                }
                template.append(line);
            }
        } finally {
            Util.closeStream(in);
        }

        if (log.isDebugEnabled())
          log.debug("Parsing parameters.");
        for (Iterator i = shortcut.getParameters().entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();           
            String content = (String) entry.getValue();
           
            VariableReplacement r = new VariableReplacement();
            r.setApplicationShortcut(app, null);
            r.setServletRequest(request);
            r.setLaunchSession(launchSession);
           
            entry.setValue(r.replace(content));
        }

        if (log.isDebugEnabled())
          log.debug("Template loaded, doing standard replacements.");

        VariableReplacement r = new VariableReplacement();
        r.setApplicationShortcut(app, shortcut.getParameters());
        r.setServletRequest(request);
        r.setLaunchSession(launchSession);       
        String templateText = r.replace(template.toString());

        ReplacementEngine engine = new ReplacementEngine();

        String tunnels = request.getParameter("tunnels");
        if (tunnels != null && !tunnels.equals("")) {
            StringTokenizer t = new StringTokenizer(tunnels, ",");
            while (t.hasMoreTokens()) {
                String name = null;
                String hostname = null;
                int port = -1;
                try {
                    String tunnel = t.nextToken();
                    StringTokenizer t2 = new StringTokenizer(tunnel, ":");
                    name = t2.nextToken();
                    hostname = t2.nextToken();
                    port = Integer.parseInt(t2.nextToken());
                } catch (Exception e) {
                    throw new Exception("Failed to parse tunnels parameter '" + tunnels + "'.", e);
                }
                final ExtensionDescriptor.TunnelDescriptor tunnelDescriptor = app.getTunnel(name);
                if (tunnelDescriptor == null) {
                    throw new Exception("No tunnel named " + name);
                }
                final String fHostname = hostname;
                final int fPort = port;
                String pattern = "\\$\\{tunnel:" + name + "\\.[^\\}]*\\}";
                engine.addPattern(pattern, new Replacer() {
                    public String getReplacement(Pattern pattern, Matcher matcher, String sequence) {
                        String match = matcher.group();
                        if (match.equals("${tunnel:" + tunnelDescriptor.getName() + ".hostname}")) {
                            return fHostname;
                        } else if (match.equals("${tunnel:" + tunnelDescriptor.getName() + ".port}")) {
                            return String.valueOf(fPort);
                        } else {
                            return "";
                        }
                    }
                }, null);

            }
        }

        // Get the location of Adito as the client sees it
        String url = request.getParameter("adito");
        if (url != null) {
            String host = request.getHeader(HttpConstants.HDR_HOST);
            if (host != null) {
                url = (request.isSecure() ? "https" : "http") + "://" + host;
            } else {

                throw new Exception("No adito parameter supplied.");
            }
        }
        final URL aditoUrl = new URL(url);
        engine.addPattern("\\$\\{adito:[^\\}]*\\}", new Replacer() {
            public String getReplacement(Pattern pattern, Matcher matcher, String sequence) {
                String match = matcher.group();
                try {
                    String param = match.substring(14, match.length() - 1);
                    if (param.equals("host")) {
                        return aditoUrl.getHost();
                    } else if (param.equals("port")) {
                        return String.valueOf(aditoUrl.getPort() == -1 ? (aditoUrl.getProtocol().equals("https") ? 443
                                        : 80) : aditoUrl.getPort());
                    } else if (param.equals("protocol")) {
                        return aditoUrl.getProtocol();
                    } else {
                        throw new Exception("Unknow variable.");
                    }
                } catch (Throwable t) {
                    log.error("Failed to replace " + match + ".", t);
                }
                return "";
            }
        }, null);

        String processed = engine.replace(templateText);
        if (log.isDebugEnabled())
          log.debug("Returning " + processed);

        Util.noCache(response);

        response.setContentType("text/html");
        response.setContentLength(processed.length());
        request.setAttribute(Constants.REQ_ATTR_COMPRESS, Boolean.FALSE);

        OutputStream out = response.getOutputStream();
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
        pw.print(processed);
        pw.flush();

        Policy pol = PolicyDatabaseFactory.getInstance().getGrantingPolicyForUser(launchSession.getSession().getUser(), shortcut);
        CoreServlet.getServlet().fireCoreEvent(new ResourceAccessEvent(this, ApplicationShortcutEventConstants.APPLICATION_SHORTCUT_LAUNCHED, shortcut, pol, launchSession.getSession(), CoreEvent.STATE_SUCCESSFUL)
        .addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_NAME, app.getName())
        .addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_ID, shortcut.getApplication()));
        //////////////////////////////////////////////
       
        return null;
View Full Code Here

                            .getActiveTunnels(session);
            for (Iterator it = tunnels.iterator(); it.hasNext();) {
                Tunnel tunnel = (Tunnel) it.next();
                if (tunnel != null && tunnel.getResourceId() >= 0) {
                    Integer id = new Integer(tunnel.getResourceId());
                    LaunchSession launchSession = activeTunnels.contains(id) ? LaunchSessionFactory.getInstance()
                                    .getFirstLaunchSessionForResource(session, tunnel) : null;
                    TunnelItem ti = new TunnelItem(tunnel, PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(
                                    tunnel, user.getRealm()), launchSession);
                    ti.setFavoriteType(getFavoriteType(tunnel.getResourceId()));
                    getModel().addItem(ti);
View Full Code Here

        if (DefaultAgentManager.getInstance().hasActiveAgent(request)) {
            Set activeTunnels = ((TunnelingService) DefaultAgentManager.getInstance().getService(TunnelingService.class))
                            .getActiveTunnels(LogonControllerFactory.getInstance().getSessionInfo(request));
            SessionInfo sessionInfo = LogonControllerFactory.getInstance().getSessionInfo(request);
            LaunchSession launchSession = activeTunnels.contains(Integer.valueOf(tunnel.getResourceId())) ? LaunchSessionFactory
                            .getInstance().getFirstLaunchSessionForResource(sessionInfo, tunnel) : null;
            return new WrappedFavoriteItem(new TunnelItem(tunnel, null, launchSession), type);
        } else
            return new WrappedFavoriteItem(new TunnelItem(tunnel, null, null), type);
View Full Code Here

TOP

Related Classes of com.adito.policyframework.LaunchSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.