Package com.adito.policyframework

Examples of com.adito.policyframework.LaunchSession


    String launchId = request.getParameter(LaunchSession.LAUNCH_ID);
    if (Util.isNullOrTrimmedBlank(launchId)) {
      throw new Exception("No launch ID supplied.");
    }

    LaunchSession launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchId);
    ReverseProxyWebForward wf = (ReverseProxyWebForward) launchSession.getResource();
   
    /* Remove all other launch sessions for this resource, we can only ever have
     * one at a time
     */
    Collection<LaunchSession> sessions = LaunchSessionFactory.getInstance().getLaunchSessionsForType(launchSession.getSession(),
        WebForwardPlugin.WEBFORWARD_RESOURCE_TYPE);
    for (LaunchSession rs : sessions) {
      if (rs != launchSession && rs.getResource() instanceof ReverseProxyWebForward && rs.getResource().getResourceId() == wf.getResourceId()) {
        LaunchSessionFactory.getInstance().removeLaunchSession(rs);
      }
    }

    if (wf.getActiveDNS() && !isValidForActiveDNS(request.getServerName()))
      throw new Exception("Invalid host '" + request.getServerName() + "'; only FQDNs are valid for Active DNS forwarding");

    String path;
    String url = wf.getDestinationURL();
    String hostField = request.getHeader("Host");
    HostService hostService = hostField == null ? null : new HostService(hostField);
    SessionInfo session = getSessionInfo(request);

    try {
      launchSession.checkAccessRights(null, session);

      /*
       * This requires more thought.
       *
       * 1. We can only have on launch session per resource
       * 2. This doesn't take into account other features of reverse proxy
       *    (authentication, encoding, host headers etc)
       *
       */
     
      /**
       * Setup other reverse proxies so they have access to each other. Only
       * reverse proxies with the same policy attached will be allowed.
      List resources = ResourceUtil.getGrantedResource(launchSession.getSession(), WebForwardPlugin.WEBFORWARD_RESOURCE_TYPE);
     
      Resource resource;
      for(Iterator it = resources.iterator(); it.hasNext();) {
        resource = (Resource) it.next();
        if(resource instanceof ReverseProxyWebForward && resource.getResourceId()!=launchSession.getResource().getResourceId()) {
          if(PolicyDatabaseFactory.getInstance().isResourceAttachedToPolicy(resource, launchSession.getPolicy(), launchSession.getSession().getRealm())) {
            LaunchSession ls = LaunchSessionFactory.getInstance().createLaunchSession(launchSession.getSession(), resource, launchSession.getPolicy());
            ls.checkAccessRights(null, session);
          }
         
        }
      }
       */
     
      VariableReplacement r = new VariableReplacement();
      r.setServletRequest(request);
      r.setLaunchSession(launchSession);
      url = r.replace(url);

      CoreEvent evt = new ResourceAccessEvent(this,
                            WebForwardEventConstants.WEB_FORWARD_STARTED,
              wf,
              launchSession.getPolicy(),
              launchSession.getSession(),
              CoreEvent.STATE_SUCCESSFUL).addAttribute(WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_TYPE,
        ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(wf.getType())).getName())
              .addAttribute(WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_URL, url);

      CoreServlet.getServlet().fireCoreEvent(evt);

      // Get the URL to redirect to
      if (wf.getActiveDNS()) {
        URL u = new URL(url);
        URL adu;
        if (Property.getPropertyInt(new SystemConfigKey("webforward.activeDNSFormat")) == 1) {
          adu = new URL("https", launchSession.getId() + "." + hostService.getHost(), hostService.getPort() == 0 ? -1
            : hostService.getPort(), u.getFile());
        } else {
          int idx = hostService.getHost().indexOf('.');
          adu = new URL("https",
                  launchSession.getId() + "." + hostService.getHost().substring(idx + 1),
                  hostService.getPort() == 0 ? -1 : hostService.getPort(),
                  u.getFile());
        }
        path = adu.toExternalForm();

      } else if (wf.getHostHeader() != null && !wf.getHostHeader().equals("")) {
        URL u = new URL(url);

        URL adu = new URL("https", wf.getHostHeader(), hostService.getPort() == 0 ? -1 : hostService.getPort(), u.getFile());

        path = adu.toExternalForm();

        if (adu.getQuery() == null || adu.getQuery().equals("")) {
          path += "?" + LaunchSession.LAUNCH_ID + "=" + launchSession.getId();
        } else {
          path += "&" + LaunchSession.LAUNCH_ID + "=" + launchSession.getId();
        }

        /**
         * Why do we need to use a JSP redirect? Because the new host
         * will be created in a new session and we need the JSESSIONID
         * which is only set once the first response has been returned
         * to the browser. This redirect allows the browser to load a
         * page on the new host and set the session cookie before an
         * automatic redirect takes the user to the correct reverse
         * proxy page.
         */
        URL adu2 = new URL("https",
            /**
             * LDP Not sure why this was using hostService.getHost because my comment above
             * clearly indicates that we have to redirect from the new host
             */
            wf.getHostHeader(),
            hostService.getPort() == 0 ? -1 : hostService.getPort(),
            "/reverseProxyRedirect.jsp?redirectURL=" + Util.urlEncode(path));

        return new ActionForward(adu2.toExternalForm(), true);

      } else {
        URL u = new URL(url);
        path = u.getPath();
        if (u.getQuery() == null || u.getQuery().equals("")) {
          path += "?" + LaunchSession.LONG_LAUNCH_ID + "=" + launchSession.getId();
        } else {
          path += "?" + u.getQuery() + "&" + LaunchSession.LONG_LAUNCH_ID + "=" + launchSession.getId();
        }
       
        URL redir = new URL("https",
          hostService.getHost(),
          hostService.getPort() == 0 ? -1 : hostService.getPort(),
          path);
        path = redir.toExternalForm();
      }
    } catch (NoPermissionException npe) {

      CoreEvent evt = new ResourceAccessEvent(this,
                            WebForwardEventConstants.WEB_FORWARD_STARTED,
              wf,
              launchSession.getPolicy(),
              launchSession.getSession(),
              npe).addAttribute(WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_TYPE,
        ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(wf.getType())).getName())
              .addAttribute(WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_URL, url);
      CoreServlet.getServlet().fireCoreEvent(evt);

