Java 类org.apache.http.auth.InvalidCredentialsException 实例源码

项目:magic-beanstalk    文件:DockerClientManagerWithAuth.java   
private void setupDockerClient() throws
    InvalidCredentialsException {
  if (dockerClient != null) {
    return;
  }

  final DockerClientConfig config = createClientConfig();

  final DockerCmdExecFactory dockerCmdExecFactory = new JerseyDockerCmdExecFactory();
  dockerClient = DockerClientBuilder.getInstance(config)
      .withDockerCmdExecFactory(dockerCmdExecFactory)
      .build();

  // Check if client was successfully created
  final AuthResponse response = dockerClient.authCmd().exec();
  if (!response.getStatus().equalsIgnoreCase("Login Succeeded")) {
    throw new InvalidCredentialsException("Could not create DockerClient");
  }
}
项目:magic-beanstalk    文件:DockerClientManagerWithAuth.java   
/**
 * Push image to container registry.
 * @param imageName the name of the image.
 * @throws InvalidCredentialsException if authentication fails.
 */
public void pushImage(String imageName) throws
    InvalidCredentialsException {

  setupDockerClient();

  AuthConfig authConfig = new AuthConfig();
  authConfig.withUsername(registryUsername);
  authConfig.withPassword(registryPassword);
  authConfig.withRegistryAddress(registryUrl);
  authConfig.withEmail(registryEmail);

  dockerClient.pushImageCmd(imageName)
      .withAuthConfig(authConfig)
      .exec(new PushImageResultCallback())
      .awaitSuccess();
}
项目:PdfUtil    文件:OutputProviderFactory.java   
public static OutputProvider getOutputProvider(URL url, String userName, String userPassword) throws MalformedURLException, InvalidCredentialsException{
    if(url == null || url.getProtocol() == null || url.getProtocol().trim().isEmpty()){
        throw new MalformedURLException("BAD URL. NO PROTOCOL.");
    }

    AuthenticationData ad = new AuthenticationData(userName, userPassword);

    String protocol = url.getProtocol();
    switch (protocol) {
    case "http":
        return new OutputHttpProvider(url, ad);
    case "file":
        return new OutputFileProvider(url, ad);
    case "ftp":
        return new OutputFtpProvider(url, ad, 30, true);
    }

    throw new MalformedURLException("NO PROTOCOL SUPPORT FOR : " + protocol);
}
项目:PdfUtil    文件:InputProviderFactory.java   
public static InputProvider getInputProvider(URL url, String userName, String userPassword) throws MalformedURLException, InvalidCredentialsException{
    if(url == null || url.getProtocol() == null || url.getProtocol().trim().isEmpty()){
        throw new MalformedURLException("BAD URL. NO PROTOCOL.");
    }

    AuthenticationData ad = new AuthenticationData(userName, userPassword);

    String protocol = url.getProtocol();
    switch (protocol) {
    case "http":
        return new InputHttpProvider(url, ad);
    case "file":
        return new InputFileProvider(url, ad);
    case "ftp":
        return new InputFtpProvider(url, ad, 30, true);
    }

    throw new MalformedURLException("NO PROTOCOL SUPPORT FOR : " + protocol);
}
项目:magic-beanstalk    文件:PushMojo.java   
@Override
public void execute() throws MojoExecutionException {
  final Log log = getLog();

  if (skipPush) {
    log.info("skipPush is true. Skipping image push step.");
    return;
  }

  if (imageName == null || imageName.isEmpty()) {
    imageName = DockerImageUtil.getImageName(
        imageRepository,
        tagName
    );
  }
  try {
    DockerClientManagerWithAuth dockerClientManager =
        new DockerClientManagerWithAuth(region, customRegistry, authPush);

    if (authPush) {
      dockerClientManager.pushImage(imageName);
    } else {
      dockerClientManager.pushImageNoAuth(imageName);
    }
  } catch (InvalidCredentialsException | SdkClientException e) {
    throw new MojoExecutionException(
        "Could not create docker client. Invalid credentials.",
        e
    );
  }
}
项目:magic-beanstalk    文件:DockerClientManagerWithAuth.java   
/**
 * Push image without authentication.
 * @param imageName the name of the image to be pushed.
 * @throws InvalidCredentialsException if authentication fails.
 */
