Search in sources :

Example 1 with NullToken

use of org.apache.accumulo.core.client.security.tokens.NullToken in project accumulo by apache.

the class CredentialsTest method testToString.

@Test
public void testToString() {
    Credentials creds = new Credentials(null, null);
    assertEquals(Credentials.class.getName() + ":null:null:<hidden>", creds.toString());
    creds = new Credentials("", new NullToken());
    assertEquals(Credentials.class.getName() + "::" + NullToken.class.getName() + ":<hidden>", creds.toString());
    creds = new Credentials("abc", null);
    assertEquals(Credentials.class.getName() + ":abc:null:<hidden>", creds.toString());
    creds = new Credentials("abc", new PasswordToken(""));
    assertEquals(Credentials.class.getName() + ":abc:" + PasswordToken.class.getName() + ":<hidden>", creds.toString());
}
Also used : NullToken(org.apache.accumulo.core.client.security.tokens.NullToken) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) Credentials(org.apache.accumulo.core.clientImpl.Credentials) Test(org.junit.jupiter.api.Test)

Example 2 with NullToken

use of org.apache.accumulo.core.client.security.tokens.NullToken in project accumulo by apache.

the class CredentialsTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    Credentials nullNullCreds = new Credentials(null, null);
    Credentials abcNullCreds = new Credentials("abc", new NullToken());
    Credentials cbaNullCreds = new Credentials("cba", new NullToken());
    Credentials abcBlahCreds = new Credentials("abc", new PasswordToken("blah"));
    // check hash codes
    assertEquals(0, nullNullCreds.hashCode());
    assertEquals("abc".hashCode(), abcNullCreds.hashCode());
    assertEquals(abcNullCreds.hashCode(), abcBlahCreds.hashCode());
    assertNotEquals(abcNullCreds.hashCode(), cbaNullCreds.hashCode());
    // identity
    assertEquals(abcNullCreds, abcNullCreds);
    assertEquals(new Credentials("abc", new NullToken()), abcNullCreds);
    // equal, but different token constructors
    assertEquals(new Credentials("abc", new PasswordToken("abc".getBytes(UTF_8))), new Credentials("abc", new PasswordToken("abc")));
    // test not equals
    assertNotEquals(nullNullCreds, abcBlahCreds);
    assertNotEquals(nullNullCreds, abcNullCreds);
    assertNotEquals(abcNullCreds, abcBlahCreds);
}
Also used : NullToken(org.apache.accumulo.core.client.security.tokens.NullToken) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) Credentials(org.apache.accumulo.core.clientImpl.Credentials) Test(org.junit.jupiter.api.Test)

Example 3 with NullToken

use of org.apache.accumulo.core.client.security.tokens.NullToken in project accumulo by apache.

the class AuthenticationTokenTest method testSerializeDeserializeToken.

@Test
public void testSerializeDeserializeToken() {
    byte[] randomBytes = new byte[12];
    do {
        // random fill, but avoid all zeros case
        random.nextBytes(randomBytes);
    } while (IntStream.range(0, randomBytes.length).allMatch(i -> randomBytes[i] == 0));
    byte[] serialized = AuthenticationTokenSerializer.serialize(new PasswordToken(randomBytes));
    PasswordToken passwordToken = AuthenticationTokenSerializer.deserialize(PasswordToken.class, serialized);
    assertArrayEquals(randomBytes, passwordToken.getPassword());
    serialized = AuthenticationTokenSerializer.serialize(new NullToken());
    AuthenticationToken nullToken = AuthenticationTokenSerializer.deserialize(NullToken.class, serialized);
    assertEquals(new NullToken(), nullToken);
}
Also used : NullToken(org.apache.accumulo.core.client.security.tokens.NullToken) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) Test(org.junit.jupiter.api.Test)

Aggregations

NullToken (org.apache.accumulo.core.client.security.tokens.NullToken)3 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)3 Test (org.junit.jupiter.api.Test)3 Credentials (org.apache.accumulo.core.clientImpl.Credentials)2 TCredentials (org.apache.accumulo.core.securityImpl.thrift.TCredentials)2 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)1