Package de.innovationgate.wgaservices

Examples of de.innovationgate.wgaservices.WGAServiceException


  public RemoteSession login(String domain, String user, String pwd) throws WGAServiceException {
    WGAConfiguration config = _core.getWgaConfiguration();

        DomainConfiguration domainConfig = _core.getDomainConfig(domain);
        if (domainConfig == null) {
            throw new WGAServiceException("Unknown domain '" + domain + "'");
        }
       
        if (domainConfig.getAuthModule() != null) {
            try {
                if (_core.getBruteForceLoginBlocker().login(domainConfig, user, pwd) == null) {
                    throw new WGAServiceException("Invalid login");  
                }
            }
            catch (AuthenticationException e) {
                throw new WGAServiceException("Authentication exception logging into domain '" + domain + "': " + e.getMessage());
            }
        }
       
        return new RemoteSession(domainConfig.getName(), user, pwd);
  }
View Full Code Here


            // Open db
            WGDatabase db = retrieveAndOpenDB(session, dbKey);
           
            // Test permissions
            if (!mayCallAction(db, actionID)) {
                throw new WGAServiceException("You are not permitted to call remote action '" + actionID + "'");
            }
           
            // Get root content and action
            TMLContext context = new TMLContext(db.getDummyContent(db.getDefaultLanguage()), _core, null, null);
            context.makeThreadMainContext();
           
            TMLAction action = context.getActionByID(actionID, null);
            if (action == null) {
                throw new WGAServiceException("Undefined action: " + actionID);
            }
           
            // Calculate execution context
            if (executionContext != null) {
                context = context.context(executionContext, false);
                if (context == null) {
                    throw new WGAServiceException("Unretrievable execution context: " + executionContext);
                }
            }
           
            // Create TMLForm, if form information was issued
            if (form != null) {
                FormInfo formInfo = new FormInfo(form.getId(), false, false);
                formInfo.setSource("none");
                formInfo.setKeepOnValidate(false);
                CSConfig csConfig = (CSConfig) db.getAttribute(WGACore.DBATTRIB_CSCONFIG);
                if (csConfig != null) {
                    formInfo.setVersionCompliance(csConfig.getVersionCompliance());
                }
                de.innovationgate.wgpublisher.webtml.utils.TMLForm tmlForm = context.createform(formInfo);
                tmlForm.importServicesForm(form);
            }
           
            // Create map of parent scope objects
            Map<String, Object> parentScopeObjects = new HashMap<String, Object>();
            parentScopeObjects.put(SCRIPTOBJ_WGASERVICESCONTEXT, _contextProvider);
           
            // Call action
            Object result = context.callCustomAction(action, params, parentScopeObjects);
            if (context.isdefined("actionresult")) {
                ExpressionResult expressionResult = (ExpressionResult) context.item("actionresult");
                if (expressionResult.isError()) {
                    WGExpressionException ex = expressionResult.getException();
                   
                    // User defined TMLScript exception should be passed on unmodified
                    if (ex.getCause() instanceof TMLScriptException) {
                        throw ex.getCause();
                    }
                    else {
                        throw ex;   
                    }
                   
                }
            }
           
            // If action result is an TMLForm, transform it back into a services form
            if (result instanceof de.innovationgate.wgpublisher.webtml.utils.TMLForm) {
                de.innovationgate.wgpublisher.webtml.utils.TMLForm tmlForm = (de.innovationgate.wgpublisher.webtml.utils.TMLForm) result;
                Form servicesForm = tmlForm.exportServicesForm();
                ActionResult actionResult = new ActionResult();
                actionResult.setForm(servicesForm);
                return actionResult;
            } else {
              ActionResult actionResult = new ActionResult();
              actionResult.setNativeResult(result);
              return actionResult;
            }
        }
        catch (TMLScriptException e) {
            throw new WGAServiceException(e.getMessage());
        }
        catch (WGCreationException e) {
            throw new WGAServiceException("Error creating context for action: " + e.getMessage());
        }
        catch (Throwable e) {
          _core.getLog().error("Exception executing remote action '" + actionID + "'", e);
          if (e instanceof WGAServiceException) {
            throw (WGAServiceException) e;
          } else {           
            throw new WGAServiceException("Error executing action: " + e.getClass().getName() + " - " + e.getMessage());
          }
        }
  }
