Package com.adito.applications

Examples of com.adito.applications.ApplicationShortcut


        return ApplicationsPlugin.APPLICATION_SHORTCUT_RESOURCE_TYPE;
    }

    @Override
    public ApplicationShortcut deleteResource(ApplicationShortcut resource) throws Exception {
        ApplicationShortcut shortcut = ApplicationShortcutDatabaseFactory.getInstance().getShortcut(resource.getResourceId());
        getApplicationShortcutService().deleteShortcut(shortcut.getResourceId());
        return shortcut;
    }
View Full Code Here


        } else if (session.getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
            selectedView = LIST_VIEW;
        }
        try {
            for (Iterator i = applicationShortcuts.iterator(); i.hasNext();) {
                ApplicationShortcut applicationShortcut = (ApplicationShortcut) i.next();
                List policies = PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(applicationShortcut,
                                session.getUser().getRealm());
                ExtensionDescriptor ed = ExtensionStore.getInstance().getExtensionDescriptor(applicationShortcut.getApplication());
                if (ed == null) {
                    log.warn("Found shortcut with an application ID '" + applicationShortcut.getApplication()
                                    + "' that does not exist. An extension may have been removed.");
                } else {
                  if(ed.getApplicationBundle().getStatus() != ExtensionBundleStatus.ACTIVATED) {
                        log.warn("Found shortcut with an application ID '" + applicationShortcut.getApplication()
                            + "' that uses an application contained in an extension bundle that is not activated (its status is '" + ed.getApplicationBundle().getStatus().getName() + "'). Ignoring.");
                  }
                  else {
                      ApplicationShortcutItem item = new ApplicationShortcutItem(ed, applicationShortcut, policies, session
                                      .getNavigationContext(), applicationShortcut.sessionPasswordRequired(session));
                      item.setFavoriteType(getFavoriteType(applicationShortcut.getResourceId()));
                      getModel().addItem(item);                   
                  }
                }
            }
            checkSort();
View Full Code Here

     *
     * @see com.adito.policyframework.forms.AbstractResourceForm#applyToResource()
     */
    @SuppressWarnings("unchecked")
    public void applyToResource() throws Exception {
        ApplicationShortcut as = (ApplicationShortcut) getResource();
        as.setAutoStart(isAutoStart());
        Map<String, String> parameterMap = as.getParameters();
        parameterMap.clear();
        for (Iterator i = getParameterItems().iterator(); i.hasNext();) {
            ShortcutParameterItem pi = (ShortcutParameterItem) i.next();
            parameterMap.put(pi.getName(), pi.getPropertyValue().toString());
        }
View Full Code Here

   * (non-Javadoc)
   *
   * @see com.adito.policyframework.actions.AbstractLaunchAction#isAgentRequired(com.adito.policyframework.Resource)
   */
  protected boolean isAgentRequired(Resource resource) {
    ApplicationShortcut shortcut = (ApplicationShortcut) resource;
    try {
      ExtensionDescriptor descriptor = ExtensionStore.getInstance().getExtensionDescriptor(shortcut.getApplication());
      return ((ApplicationLauncherType) descriptor.getExtensionType()).isAgentRequired(shortcut, descriptor);
    } catch (Exception e) {
      log.error("Failed to determine if agent is required. Assuming not.");
      return false;
    }
View Full Code Here

   *      com.adito.policyframework.LaunchSession,
   *      javax.servlet.http.HttpServletRequest, java.lang.String)
   */
  protected ActionForward launch(ActionMapping mapping, LaunchSession launchSession, HttpServletRequest request, String returnTo)
          throws Exception {
    ApplicationShortcut shortcut = (ApplicationShortcut) launchSession.getResource();
    ExtensionDescriptor descriptor = ExtensionStore.getInstance().getExtensionDescriptor(shortcut.getApplication());
    HashMap<String, String> parameters = new HashMap<String, String>();
    Enumeration e = request.getParameterNames();
    while (e.hasMoreElements()) {
      String nameParam = (String) e.nextElement();
      parameters.put(nameParam, request.getParameter(nameParam));
    }

    // Do the launch
    try {
      if(descriptor.getApplicationBundle().getStatus() != ExtensionBundleStatus.ACTIVATED) {
        throw new Exception("Extension bundle " + descriptor.getApplicationBundle().getId() +" is not activated, cannot launch applicaiton.");
      }
      ActionForward fwd = ((ApplicationLauncherType) descriptor.getExtensionType()).launch(parameters,
        descriptor,
        shortcut,
        mapping,
        launchSession,
        returnTo,
        request);

      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()));

      /*
       * If the launch implementation returns its own forward, it is
       * reponsible for setting up its 'launched' message
       */
      if (fwd == null) {
        ActionMessages msgs = new ActionMessages();
        msgs.add(Globals.MESSAGE_KEY, new BundleActionMessage(ApplicationsPlugin.MESSAGE_RESOURCES_KEY,
                "launchApplication.launched",
                shortcut.getResourceName()));
        saveMessages(request, msgs);
        return new RedirectWithMessages(returnTo, request);
      }
      return fwd;
    } catch (Exception ex) {
View Full Code Here

    /* (non-Javadoc)
   * @see com.adito.policyframework.actions.AbstractResourceDispatchAction#commitCreatedResource(org.apache.struts.action.ActionMapping, com.adito.policyframework.forms.AbstractResourceForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
  protected Resource commitCreatedResource(ActionMapping mapping, AbstractResourceForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    ApplicationShortcutForm asf = (ApplicationShortcutForm)form;
    ApplicationShortcut as = (ApplicationShortcut)asf.getResource();
    int resourceId = ApplicationShortcutDatabaseFactory.getInstance().createApplicationShortcut(
      as.getApplication(), asf.getResourceName(), asf.getResourceDescription(),
      as.getParameters(), as.isAutoStart(), getSessionInfo(request).getRealmId());
    return as.getResourceType().getResourceById(resourceId);
   
  }
View Full Code Here

        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

        for (Iterator i = parameterItems.iterator(); i.hasNext();) {
            ShortcutParameterItem pi = (ShortcutParameterItem) i.next();
            parameterMap.put(pi.getName(), pi.getPropertyValue().toString());
        }
        boolean autoStart = false; // TODO hook this in
        ApplicationShortcut shortcut = null;
        try {
            int shortcutId = ApplicationShortcutDatabaseFactory.getInstance().createApplicationShortcut(application, name, description,
                            parameterMap, autoStart, getSessionInfo(request).getRealmId());
            shortcut = ApplicationShortcutDatabaseFactory.getInstance().getShortcut(shortcutId);
            actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
View Full Code Here

TOP

Related Classes of com.adito.applications.ApplicationShortcut

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.