AuthTokens { public static AuthToken basic( String username, String password ) { return basic( username, password, null ); }  static AuthToken basic( String username, String password ); static AuthToken basic( String username, String password, String realm ); static AuthToken kerberos( String base64EncodedTicket ); static AuthToken custom( String principal, String credentials, String realm, String scheme); static AuthToken custom( String principal, String credentials, String realm, String scheme, Map<String, Object> parameters); static AuthToken none();  }
@Test void basicAuthWithoutRealm() { InternalAuthToken basic = (InternalAuthToken) basic( "foo", "bar" ); Map<String,Value> map = basic.toMap(); assertThat( map.size(), equalTo( 3 ) ); assertThat( map.get( "scheme" ), equalTo( (Value) new StringValue( "basic" ) ) ); assertThat( map.get( "principal" ), equalTo( (Value) new StringValue( "foo" ) ) ); assertThat( map.get( "credentials" ), equalTo( (Value) new StringValue( "bar" ) ) ); }
@Test void basicAuthWithRealm() { InternalAuthToken basic = (InternalAuthToken) basic( "foo", "bar", "baz" ); Map<String,Value> map = basic.toMap(); assertThat( map.size(), equalTo( 4 ) ); assertThat( map.get( "scheme" ), equalTo( (Value) new StringValue( "basic" ) ) ); assertThat( map.get( "principal" ), equalTo( (Value) new StringValue( "foo" ) ) ); assertThat( map.get( "credentials" ), equalTo( (Value) new StringValue( "bar" ) ) ); assertThat( map.get( "realm" ), equalTo( (Value) new StringValue( "baz" ) ) ); }
@Test void shouldNotAllowBasicAuthTokenWithNullUsername() { NullPointerException e = assertThrows( NullPointerException.class, () -> AuthTokens.basic( null, "password" ) ); assertEquals( "Username can't be null", e.getMessage() ); }
@Test void shouldNotAllowBasicAuthTokenWithNullPassword() { NullPointerException e = assertThrows( NullPointerException.class, () -> AuthTokens.basic( "username", null ) ); assertEquals( "Password can't be null", e.getMessage() ); }
@Test void shouldAllowBasicAuthTokenWithNullRealm() { AuthToken token = AuthTokens.basic( "username", "password", null ); Map<String,Value> map = ((InternalAuthToken) token).toMap(); assertEquals( 3, map.size() ); assertEquals( "basic", map.get( "scheme" ).asString() ); assertEquals( "username", map.get( "principal" ).asString() ); assertEquals( "password", map.get( "credentials" ).asString() ); }