View Full Code Here

 
    protected WGDatabase retrieveAndOpenDB(RemoteSession session, String dbkey) throws WGAServiceException {
        try {
            WGDatabase db = (WGDatabase) _core.getContentdbs().get(dbkey);
            if (db == null) {
              throw new WGAServiceException("No database of key '" + dbkey + "'");
            }
           
            // check client access to db
            if (!_core.isClientPermitted(db, getRequest())) {
                throw new WGAServiceException("Client '" + (getRequest()).getRemoteAddr() + " is not permitted to access db '" + db.getDbReference() + "'.");
            }
           
            // Normal db user login
            if (session.getDomain() != null) {
              
                DomainConfiguration domainConfig = _core.getDomainConfigForDatabase(db);
                if (!domainConfig.getName().equals(session.getDomain())) {
                    throw new WGAServiceException("The database '" + db.getDbReference() + "' is not in domain '" + session.getDomain() + "'");
                }
               
                if (_core.getBruteForceLoginBlocker().login(db, session.getUsername(), session.getPassword()) <= WGDatabase.ACCESSLEVEL_NOACCESS) {
                    throw new WGAServiceException("Login is invalid or no access to database '" + dbkey + "'");
                }
                return _core.prepareDB(db, null);   
            }
           
            // Administrative login
            else {
               
                HttpServletRequest request = getRequest();
                if (!_core.isAdministrativePort(request.getLocalPort())) {
                    throw new WGAServiceException("Administrative services are not enabled");
                }
              
                if (!_core.isAdminLogin(session.getUsername(), session.getPassword(), request)) {
                    throw new WGAServiceException("Administrative login is invalid");
                }
               
                if (!db.isSessionOpen()) {
                  db.openSession();
                }
                return _core.prepareDB(db, null);
            }
           
           
        }
        catch (WGAPIException e) {
            throw new WGAServiceException("Error retrieveAndOpenDB(). Exception: '" + e.getClass().getName() + "' message: '" + e.getMessage() + "'.");
        }
    }
View Full Code Here

  }

  public RemoteSession adminLogin(String user, String pwd) throws WGAServiceException {
    HttpServletRequest request = getRequest();
        if (!isAdminServiceEnabled()) {
            throw new WGAServiceException("Administrative services are disabled");         
        }
      
        if (!_core.isAdminLogin(user, pwd, request)) {
            throw new WGAServiceException("Administrative login is invalid");
        }
       
        return new RemoteSession(null, user, pwd);
  }
View Full Code Here


  public String getDesignPath(RemoteSession session, String dbKey) throws WGAServiceException {

        if (!isAdminServiceEnabled()) {
            throw new WGAServiceException("Administrative services are disabled");
        }
   
    if (!isAdminSession(session)) {
      throw new WGAServiceException("You need an administrative login to access this service.");
    }
   
    WGDatabase db = retrieveAndOpenDB(session, dbKey);
    if (db.isSessionOpen()) {
      WGDesignProvider provider = db.getDesignProvider();
View Full Code Here

    return _core.isAdministrativePort(getRequest().getLocalPort());
  }

  public synchronized void installPlugins(RemoteSession session, List<DataSource> plugins) throws WGAServiceException {
    if (!isAdminServiceEnabled()) {
            throw new WGAServiceException("Administrative services are disabled");
        }
   
    if (!isAdminSession(session)) {
      throw new WGAServiceException("You need an administrative login to access this service.");
    }
       
    try {
      WGAPluginSet pluginSet = _core.getPluginSet();
      List<WorkspaceOperation> operations = new ArrayList<WorkspaceOperation>();
      Iterator<DataSource> pluginIt = plugins.iterator();
     
      while (pluginIt.hasNext()) {
        InstallPluginOperation operation = pluginSet.loadPluginToWorkspace(pluginIt.next().getInputStream());
        operations.add(operation);
      }
      pluginSet.performOperations(operations);
      pluginSet.save();
     
      operations.clear();
      _core.updatePlugins();
    } catch (Exception e) {
      throw new WGAServiceException("Plugin installation failed.", e);
    }

  }
View Full Code Here

  }

  public List<FSDesignResourceState> retrieveFSDesignResourceState(RemoteSession session, String path) throws WGAServiceException {
        if (!isAdminServiceEnabled()) {
            throw new WGAServiceException("Administrative services are disabled");
        }
   
    if (!isAdminSession(session)) {
      throw new WGAServiceException("You need an administrative login to access this service.");
    }
   
    WGADesignSource source = _core.getDesignManager().getDesignSources().get(WGAConfiguration.UID_DESIGNSOURCE_FILESYSTEM);
    if (source instanceof FileSystemDesignSource) {
      FileSystemDesignSource fsSource = (FileSystemDesignSource)source;
      try {
        fsSource.getDir().refresh();
        FileObject base = fsSource.getDir().resolveFile(path);
        if (base.exists()) {
          return createStates(base, base);         
        }
      } catch (Exception e) {       
        throw new WGAServiceException(e);
      }     
    }
    return new ArrayList<FSDesignResourceState>();
  }
