Beispiel #1
0
  /**
   * Method description
   *
   * @param request
   * @param response
   * @param username
   * @param password
   * @return
   */
  @Override
  public AuthenticationResult authenticate(
      HttpServletRequest request, HttpServletResponse response, String username, String password) {
    String applicationName = request.getRequestURI().split("/")[3];
    AssertUtil.assertIsNotEmpty(username);
    AssertUtil.assertIsNotEmpty(password);
    AssertUtil.assertIsNotEmpty(applicationName);
    AppFactoryConfiguration configuration =
        (AppFactoryConfiguration)
            PrivilegedCarbonContext.getCurrentContext()
                .getOSGiService(AppFactoryConfiguration.class);

    if (authenticateRemotely(username, password, applicationName, configuration)) {
      return new AuthenticationResult(getUser(username), getGroups(applicationName));
    }

    return AuthenticationResult.FAILED;
  }
Beispiel #2
0
  /**
   * Method description
   *
   * @param request
   * @param response
   */
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) {
    BufferedInputStream webToProxyBuf = null;
    BufferedOutputStream proxyToClientBuf = null;
    HttpURLConnection con;

    try {
      URL url = urlProvider.getProxyURL();

      AssertUtil.assertIsNotNull(url);

      if (logger.isInfoEnabled()) {
        logger.info("proxy request for {}", url.toString());
      }

      con = (HttpURLConnection) url.openConnection();
      con.setDoOutput(true);
      con.setDoInput(true);
      con.setUseCaches(true);

      for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); ) {
        String headerName = e.nextElement().toString();

        con.setRequestProperty(headerName, request.getHeader(headerName));
      }

      con.connect();
      response.setStatus(con.getResponseCode());

      for (Iterator i = con.getHeaderFields().entrySet().iterator(); i.hasNext(); ) {
        Map.Entry mapEntry = (Map.Entry) i.next();

        if (mapEntry.getKey() != null) {
          response.setHeader(
              mapEntry.getKey().toString(), ((List) mapEntry.getValue()).get(0).toString());
        }
      }

      webToProxyBuf = new BufferedInputStream(con.getInputStream());
      proxyToClientBuf = new BufferedOutputStream(response.getOutputStream());

      int oneByte;

      while ((oneByte = webToProxyBuf.read()) != -1) {
        proxyToClientBuf.write(oneByte);
      }

      con.disconnect();
    } catch (Exception ex) {
      logger.error("could not proxy request", ex);
    } finally {
      IOUtil.close(webToProxyBuf);
      IOUtil.close(proxyToClientBuf);
    }
  }
Beispiel #3
0
  /**
   * Method description
   *
   * @param user
   */
  @Override
  protected void preUpate(User user) {
    if (DUMMY_PASSWORT.equals(user.getPassword())) {
      User o = manager.get(user.getName());

      AssertUtil.assertIsNotNull(o);
      user.setPassword(o.getPassword());
    } else {
      encryptPassword(user);
    }
  }