Package org.geomajas.command

Examples of org.geomajas.command.CommandResponse


  // assure we are logged in as a specific user to set correct authorizations
  public void login(String name) {
    LoginRequest request = new LoginRequest();
    request.setLogin(name);
    request.setPassword(name);
    CommandResponse response = commandDispatcher.execute("command.staticsecurity.Login", request, null, "en");
    Assert.assertFalse(response.isError());
    Assert.assertTrue(response instanceof LoginResponse);
    securityManager.createSecurityContext(((LoginResponse)response).getToken());
  }
View Full Code Here


  // assure we are logged in as a specific user to set correct authorizations
  public void login(String name) {
    LoginRequest request = new LoginRequest();
    request.setLogin(name);
    request.setPassword(name);
    CommandResponse response = commandDispatcher.execute("command.staticsecurity.Login", request, null, "en");
    Assert.assertFalse(response.isError());
    Assert.assertTrue(response instanceof LoginResponse);
    securityManager.createSecurityContext(((LoginResponse)response).getToken());
  }
View Full Code Here

  // assure we are logged in as a specific user to set correct authorizations
  public void login(String name) {
    LoginRequest request = new LoginRequest();
    request.setLogin(name);
    request.setPassword(name);
    CommandResponse response = commandDispatcher.execute("command.staticsecurity.Login", request, null, "en");
    Assert.assertFalse(response.isError());
    Assert.assertTrue(response instanceof LoginResponse);
    securityManager.createSecurityContext(((LoginResponse)response).getToken());
  }