View Full Code Here

    return path;
  }

  public DataSource retrieveFSDesignResourceContent(RemoteSession session, FSDesignResourceState state) throws WGAServiceException {
        if (!isAdminServiceEnabled()) {
            throw new WGAServiceException("Administrative services are disabled");
        }
   
    if (!isAdminSession(session)) {
      throw new WGAServiceException("You need an administrative login to access this service.");
    }
   
    WGADesignSource source = _core.getDesignManager().getDesignSources().get(WGAConfiguration.UID_DESIGNSOURCE_FILESYSTEM);
    if (source instanceof FileSystemDesignSource) {
      FileSystemDesignSource fsSource = (FileSystemDesignSource)source;
      try {
        fsSource.getDir().refresh();
        FileObject resource = fsSource.getDir().resolveFile(state.getPath());
       
        String basePath = fsSource.getDir().getURL().getPath();
        String resourcePath = resource.getURL().getPath();
        if (!resourcePath.startsWith(basePath)) {
          throw new WGAServiceException(new IllegalArgumentException("Illegal design resource path '" + state.getPath() + "'."));
        }
       
        if (resource.exists()) {
          if (resource.getType().equals(FileType.FOLDER)) {
            throw new WGAServiceException(new IllegalArgumentException("Cannot retrieve content of a folder."));
          }
          else {
            return new URLDataSource(resource.getURL());
          }
        }     
      } catch (FileSystemException e) {       
        throw new WGAServiceException("Retrieving content of FSDesignResource '" + state.getPath() + "' failed.", e);
      }     
    }
    return null;
  }
View Full Code Here

    return null;
  }

  public void deleteFSDesignResource(RemoteSession session, String path) throws WGAServiceException {
        if (!isAdminServiceEnabled()) {
            throw new WGAServiceException("Administrative services are disabled");
        }
   
    if (!isAdminSession(session)) {
      throw new WGAServiceException("You need an administrative login to access this service.");
    }

    WGADesignSource source = _core.getDesignManager().getDesignSources().get(WGAConfiguration.UID_DESIGNSOURCE_FILESYSTEM);
    if (source instanceof FileSystemDesignSource) {
      FileSystemDesignSource fsSource = (FileSystemDesignSource)source;
      try {
        fsSource.getDir().refresh();
        FileObject resource = fsSource.getDir().resolveFile(path);
       
        String basePath = fsSource.getDir().getURL().getPath();
        String resourcePath = resource.getURL().getPath();
        if (!resourcePath.startsWith(basePath)) {
          throw new WGAServiceException(new IllegalArgumentException("Illegal design resource path '" + path + "'."));
        }
       
        if (resource.exists()) {
          resource.delete(new FileSelector() {

            public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
              return true;
            }

            public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
              return true;
            }
           
          });
        }
      } catch (FileSystemException e) {
        throw new WGAServiceException("Deleting FSDesignResource '" + path + "' failed.", e);
      }
    }
  }
View Full Code Here

    }
  }

  public void updateFSDesignResource(RemoteSession session, String path, DataSource content, long lastModified) throws WGAServiceException {
        if (!isAdminServiceEnabled()) {
            throw new WGAServiceException("Administrative services are disabled");
        }
   
    if (!isAdminSession(session)) {
      throw new WGAServiceException("You need an administrative login to access this service.");
    }
   
    WGADesignSource source = _core.getDesignManager().getDesignSources().get(WGAConfiguration.UID_DESIGNSOURCE_FILESYSTEM);
    if (source instanceof FileSystemDesignSource) {
      FileSystemDesignSource fsSource = (FileSystemDesignSource)source;
      try {
        fsSource.getDir().refresh();
        FileObject resource = fsSource.getDir().resolveFile(path);
       
        String basePath = fsSource.getDir().getURL().getPath();
        String resourcePath = resource.getURL().getPath();
        if (!resourcePath.startsWith(basePath)) {
          throw new WGAServiceException(new IllegalArgumentException("Illegal design resource path '" + path + "'."));
        }

        resource.createFile();
        OutputStream out = resource.getContent().getOutputStream();
        InputStream in = content.getInputStream();
        WGUtils.inToOut(in, out, 1024);
        out.close();
        in.close();
        resource.getContent().setLastModifiedTime(lastModified);
      } catch (FileSystemException e) {
        throw new WGAServiceException("Updating FSDesignResource '" + path + "' failed.", e);
      } catch (IOException e) {
        throw new WGAServiceException("Updating FSDesignResource '" + path + "' failed.", e);
      }
    }
  }
View Full Code Here

TOP

Related Classes of de.innovationgate.wgaservices.WGAServiceException

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.