@Test public void shouldFindUserByUsername() { stubFor(get(urlPathEqualTo("/api/users")) .withQueryParam("username", new EqualToPattern("johndoe")) .willReturn(okJson("{\"id\" : \"123456789\", \"username\" : \"johndoe\"}"))); TestObserver<User> testObserver = userProvider.findByUsername("johndoe").test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete(); testObserver.assertNoErrors(); testObserver.assertValue(u -> "123456789".equals(u.getId())); testObserver.assertValue(u -> "johndoe".equals(u.getUsername())); }
@Override public Maybe<User> findByUsername(String username) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); DefaultUser user = new DefaultUser(username); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration readResourceConfiguration = usersResourceConfiguration.getPaths().getReadResource(); final String readUserURI = usersResourceConfiguration.getBaseURL() + readResourceConfiguration.getBaseURL(); final HttpMethod readUserHttpMethod = HttpMethod.valueOf(readResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> readUserHttpHeaders = readResourceConfiguration.getHttpHeaders(); final String readUserBody = readResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, readUserURI, readUserHttpMethod, readUserHttpHeaders, readUserBody); return requestHandler .toMaybe() .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = readResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Maybe.error(ex); } LOGGER.error("An error has occurred while searching user {} from the remote HTTP identity provider", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while searching the user {}", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching the user", ex)); } }
HttpUserProvider implements UserProvider { @Override public Maybe<User> findByUsername(String username) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); DefaultUser user = new DefaultUser(username); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration readResourceConfiguration = usersResourceConfiguration.getPaths().getReadResource(); final String readUserURI = usersResourceConfiguration.getBaseURL() + readResourceConfiguration.getBaseURL(); final HttpMethod readUserHttpMethod = HttpMethod.valueOf(readResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> readUserHttpHeaders = readResourceConfiguration.getHttpHeaders(); final String readUserBody = readResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, readUserURI, readUserHttpMethod, readUserHttpHeaders, readUserBody); return requestHandler .toMaybe() .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = readResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Maybe.error(ex); } LOGGER.error("An error has occurred while searching user {} from the remote HTTP identity provider", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while searching the user {}", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching the user", ex)); } } }
HttpUserProvider implements UserProvider { @Override public Maybe<User> findByUsername(String username) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); DefaultUser user = new DefaultUser(username); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration readResourceConfiguration = usersResourceConfiguration.getPaths().getReadResource(); final String readUserURI = usersResourceConfiguration.getBaseURL() + readResourceConfiguration.getBaseURL(); final HttpMethod readUserHttpMethod = HttpMethod.valueOf(readResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> readUserHttpHeaders = readResourceConfiguration.getHttpHeaders(); final String readUserBody = readResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, readUserURI, readUserHttpMethod, readUserHttpHeaders, readUserBody); return requestHandler .toMaybe() .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = readResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Maybe.error(ex); } LOGGER.error("An error has occurred while searching user {} from the remote HTTP identity provider", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while searching the user {}", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching the user", ex)); } }  }
HttpUserProvider implements UserProvider { @Override public Maybe<User> findByUsername(String username) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); DefaultUser user = new DefaultUser(username); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration readResourceConfiguration = usersResourceConfiguration.getPaths().getReadResource(); final String readUserURI = usersResourceConfiguration.getBaseURL() + readResourceConfiguration.getBaseURL(); final HttpMethod readUserHttpMethod = HttpMethod.valueOf(readResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> readUserHttpHeaders = readResourceConfiguration.getHttpHeaders(); final String readUserBody = readResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, readUserURI, readUserHttpMethod, readUserHttpHeaders, readUserBody); return requestHandler .toMaybe() .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = readResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Maybe.error(ex); } LOGGER.error("An error has occurred while searching user {} from the remote HTTP identity provider", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while searching the user {}", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching the user", ex)); } }  @Override Maybe<User> findByUsername(String username); @Override Single<User> create(User user); @Override Single<User> update(String id, User updateUser); @Override Completable delete(String id); }
HttpUserProvider implements UserProvider { @Override public Maybe<User> findByUsername(String username) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); DefaultUser user = new DefaultUser(username); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration readResourceConfiguration = usersResourceConfiguration.getPaths().getReadResource(); final String readUserURI = usersResourceConfiguration.getBaseURL() + readResourceConfiguration.getBaseURL(); final HttpMethod readUserHttpMethod = HttpMethod.valueOf(readResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> readUserHttpHeaders = readResourceConfiguration.getHttpHeaders(); final String readUserBody = readResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, readUserURI, readUserHttpMethod, readUserHttpHeaders, readUserBody); return requestHandler .toMaybe() .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = readResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Maybe.error(ex); } LOGGER.error("An error has occurred while searching user {} from the remote HTTP identity provider", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while searching the user {}", username, ex); return Maybe.error(new TechnicalManagementException("An error has occurred while searching the user", ex)); } }  @Override Maybe<User> findByUsername(String username); @Override Single<User> create(User user); @Override Single<User> update(String id, User updateUser); @Override Completable delete(String id);  }