public void pushImageNoAuth(String imageName) throws
    InvalidCredentialsException {
  setupDockerClient();

  dockerClient.pushImageCmd(imageName)
      .exec(new PushImageResultCallback())
      .awaitSuccess();
}
项目:RedisConnector    文件:RemoteApiServlet.java   
private synchronized void serveRunStart(HttpServletRequest request,
        HttpServletResponse response, String path) throws IOException, CoreException, InvalidCredentialsException {
    JSONObject input = parseInput(request);
    verifyPassword(input);

    IContext context = Core.createSystemContext();
    if (!detectedUnitTests) {
        TestManager.instance().findAllTests(context);
        detectedUnitTests = true;
    }

    if (testSuiteRunner != null && !testSuiteRunner.isFinished()) {
        throw new IllegalArgumentException("Cannot start a test run while another test run is still running");
    }

    LOG.info("[remote api] starting new test run");
    testSuiteRunner = new TestSuiteRunner();

    Thread t = new Thread() {
        @Override
        public void run() {
            testSuiteRunner.run();
        }
    };

    t.start();
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);      
}
项目:RedisConnector    文件:RemoteApiServlet.java   
private void verifyPassword(JSONObject input) throws InvalidCredentialsException {
    if (!input.has(PARAM_PASSWORD)) {
        LOG.warn("[remote api] Missing password");
        throw new IllegalArgumentException("No '" + PARAM_PASSWORD + "' attribute found in the JSON body. Please provide a password");
    }

    if (!password.equals(input.getString(PARAM_PASSWORD))) {
        LOG.warn("[remote api] Invalid password");
        throw new InvalidCredentialsException();
    }
}
项目:MqttClient    文件:RemoteApiServlet.java   
private synchronized void serveRunStart(HttpServletRequest request,
        HttpServletResponse response, String path) throws IOException, CoreException, InvalidCredentialsException {
    JSONObject input = parseInput(request);
    verifyPassword(input);

    IContext context = Core.createSystemContext();
    if (!detectedUnitTests) {
        TestManager.instance().findAllTests(context);
        detectedUnitTests = true;
    }

    if (testSuiteRunner != null && !testSuiteRunner.isFinished()) {
        throw new IllegalArgumentException("Cannot start a test run while another test run is still running");
    }

    LOG.info("[remote api] starting new test run");
    testSuiteRunner = new TestSuiteRunner();

    Thread t = new Thread() {
        @Override
        public void run() {
            testSuiteRunner.run();
        }
    };

    t.start();
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);      
}
项目:MqttClient    文件:RemoteApiServlet.java   
private void verifyPassword(JSONObject input) throws InvalidCredentialsException {
    if (!input.has(PARAM_PASSWORD)) {
        LOG.warn("[remote api] Missing password");
        throw new IllegalArgumentException("No '" + PARAM_PASSWORD + "' attribute found in the JSON body. Please provide a password");
    }

    if (!password.equals(input.getString(PARAM_PASSWORD))) {
        LOG.warn("[remote api] Invalid password");
        throw new InvalidCredentialsException();
    }
}
项目:database-connector    文件:RemoteApiServlet.java   
private synchronized void serveRunStart(HttpServletRequest request,
        HttpServletResponse response, String path) throws IOException, CoreException, InvalidCredentialsException {
    JSONObject input = parseInput(request);
    verifyPassword(input);

    IContext context = Core.createSystemContext();
    if (!detectedUnitTests) {
        TestManager.instance().findAllTests(context);
        detectedUnitTests = true;
    }

    if (testSuiteRunner != null && !testSuiteRunner.isFinished()) {
        throw new IllegalArgumentException("Cannot start a test run while another test run is still running");
    }

    LOG.info("[remote api] starting new test run");
    testSuiteRunner = new TestSuiteRunner();

    Thread t = new Thread() {
        @Override
        public void run() {
            testSuiteRunner.run();
        }
    };

    t.start();
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);      
}
项目:database-connector    文件:RemoteApiServlet.java   
private void verifyPassword(JSONObject input) throws InvalidCredentialsException {
    if (!input.has(PARAM_PASSWORD)) {
        LOG.warn("[remote api] Missing password");
        throw new IllegalArgumentException("No '" + PARAM_PASSWORD + "' attribute found in the JSON body. Please provide a password");
    }

    if (!password.equals(input.getString(PARAM_PASSWORD))) {
        LOG.warn("[remote api] Invalid password");
        throw new InvalidCredentialsException();
    }
}
项目:PdfUtil    文件:OutputProviderFactory.java   
public static OutputProvider getOutputProvider(URL url) throws MalformedURLException, InvalidCredentialsException{
    if(url == null || url.getProtocol() == null || url.getProtocol().trim().isEmpty()){
        throw new MalformedURLException("BAD URL. NO PROTOCOL.");
    }

    String userInfo = url.getUserInfo();
    if(userInfo != null && userInfo.contains(":")){
        String[] userData = userInfo.split(Pattern.quote(":"));
        String userName = userData[0];
        String userPassword = userData[1];
        return getOutputProvider(url, userName, userPassword);
    } else {
        return getOutputProvider(url, null, null);
    }
}
项目:PdfUtil    文件:OutputFtpProvider.java   
protected OutputFtpProvider(
    URL url, AuthenticationData authenticationData, int timeOutSeconds, boolean connectWithPassiveMode
) throws MalformedURLException, InvalidCredentialsException {
    super(url, authenticationData);
    this.timeOutSeconds = timeOutSeconds;
    this.connectWithPassiveMode = connectWithPassiveMode;
}
项目:PdfUtil    文件:ContentProvider.java   
private void checkAuthenticationData(AuthenticationData authenticationData) throws InvalidCredentialsException{
    if(isAuthenticationRequired()){
        if(!StringValidator.validateString(authenticationData.getUserName()) 
        || !StringValidator.validateString(authenticationData.getUserPassword())){
            throw new InvalidCredentialsException();
        }
    }
}
项目:PdfUtil    文件:InputFtpProvider.java   
protected InputFtpProvider(
    URL url, AuthenticationData authenticationData, int timeOutSeconds, boolean connectWithPassiveMode
) throws MalformedURLException, InvalidCredentialsException {
    super(url, authenticationData);
    this.timeOutSeconds = timeOutSeconds;
    this.connectWithPassiveMode = connectWithPassiveMode;
}
项目:PdfUtil    文件:InputProviderFactory.java   
public static InputProvider getInputProvider(URL url) throws MalformedURLException, InvalidCredentialsException{
    if(url == null || url.getProtocol() == null || url.getProtocol().trim().isEmpty()){
        throw new MalformedURLException("BAD URL. NO PROTOCOL.");
    }

    String userInfo = url.getUserInfo();
    if(userInfo != null && userInfo.contains(":")){
        String[] userData = userInfo.split(Pattern.quote(":"));
        String userName = userData[0];
        String userPassword = userData[1];
        return getInputProvider(url, userName, userPassword);
    } else {
        return getInputProvider(url, null, null);
    }
}
项目:RestServices    文件:RemoteApiServlet.java   
private synchronized void serveRunStart(HttpServletRequest request,
        HttpServletResponse response, String path) throws IOException, CoreException, InvalidCredentialsException {
    JSONObject input = parseInput(request);
    verifyPassword(input);

    IContext context = Core.createSystemContext();
    if (!detectedUnitTests) {
        TestManager.instance().findAllTests(context);
        detectedUnitTests = true;
    }

    if (testSuiteRunner != null && !testSuiteRunner.isFinished()) {
        throw new IllegalArgumentException("Cannot start a test run while another test run is still running");
    }

    LOG.info("[remote api] starting new test run");
    testSuiteRunner = new TestSuiteRunner();

    Thread t = new Thread() {
        @Override
        public void run() {
            testSuiteRunner.run();
        }
    };

    t.start();
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);      
}
项目:RestServices    文件:RemoteApiServlet.java   
private void verifyPassword(JSONObject input) throws InvalidCredentialsException {
    if (!input.has(PARAM_PASSWORD)) {
        LOG.warn("[remote api] Missing password");
        throw new IllegalArgumentException("No '" + PARAM_PASSWORD + "' attribute found in the JSON body. Please provide a password");
    }

    if (!password.equals(input.getString(PARAM_PASSWORD))) {
        LOG.warn("[remote api] Invalid password");
        throw new InvalidCredentialsException();
    }
}
项目:Cherry    文件:RequestInterceptor.java   
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException, InvalidCredentialsException {
  log.debug("Intercepted request [{}] with URI [{}] for context [{}].", request, request.getRequestLine().getUri(), context);

  final Boolean authenticated = authenticate(request, context);

  context.setAttribute(Authenticated, authenticated);
  Context.instance().getInvocationContext().set(Key.Authenticated, authenticated);

  if (request instanceof BasicHttpRequest) if (isDebugEnabled())
    getTracerService().examine(request);
}
项目:UnitTesting    文件:RemoteApiServlet.java   
private synchronized void serveRunStart(HttpServletRequest request,
        HttpServletResponse response, String path) throws IOException, CoreException, InvalidCredentialsException {
    JSONObject input = parseInput(request);
    verifyPassword(input);

    IContext context = Core.createSystemContext();
    if (!detectedUnitTests) {
        TestManager.instance().findAllTests(context);
        detectedUnitTests = true;
    }

    if (testSuiteRunner != null && !testSuiteRunner.isFinished()) {
        throw new IllegalArgumentException("Cannot start a test run while another test run is still running");
    }

    LOG.info("[remote api] starting new test run");
    testSuiteRunner = new TestSuiteRunner();

    Thread t = new Thread() {
        @Override
        public void run() {
            testSuiteRunner.run();
        }
    };

    t.start();
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);      
}
项目:UnitTesting    文件:RemoteApiServlet.java   
private void verifyPassword(JSONObject input) throws InvalidCredentialsException {
    if (!input.has(PARAM_PASSWORD)) {
        LOG.warn("[remote api] Missing password");
        throw new IllegalArgumentException("No '" + PARAM_PASSWORD + "' attribute found in the JSON body. Please provide a password");
    }

    if (!password.equals(input.getString(PARAM_PASSWORD))) {
        LOG.warn("[remote api] Invalid password");
        throw new InvalidCredentialsException();
    }
}
项目:ats-framework    文件:GGSSchemeBase.java   
@Override
public Header authenticate(
                            final Credentials credentials,
                            final HttpRequest request,
                            final HttpContext context ) throws AuthenticationException {

    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    switch (state) {
        case UNINITIATED:
            throw new AuthenticationException(getSchemeName() + " authentication has not been initiated");
        case FAILED:
            throw new AuthenticationException(getSchemeName() + " authentication has failed");
        case CHALLENGE_RECEIVED:
            try {
                token = generateToken(token);
                state = State.TOKEN_GENERATED;
            } catch (GSSException gsse) {
                state = State.FAILED;
                if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL
                    || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED)
                    throw new InvalidCredentialsException(gsse.getMessage(), gsse);
                if (gsse.getMajor() == GSSException.NO_CRED)
                    throw new InvalidCredentialsException(gsse.getMessage(), gsse);
                if (gsse.getMajor() == GSSException.DEFECTIVE_TOKEN
                    || gsse.getMajor() == GSSException.DUPLICATE_TOKEN
                    || gsse.getMajor() == GSSException.OLD_TOKEN)
                    throw new AuthenticationException(gsse.getMessage(), gsse);
                // other error
                throw new AuthenticationException(gsse.getMessage());
            }
            // continue to next case block
        case TOKEN_GENERATED:
            String tokenstr = new String(base64codec.encode(token));
            if (log.isDebugEnabled()) {
                log.debug("Sending response '" + tokenstr + "' back to the auth server");
            }
            return new BasicHeader("Authorization", "Negotiate " + tokenstr);
        default:
            throw new IllegalStateException("Illegal state: " + state);
    }
}
项目:lams    文件:GGSSchemeBase.java   
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    switch (state) {
    case UNINITIATED:
        throw new AuthenticationException(getSchemeName() + " authentication has not been initiated");
    case FAILED:
        throw new AuthenticationException(getSchemeName() + " authentication has failed");
    case CHALLENGE_RECEIVED:
        try {
            String key = null;
            if (isProxy()) {
                key = ExecutionContext.HTTP_PROXY_HOST;
            } else {
                key = ExecutionContext.HTTP_TARGET_HOST;
            }
            HttpHost host = (HttpHost) context.getAttribute(key);
            if (host == null) {
                throw new AuthenticationException("Authentication host is not set " +
                        "in the execution context");
            }
            String authServer;
            if (!this.stripPort && host.getPort() > 0) {
                authServer = host.toHostString();
            } else {
                authServer = host.getHostName();
            }

            if (log.isDebugEnabled()) {
                log.debug("init " + authServer);
            }
            token = generateToken(token, authServer);
            state = State.TOKEN_GENERATED;
        } catch (GSSException gsse) {
            state = State.FAILED;
            if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL
                    || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED)
                throw new InvalidCredentialsException(gsse.getMessage(), gsse);
            if (gsse.getMajor() == GSSException.NO_CRED )
                throw new InvalidCredentialsException(gsse.getMessage(), gsse);
            if (gsse.getMajor() == GSSException.DEFECTIVE_TOKEN
                    || gsse.getMajor() == GSSException.DUPLICATE_TOKEN
                    || gsse.getMajor() == GSSException.OLD_TOKEN)
                throw new AuthenticationException(gsse.getMessage(), gsse);
            // other error
            throw new AuthenticationException(gsse.getMessage());
        }
    case TOKEN_GENERATED:
        String tokenstr = new String(base64codec.encode(token));
        if (log.isDebugEnabled()) {
            log.debug("Sending response '" + tokenstr + "' back to the auth server");
        }
        return new BasicHeader("Authorization", "Negotiate " + tokenstr);
    default:
        throw new IllegalStateException("Illegal state: " + state);
    }
}
项目:PdfUtil    文件:OutputProvider.java   
public OutputProvider(URL url, AuthenticationData authenticationData) throws MalformedURLException, InvalidCredentialsException {
    super(url, authenticationData);
}
项目:PdfUtil    文件:OutputHttpProvider.java   
protected OutputHttpProvider(URL url, AuthenticationData authenticationData) throws MalformedURLException, InvalidCredentialsException {
    super(url, authenticationData);
}
项目:PdfUtil    文件:OutputFileProvider.java   
protected OutputFileProvider(URL url, AuthenticationData authenticationData) throws MalformedURLException, InvalidCredentialsException {
    super(url, authenticationData);
}
项目:PdfUtil    文件:ContentProvider.java   
protected ContentProvider(URL url, AuthenticationData authenticationData) throws MalformedURLException, InvalidCredentialsException {
    isValidProtocol(url);
    checkAuthenticationData(authenticationData);
    this.url = url;
    this.authenticationData = authenticationData;
}
项目:PdfUtil    文件:InputHttpProvider.java   
protected InputHttpProvider(URL url, AuthenticationData authenticationData) throws MalformedURLException, InvalidCredentialsException {
    super(url, authenticationData);
    this.contentEncodingHandler = new HttpContentEncodingHandler();
    this.contentTransferEncodingHandler = new HttpContentTransferEncodingHandler();
}
项目:PdfUtil    文件:InputFileProvider.java   
protected InputFileProvider(URL url, AuthenticationData authenticationData) throws MalformedURLException, InvalidCredentialsException {
    super(url, authenticationData);
}
项目:PdfUtil    文件:InputProvider.java   
public InputProvider(URL url, AuthenticationData authenticationData) throws MalformedURLException, InvalidCredentialsException {
    super(url, authenticationData);
}
项目:Cherry    文件:RequestInterceptor.java   
private Boolean authenticate(final HttpRequest request, final HttpContext context) throws InvalidCredentialsException {
  context.setAttribute(CreateCookie, false);

  if (isOpenGateMessage(request)) {
    final User identity = getUser(request);

    if (null == authenticate(identity)) {
      context.setAttribute(CreateCookie, true);
      return true;
    }

    return false;
  }

  if (isCookiePathHit(request)) {
    final WeakReference<HeaderIterator> headerIterator = new WeakReference<HeaderIterator>(request.headerIterator(Cookie));

    Header header;
    HeaderElement[] elements;
    String value;

    while (headerIterator.get().hasNext()) {
      header = headerIterator.get().nextHeader();

      elements = header.getElements();

      for (final HeaderElement element : elements)
        if (getSessionCookie().equalsIgnoreCase(element.getName())) {
          value = element.getValue();

          if (!isTampered(value))
            return true;
          else return false;
        }
    }

    return false;
  }

  throw new IllegalStateException("Unknown execution context!");
}
项目:Cherry    文件:RequestInterceptor.java   
private InvalidCredentialsException authenticate(final User user) {
  return getUserRepository().authenticate(user);
}
项目:cloudstack    文件:ElastistorUtil.java   
public ElastiCenterClient(String address, String key) throws InvalidCredentialsException, InvalidParameterException, SSLHandshakeException, ServiceUnavailableException {
    elastiCenterAddress = address;
    apiKey = key;
    initialize();
}
项目:cloudstack    文件:ElastistorUtil.java   
public Object executeCommand(String command, MultivaluedMap<String, String> params, Object responeObj) throws Throwable {

            if (!initialized) {
                throw new IllegalStateException("Error : ElastiCenterClient is not initialized.");
            }

            if (command == null || command.trim().isEmpty()) {
                throw new InvalidParameterException("No command to execute.");
            }

            try {
                ClientConfig config = new DefaultClientConfig();
                Client client = Client.create(config);
                WebResource webResource = client.resource(UriBuilder.fromUri(restprotocol + elastiCenterAddress + restpath).build());

                MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
                queryParams.add(queryparamapikey, apiKey);
                queryParams.add(queryparamresponse, responseType);

                queryParams.add(queryparamcommand, command);

                if (null != params) {
                    for (String key : params.keySet()) {
                        queryParams.add(key, params.getFirst(key));
                    }
                }
                if (debug) {
                    System.out.println("Command Sent " + command + " : " + queryParams);
                }
                ClientResponse response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

                if (response.getStatus() >= 300) {
                    if (debug)
                        System.out.println("ElastiCenter returned error code : " + response.getStatus());
                    if (401 == response.getStatus()) {
                        throw new InvalidCredentialsException("Please specify a valid API Key.");
                    } else if (431 == response.getStatus()) {
                        throw new InvalidParameterException(response.getHeaders().getFirst("X-Description"));
                    } else if (432 == response.getStatus()) {
                        throw new InvalidParameterException(command + " does not exist on the ElastiCenter server.  Please specify a valid command or contact your ElastiCenter Administrator.");
                    } else {
                        throw new ServiceUnavailableException("Internal Error. Please contact your ElastiCenter Administrator.");
                    }
                } else if (null != responeObj) {
                    String jsonResponse = response.getEntity(String.class);
                    if (debug) {
                        System.out.println("Command Response : " + jsonResponse);
                    }
                    Gson gson = new Gson();
                    return gson.fromJson(jsonResponse, responeObj.getClass());
                } else {
                    return "Success";
                }
            } catch (Throwable t) {
                throw t;
            }
        }
项目:Cherry    文件:UserRepository.java   
public InvalidCredentialsException authenticate(final User criteria) {
  final User found = find(criteria);

  if (null == found)
    return new InvalidCredentialsException("Non existing identity [" + criteria.getName() + "]!");

  final Boolean paroleMatch = getCryptoService().checkParole(criteria.getParole(), found.getParole());// found.getParole().equals(criteria.getParole())

  if (!paroleMatch)
    return new InvalidCredentialsException("Parole failure for identity [" + criteria.getName() + "]!");

  return null;
}