public void messageResolvers() { // tag::basic[] AuthenticationTokenResolver<HttpRequest> basicResolver = AuthenticationToken.httpBasicResolver(); // end::basic[] // tag::bearer[] AuthenticationTokenResolver<HttpRequest> bearerResolver = AuthenticationToken.httpBearerResolver(); // end::bearer[] }
@Override public Realm getContext(Class<?> type) { return Realm.builder() // .withResolver(AuthenticationToken.httpBasicResolver()) // <1> .withAuthenticator(Account.authenticator(getAccountProvider())) // <2> .withDefaultAuthorizer() // <3> .build(); }
public void contextResourceRealm() { // tag::realm2[] Context.get().classLoaderScope() // <1> .map(s -> s.put(Realm.CONTEXT_KEY, Realm.builder().withResolver(AuthenticationToken.httpBasicResolver()) .withAuthenticator(Account.authenticator(getAccountProvider())).withDefaultAuthorizer() .build())); // end::realm2[] }
public void basicresolver() { // tag::basicresolver[] AccountProvider accountProvider = getAccountProvider(); Realm realm = Realm.builder().withResolver(AuthenticationToken.httpBasicResolver()) // <1> .withAuthenticator(Account.authenticator(accountProvider)) // <2> .build(); // obtain the HttpRequest message, for example using a servlet request HttpRequest request = getHttpRequest(); try { Authentication authc = realm.authenticate(request); // <3> } catch (AuthenticationException e) { // handle authentication failures } // end::basicresolver[] }
public void configureJaxrsApplication() { AccountProvider provider = id -> { // <5> // a test provider wich always returns an Account with given id and s3cr3t as password return Optional.ofNullable(Account.builder(id).credentials(Credentials.builder().secret("s3cr3t").build()) .enabled(true).build()); }; Realm realm = Realm.builder() // <6> .withResolver(AuthenticationToken.httpBasicResolver()) // <7> .withAuthenticator(Account.authenticator(provider)) // <8> .withDefaultAuthorizer().build(); ContextResolver<Realm> realmContextResolver = new ContextResolver<Realm>() { // <9> @Override public Realm getContext(Class<?> type) { return realm; } }; register(realmContextResolver); // <10> } // end::auth[]