View Full Code Here


    }
   
    class RepositoryResource extends AbstractVFSResource {

        RepositoryResource(URI relativeUri) {
            super(new LaunchSession(getSession()),
              relativeUri, true, "", null, VFSRepository.this);
        }
View Full Code Here

            // Launch the agent and return here
          if(isAgentRequired(resource) && !DefaultAgentManager.getInstance().hasActiveAgent(request)) {
            return new ActionForward("/launchAgent.do?returnTo=" +  Util.urlEncode(CoreUtil.getRealRequestURI(request) + "?resourceId=" + id + "&policy=" + policy.getResourceId() + "&returnTo=" + Util.urlEncode(returnTo)), true);
          }
          else {
                LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(session, resource, policy);
                launchSession.checkAccessRights(null, session);
                try {
                  return launch(mapping, launchSession, request, returnTo);
                }
                catch(CoreException ce) {
                  ActionMessages errs = new ActionMessages();
View Full Code Here

         */

        String launchId = request.getParameter(LaunchSession.LAUNCH_ID);

        if (launchId != null) {
            LaunchSession launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchId);
            if (launchSession != null) {
                sessionInfo = launchSession.getSession();
                LogonControllerFactory.getInstance().addCookies(new ServletRequestAdapter((HttpServletRequest) request),
                    new ServletResponseAdapter((HttpServletResponse) response), launchSession.getSession().getLogonTicket(),
                    launchSession.getSession());
                sessionInfo.access();
            } else if (log.isDebugEnabled())
                log.debug("Could not locate session using ticket");
        }
        sessionInfo = LogonControllerFactory.getInstance().getSessionInfo(req);
View Full Code Here

    protected String name;

    public int doStartTag() throws JspException {

        // Look up the requested property value
        LaunchSession launchSession = (LaunchSession)TagUtils.getInstance().lookup(pageContext, name, property, scope);
       
       
      FileSystemForm fsf = (FileSystemForm) pageContext.getRequest().getAttribute("fileSystemForm");
        StringBuffer results = new StringBuffer();
        results.append("<div class=\"path\"><span>");
        StringTokenizer tok = new StringTokenizer(fsf.getPath(), "/");
       
        String currentPath = tok.nextToken(); // Important: skip the file store
        // we only remove the second entry if the first one is the store, else we are straight into the proper paths.
        if (currentPath.equals("fs")){
            currentPath = tok.nextToken(); // Important: skip the file store type
        }
        while(tok.hasMoreTokens()) {
          String element = tok.nextToken();
          currentPath += "/" + element;
            results.append("<a href=\"fileSystem.do?actionTarget=list&" + LaunchSession.LAUNCH_ID + "=" + launchSession.getId() + "&path=" + URLUTF8Encoder.encode(currentPath, false) + "\">" + element +"</a>&nbsp/&nbsp");
    }
        results.append(" </span></div>");
        paths = results.toString();
        return (SKIP_BODY);
    }
View Full Code Here

    fileSystemForm.initialize(request, allFileSystemItems, this.getSessionInfo(request));
  }

  VFSResource checkLaunchSession(HttpServletRequest request, HttpServletResponse response, FileSystemForm fileSystemForm)
          throws Exception {
    LaunchSession launchSession = fileSystemForm.getLaunchSession();
    if (launchSession == null) {
      if (fileSystemForm.getLaunchId() == null || fileSystemForm.getLaunchId() == "") {
        // For a path that is not a network place
        launchSession = new LaunchSession(getSessionInfo(request));
      }
      else {
        launchSession = LaunchSessionFactory.getInstance().getLaunchSession(getSessionInfo(request), fileSystemForm.getLaunchId());
      }
      if(launchSession == null) {
        throw new Exception("No launch session.");
      }
      fileSystemForm.setLaunchSession(launchSession);
    }
    DAVTransaction transaction = new DAVTransaction(request, response);
    VFSRepository repository = VFSRepository.getRepository(launchSession.getSession().getHttpSession());
    VFSResource res = repository.getResource(launchSession, fileSystemForm.getPath(), transaction.getCredentials());
    if (res == null) {
      throw new Exception("Could not find network place resource for path " + fileSystemForm.getPath() + ".");
    }
    fileSystemForm.setVFSResource(res);
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());
                    String uri = resource.getLaunchUri(launchSession);
                    ByteArrayWriter baw = new ByteArrayWriter();
                    baw.writeString(uri);
                    request.setRequestData(baw.toByteArray());
                  return true;
View Full Code Here

        if (uploadFile == null || uploadFile.getFileName() == null || uploadFile.getFileName().trim().equals("")) {
            return upload.getUploadedForward();
        }

        LaunchSession launchSession = null;
        VFSResource res = null;
        try {
           
            // Get the launch session
            SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
            launchSession = session == null ? null : LaunchSessionFactory.getInstance().getLaunchSession(session, upload.getExtraAttribute2());
            if(launchSession == null) {
                throw new Exception("No launch session.");
            }
            launchSession.checkAccessRights(null, session);

            res = DAVServlet.getDAVResource(launchSession, request, response, upload.getResourcePath() + "/" + uploadFile.getFileName());
           
            res.getFile().exists();
            InputStream in = uploadFile.getInputStream();
View Full Code Here

            return false;
        }
       
        // Get the launch session
        SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
        LaunchSession launchSession = session == null ? null : LaunchSessionFactory.getInstance().getLaunchSession(session, fileUpload.getExtraAttribute2());
        if(launchSession == null) {
            throw new Exception("No launch session.");
        }

        VFSResource res = DAVServlet.getDAVResource(launchSession, request, response, fileUpload.getResourcePath() + "/" + file.getFileName());
View Full Code Here

        String ref = request.getParameter("returnTo");
        if (ref == null) {
           ref = CoreUtil.getReferer(request);
           ref = ref == null ? "/showHome.do" : ref;
        }
        LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(session, null, null);
        launchSession.setAttribute(Constants.LAUNCH_ATTR_AGENT_RETURN_TO, ref);
        launchSession.setAttribute(Constants.LAUNCH_ATTR_AGENT_EXTENSION, desc);
        request.setAttribute(Constants.REQ_ATTR_LAUNCH_SESSION, launchSession);
        postSetup(mapping, form, request, response, launchSession);
        return mapping.findForward("launchViaAgentApplet");
    }
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.