View Full Code Here

  public void testGetConfigurationFilterToolsAndInvisibleLayers() throws Exception {
    login("luc");
    GetMapConfigurationRequest request = new GetMapConfigurationRequest();
    request.setApplicationId(APP_ID);
    request.setMapId(MAP_ID);
    CommandResponse response = commandDispatcher.execute(GetMapConfigurationRequest.COMMAND, request,
        securityContext.getToken(), "en");
    Assert.assertFalse(response.isError());
    Assert.assertTrue(response instanceof GetMapConfigurationResponse);
    ClientMapInfo mapInfo = ((GetMapConfigurationResponse)response).getMapInfo();

    Assert.assertEquals(MAP_ID, mapInfo.getId());
    Assert.assertEquals("EPSG:4326", mapInfo.getCrs());
View Full Code Here

  public void testGetConfigurationFilterAttributes() throws Exception {
    login("marino");
    GetMapConfigurationRequest request = new GetMapConfigurationRequest();
    request.setApplicationId(APP_ID);
    request.setMapId(MAP_ID);
    CommandResponse response = commandDispatcher.execute(GetMapConfigurationRequest.COMMAND, request,
        securityContext.getToken(), "en");
    Assert.assertFalse(response.isError());
    Assert.assertTrue(response instanceof GetMapConfigurationResponse);
    ClientMapInfo mapInfo = ((GetMapConfigurationResponse)response).getMapInfo();

    Assert.assertEquals(MAP_ID, mapInfo.getId());
    Assert.assertEquals("EPSG:4326", mapInfo.getCrs());
View Full Code Here

  // assure we are logged in as a specific user to set correct authorizations
  public void login(String name) {
    LoginRequest request = new LoginRequest();
    request.setLogin(name);
    request.setPassword(name);
    CommandResponse response = commandDispatcher.execute(LoginRequest.COMMAND, request, null, "en");
    Assert.assertFalse(response.isError());
    Assert.assertTrue(response instanceof LoginResponse);
    securityManager.createSecurityContext(((LoginResponse) response).getToken());
  }
View Full Code Here

  public void oneBboxTest() throws Exception {
    GetLocationForStringRequest request = new GetLocationForStringRequest();
    request.setCrs("EPSG:900913");
    request.setLocation("one");

    CommandResponse commandResponse = commandDispatcher.execute(GetLocationForStringRequest.COMMAND, request, null,
        "en");
    Assert.assertNotNull(commandResponse);
    Assert.assertTrue(commandResponse instanceof GetLocationForStringResponse);
    GetLocationForStringResponse response = (GetLocationForStringResponse)commandResponse;
    Assert.assertTrue(response.isLocationFound());
View Full Code Here

  public void combineBboxTest() throws Exception {
    GetLocationForStringRequest request = new GetLocationForStringRequest();
    request.setCrs("EPSG:900913");
    request.setLocation("bla");

    CommandResponse commandResponse = commandDispatcher.execute(GetLocationForStringRequest.COMMAND, request, null,
        "en");
    Assert.assertNotNull(commandResponse);
    Assert.assertTrue(commandResponse instanceof GetLocationForStringResponse);
    GetLocationForStringResponse response = (GetLocationForStringResponse)commandResponse;
    Assert.assertTrue(response.isLocationFound());
View Full Code Here

    String id = Long.toString(++commandCount); // NOTE this is not thread safe
    // safe or cluster aware
    log.info("{} execute command {} for user token {} in locale {}, request {}", new Object[] { id, commandName,
        userToken, locale, request });
    long begin = System.currentTimeMillis();
    CommandResponse response;

    String previousToken = securityContext.getToken();
    boolean tokenIdentical;
    if (null == userToken) {
      tokenIdentical = false; // always need to *try* as otherwise login would never be possible
    } else {
      tokenIdentical = userToken.equals(previousToken);
    }
    try {
      if (!tokenIdentical) {
        // need to change security context
        log.debug("login using token {}", userToken);
        if (!securityManager.createSecurityContext(userToken)) {
          // not authorized
          response = new CommandResponse();
          response.setId(id);
          response.getErrors().add(
              new GeomajasSecurityException(ExceptionCode.CREDENTIALS_MISSING_OR_INVALID, userToken));
          response.setExecutionTime(System.currentTimeMillis() - begin);
          return response;
        }
      }

      // check access rights for the command
      if (securityContext.isCommandAuthorized(commandName)) {

        Command command = null;
        try {
          command = applicationContext.getBean(commandName, Command.class);
        } catch (BeansException be) {
          log.error("could not create command bean for {}", new Object[] { commandName }, be);
        }
        if (null != command) {
          response = command.getEmptyCommandResponse();
          response.setId(id);
          try {
            command.execute(request, response);
          } catch (Throwable throwable) { //NOPMD
            log.error("Error executing command", throwable);
            response.getErrors().add(throwable);
          }
        } else {
          response = new CommandResponse();
          response.setId(id);
          response.getErrors().add(new GeomajasException(ExceptionCode.COMMAND_NOT_FOUND, commandName));
        }

      } else {
        // not authorized
        response = new CommandResponse();
        response.setId(id);
        response.getErrors().add(
            new GeomajasSecurityException(ExceptionCode.COMMAND_ACCESS_DENIED, commandName, securityContext
                .getUserId()));
      }

      // Now process the errors for display on the client:
      List<Throwable> errors = response.getErrors();
      Locale localeObject = null;
      if (null != errors && !errors.isEmpty()) {
        log.warn("Command caused exceptions, to be passed on to caller:");
        for (Throwable t : errors) {
          String msg;
          if (!(t instanceof GeomajasException)) {
            msg = t.getMessage();
            if (null == msg) {
              msg = t.getClass().getName();
            } else {
              log.warn(msg, t);
            }
          } else {
            if (log.isDebugEnabled()) {
              log.debug("exception occurred {}, stack trace\n{}", t, t.getStackTrace());
            }
            if (null == localeObject && null != locale) {
              localeObject = new Locale(locale);
            }
            msg = ((GeomajasException) t).getMessage(localeObject);
            log.warn(msg);
          }
         
          // For each exception, make sure the entire exception is sent to the client:
          response.getErrorMessages().add(msg);
          response.getExceptions().add(new ExceptionDto(t.getClass().getName(), msg, t.getStackTrace()));
        }
      }

      response.setExecutionTime(System.currentTimeMillis() - begin);
      if (log.isTraceEnabled()) {
        log.trace("response:\n{}", response);
      }
      return response;
    } finally {
View Full Code Here

  // assure we are logged in as a specific user to set correct authorizations
  public void login(String name) {
    LoginRequest request = new LoginRequest();
    request.setLogin(name);
    request.setPassword(name);
    CommandResponse response = commandDispatcher.execute(LoginRequest.COMMAND, request, null, "en");
    junit.framework.Assert.assertFalse(response.isError());
    junit.framework.Assert.assertTrue(response instanceof LoginResponse);
    securityManager.createSecurityContext(((LoginResponse)response).getToken());
  }
View Full Code Here

TOP

Related Classes of org.geomajas.command.CommandResponse

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.