@Override
  protected void login(LoginController controller, Credentials credentials) throws IOException {
    try {
      client =
          new CloudFrontService(
              new AWSCredentials(credentials.getUsername(), credentials.getPassword())) {

            @Override
            protected HttpClient initHttpConnection() {
              return CloudFrontDistributionConfiguration.this.http();
            }
          };
      // Provoke authentication error
      for (String container : this.getContainers()) {
        for (Distribution.Method method : getMethods(container)) {
          // Cache first container
          this.cache(this.getOrigin(method, container), method);
          break;
        }
        break;
      }
    } catch (CloudFrontServiceException e) {
      log.warn(String.format("Invalid account: %s", e.getMessage()));
      this.message(Locale.localizedString("Login failed", "Credentials"));
      controller.fail(host.getProtocol(), credentials);
      this.login();
    }
  }
Example #2
0
 public Connection getConnection(Credentials c) {
   try {
     Class.forName("com.mysql.jdbc.Driver");
     return DriverManager.getConnection(c.getUrl(), c.getUsername(), c.getPassword());
   } catch (Throwable e) {
     throw new IllegalArgumentException(e);
   }
 }
 protected ApplicationUser findApplicationUserByCredentials(final Credentials credentials) {
   return getEntityManager()
       .createQuery(
           "SELECT au FROM ApplicationUser au WHERE au.username = :username AND au.password = :password",
           ApplicationUser.class)
       .setParameter(USERNAME, credentials.getUsername())
       .setParameter(PASSWORD, credentials.getPassword())
       .getSingleResult();
 }
Example #4
0
  public static GitHubClient createGitHubClientFromCredentials(Credentials credentials) {
    GitHubClient gitHubClient = new GitHubClient();

    String user = credentials.getUser();
    String password = credentials.getPassword();
    String oauthToken = credentials.getOauthToken();

    if (oauthToken != null && !oauthToken.isEmpty()) {
      return gitHubClient.setOAuth2Token(oauthToken);
    } else if (user != null && !user.isEmpty() && password != null && !password.isEmpty()) {
      return gitHubClient.setCredentials(user, password);
    } else {
      throw new RuntimeException("Unable to initialize GitHubClient: missing credentials!");
    }
  }
  /**
   * Ensure that non URL-safe characters in login and password parts are properly handled, both when
   * parsing and representing URLs as string.
   *
   * @throws MalformedURLException should not happen
   */
  @Test
  public void testCredentialsURLEncoding() throws MalformedURLException {
    FileURL url = getRootURL();

    String urlDecodedString = ":@&=+$,/?t%#[]";
    String urlEncodedString = "%3A%40%26%3D%2B%24%2C%2F%3Ft%25%23%5B%5D";

    url.setCredentials(new Credentials(urlDecodedString, urlDecodedString));
    String urlRep = url.getScheme() + "://" + urlEncodedString + ":" + urlEncodedString + "@";
    assert urlRep.equals(url.toString(true, false));

    url = FileURL.getFileURL(urlRep);
    Credentials credentials = url.getCredentials();
    assert credentials.getLogin().equals(urlDecodedString);
    assert credentials.getPassword().equals(urlDecodedString);
  }
 @Override
 public Response intercept(Chain chain) throws IOException {
   Request request = chain.request();
   Request modifiedRequest =
       request
           .newBuilder()
           .addHeader(
               "Authorization",
               "Basic "
                   + Base64.getEncoder()
                       .encodeToString(
                           (credentials.getUsername() + ":" + credentials.getPassword())
                               .getBytes()))
           .build();
   return chain.proceed(modifiedRequest);
 }
  @Test
  public void testSession() {
    String password = Credentials.getPassword();
    assertFalse("Password can be an empty string", password.equals(""));

    for (int i = 0; i < 10; i++) {
      Session session = context.getSession();

      assertTrue("Notes Session could not be retrieved at the iteration " + i, session.isOpen());
      assertFalse(
          "There's a problem with the Session at the iteration "
              + i
              + ". I can't retrieve the current user name.",
          session.getUserName().equals(""));

      context.closeSession();
    }
  }
 public Connection connection() {
   Connection conn;
   try {
     Class.forName(credentials.getDriver()).newInstance();
     conn =
         DriverManager.getConnection(
             credentials.getUrl(), credentials.getUsername(), credentials.getPassword());
     return conn;
   } catch (InstantiationException ex) {
     Logger.getLogger(GetSQLConnection.class.getName()).log(Level.SEVERE, null, ex);
     return null;
   } catch (IllegalAccessException ex) {
     Logger.getLogger(GetSQLConnection.class.getName()).log(Level.SEVERE, null, ex);
     return null;
   } catch (SQLException ex) {
     Logger.getLogger(GetSQLConnection.class.getName()).log(Level.SEVERE, null, ex);
     return null;
   } catch (ClassNotFoundException ex) {
     Logger.getLogger(GetSQLConnection.class.getName()).log(Level.SEVERE, null, ex);
     return null;
   }
 }
  /**
   * Returns GP ServiceClient instance used for this for this maven session.
   *
   * <p>This implementation resolves service credentials in the following order:
   *
   * <ol>
   *   <li>A json file specified by user defined property 'gp.credentials.json'. This is typically
   *       specified by a command line argument, e.g.<br>
   *       <code>-D gp.credentials.json=/home/yoshito/gpcreds.json</code>
   *   <li>A json file specified by &lt;credentialsJson&gt; in pom.xml
   *   <li>A set of fields specified by &lt;credentials&gt; in pom.xml
   * </ol>
   *
   * @return An instance of ServiceClient.
   * @throws MojoFailureException on a failure.
   */
  protected ServiceClient getServiceClient() throws MojoFailureException {
    if (gpClient == null) {
      synchronized (this) {
        Credentials creds = credentials;
        if (credentialsJson != null) {
          getLog().info("Reading GP service credentials from " + credentialsJson.getAbsolutePath());
          try (InputStreamReader reader =
              new InputStreamReader(new FileInputStream(credentialsJson), StandardCharsets.UTF_8)) {
            Gson gson = new Gson();
            creds = gson.fromJson(reader, Credentials.class);
          } catch (IOException e) {
            throw new MojoFailureException(
                "Error while reading the specified JSON credential file.", e);
          } catch (JsonSyntaxException e) {
            throw new MojoFailureException("Bad JSON credential format.", e);
          }
        }

        if (creds == null) {
          throw new MojoFailureException(
              "Globalization Pipeline service credentials are not specified.");
        }

        if (!creds.isValid()) {
          throw new MojoFailureException("Bad credentials: " + creds);
        }

        getLog().debug("Using GP service credentials " + creds);

        gpClient =
            ServiceClient.getInstance(
                ServiceAccount.getInstance(
                    creds.getUrl(), creds.getInstanceId(),
                    creds.getUserId(), creds.getPassword()));
      }
    }
    return gpClient;
  }