public DirectBearerAuthClient(final Authenticator tokenAuthenticator, final ProfileCreator profileCreator) { defaultAuthenticator(tokenAuthenticator); defaultProfileCreator(profileCreator); }
@Override public String toString() { return toNiceString(this.getClass(), "name", getName(), "credentialsExtractor", getCredentialsExtractor(), "authenticator", getAuthenticator(), "profileCreator", getProfileCreator(), "authorizationGenerators", getAuthorizationGenerators(), "realmName", this.realmName); } }
@Test public void testAuthentication() { final DirectBearerAuthClient client = new DirectBearerAuthClient(new SimpleTestTokenAuthenticator()); final MockWebContext context = MockWebContext.create(); context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, HttpConstants.BEARER_HEADER_PREFIX + TOKEN); final TokenCredentials credentials = client.getCredentials(context); final CommonProfile profile = (CommonProfile) client.getUserProfile(credentials, context); assertEquals(TOKEN, profile.getId()); }
@Test public void testHasDefaultProfileCreator() { final DirectBearerAuthClient bearerAuthClient = new DirectBearerAuthClient(new SimpleTestTokenAuthenticator()); bearerAuthClient.init(); }
@Test public void testMissingTokenAuthenticator() { final DirectBearerAuthClient bearerAuthClient = new DirectBearerAuthClient(null); TestsHelper.expectException(() -> bearerAuthClient.getCredentials(MockWebContext.create()), TechnicalException.class, "authenticator cannot be null"); }
@Test public void testMissingProfileCreator() { final DirectBearerAuthClient bearerAuthClient = new DirectBearerAuthClient(new SimpleTestTokenAuthenticator(), null); TestsHelper.expectException(() -> bearerAuthClient.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
public DirectBearerAuthClient(final Authenticator tokenAuthenticator) { defaultAuthenticator(tokenAuthenticator); }
@Override protected void clientInit() { assertNotBlank("realmName", this.realmName); defaultCredentialsExtractor(new BearerAuthExtractor()); }