Package org.sonatype.nexus.client.core

Examples of org.sonatype.nexus.client.core.NexusClient


  }

  protected NexusClient createNexusClientForRemoteHeader(final String headerName,
                                                         final String headerValue)
  {
    final NexusClient nexusClient = createNexusClientForAnonymous(nexus());
    ((JerseyNexusClient) nexusClient).getClient().addFilter(new ClientFilter()
    {
      @Override
      public ClientResponse handle(final ClientRequest clientRequest) throws ClientHandlerException {
        clientRequest.getHeaders().putSingle(headerName, headerValue);
View Full Code Here


      throws Exception
  {
    configureRemoteHeader("REMOTE_USER");
    configureSecurityRealms();

    final NexusClient rutAuthClient = createNexusClientForRemoteHeader("REMOTE_USER", "admin");

    // if we can get the users it means that authentication was successful and we have enough rights
    rutAuthClient.getSubsystem(Users.class).get();
  }
View Full Code Here

      throws Exception
  {
    configureRemoteHeader("REMOTE_USER");
    configureSecurityRealms();

    final NexusClient rutAuthClient = createNexusClientForRemoteHeader("REMOTE_USER", "deployment");

    // if we can get the repositories it means that authentication was successful and we have enough rights
    rutAuthClient.getSubsystem(Repositories.class).get();

    thrown.expect(NexusClientAccessForbiddenException.class); // 403
    // we should not be able to access users as we do not have enough rights
    rutAuthClient.getSubsystem(Users.class).get();
  }
View Full Code Here

      throws Exception
  {
    configureRemoteHeader("REMOTE_USER");
    configureSecurityRealms();

    final NexusClient rutAuthClient = createNexusClientForRemoteHeader("REMOTE_USER", "unknown");

    thrown.expect(NexusClientResponseException.class); // 401
    // we should not be able to access repositories as we do not have enough rights
    rutAuthClient.getSubsystem(Repositories.class).get();
  }
View Full Code Here

  public void kenaiLogsInWithGoodCredentials()
      throws Exception
  {
    createKenaiBaseRoleIfNeeded();
    // see KenaiAuthcBehaviour: "authenticated" users are those having password = username + "123"
    final NexusClient kenaiAuthenticatedClient = createNexusClient(nexus(), "kenaiuser", "kenaiuser123");
    final Roles kenaiAuthenticatedRoles = kenaiAuthenticatedClient.getSubsystem(Roles.class);
    final Collection<Role> existingRoles = kenaiAuthenticatedRoles.get();
    // most likely redundant, as it all this above would not work, a NexusClientResponseException 401 would be
    // thrown at kenaiAuthenticatedRoles.get();
    assertThat(existingRoles, not(empty()));
  }
View Full Code Here

      throws Exception
  {
    createKenaiBaseRoleIfNeeded();
    // see KenaiAuthcBehaviour: "authenticated" users are those having password = username + "123"
    // this user below will have BAD credentials
    final NexusClient kenaiAuthenticatedClient = createNexusClient(nexus(), "kenaiuser", "kenaiuserABC");
    assertThat("Line above should throw NexusClientResponseException with 401 response!", false);
  }
View Full Code Here

  @Test
  public void testUserWithSingleQuotePassword() {
    Users users = client().getSubsystem(Users.class);
    String password = "\"";
    users.create("test").withPassword(password).withRole("nx-admin").withEmail("no@where.com").save();
    NexusClient client = createNexusClient(nexus(), "test", password);
    //will fail if can't authenticate
    Assert.assertThat(client.getNexusStatus(), Is.is(notNullValue()));
  }
View Full Code Here

   */
  @Test
  public void accessUsersFromSelfSignedLdapServer()
      throws Exception
  {
    final NexusClient nexusClient = getNexusClient();

    final LdapServerConfigurationDTO ldapServerConfig = getLdapServerConfiguration();
    final URI uri = getLdapServerUri(ldapServerConfig);

    // disable Nexus TrustStore for default server
    nexusClient.getSubsystem(TrustStore.class).disableFor(ldapTrustStoreKey(ldapServerConfig.getId()));

    // there will be no user as backend will fail to connect to LDAP server since it has an untrusted certificate
    {
      final List<PlexusUserResource> ldapUsers = getLdapUsers();
      assertThat(ldapUsers, hasSize(0));
    }

    // enable Nexus TrustStore for default server
    nexusClient.getSubsystem(TrustStore.class).enableFor(ldapTrustStoreKey(ldapServerConfig.getId()));
    // trust ldap server certificate
    nexusClient.getSubsystem(Certificates.class).get(uri.getHost(), uri.getPort(), uri.getScheme()).save();

    // there should be at least one user as now the certificate is trusted so ldap server can be accessed
    {
      final List<PlexusUserResource> ldapUsers = getLdapUsers();
      assertThat(ldapUsers, hasSize(greaterThan(0)));
View Full Code Here

   */
  @Test
  public void testConnectionToSelfSignedLdapServer()
      throws Exception
  {
    final NexusClient nexusClient = getNexusClient();

    final LdapServerConfigurationDTO ldapServerConfig = getLdapServerConfiguration();
    final URI uri = getLdapServerUri(ldapServerConfig);

    // trust ldap server certificate
    nexusClient.getSubsystem(Certificates.class).get(uri.getHost(), uri.getPort(), uri.getScheme()).save();

    // disable Nexus TrustStore for default server
    nexusClient.getSubsystem(TrustStore.class).disableFor(ldapTrustStoreKey(ldapServerConfig.getId()));

    // test connection without sending the ldap server id. This will result in not using Nexus SSL Trust Store which
    // should result in a failure
    try {
      testConnection(ldapServerConfig, false);
      assertThat("Expected to fail with Exception", false);
    }
    catch (Exception e) {
      assertThat(e.getMessage(), containsString("unable to find valid certification path"));
    }

    // test connection with sending the ldap server id. Nexus SSL Trust Store will not be used as is not enabled
    // which should result in a failure
    try {
      testConnection(ldapServerConfig, true);
      assertThat("Expected to fail with Exception", false);
    }
    catch (Exception e) {
      assertThat(e.getMessage(), containsString("unable to find valid certification path"));
    }

    // enable Nexus TrustStore for default server
    nexusClient.getSubsystem(TrustStore.class).enableFor(ldapTrustStoreKey(ldapServerConfig.getId()));

    // test connection with sending the ldap server id. Nexus SSL Trust Store will be used as it is enabled
    // which should result in a success
    testConnection(ldapServerConfig, true);

View Full Code Here

   */
  @Test
  public void testUserAndGroupMappingsToSelfSignedLdapServer()
      throws Exception
  {
    final NexusClient nexusClient = getNexusClient();

    final LdapServerConfigurationDTO ldapServerConfig = getLdapServerConfiguration();
    final URI uri = getLdapServerUri(ldapServerConfig);

    // trust ldap server certificate
    nexusClient.getSubsystem(Certificates.class).get(uri.getHost(), uri.getPort(), uri.getScheme()).save();

    // disable Nexus TrustStore for default server
    nexusClient.getSubsystem(TrustStore.class).disableFor(ldapTrustStoreKey(ldapServerConfig.getId()));

    // test without sending the ldap server id. This will result in not using Nexus SSL Trust Store which
    // should result in a failure
    try {
      testUserAndGroupMappings(ldapServerConfig, false);
      assertThat("Expected to fail with Exception", false);
    }
    catch (Exception e) {
      assertThat(e.getMessage(), containsString("unable to find valid certification path"));
    }

    // test with sending the ldap server id. Nexus SSL Trust Store will not be used as is not enabled
    // which should result in a failure
    try {
      testUserAndGroupMappings(ldapServerConfig, true);
      assertThat("Expected to fail with Exception", false);
    }
    catch (Exception e) {
      assertThat(e.getMessage(), containsString("unable to find valid certification path"));
    }

    // enable Nexus TrustStore for default server
    nexusClient.getSubsystem(TrustStore.class).enableFor(ldapTrustStoreKey(ldapServerConfig.getId()));

    // test with sending the ldap server id. Nexus SSL Trust Store will be used as it is enabled
    // which should result in a success
    testUserAndGroupMappings(ldapServerConfig, true);

View Full Code Here

TOP

Related Classes of org.sonatype.nexus.client.core.NexusClient

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.