List of usage examples for io.vertx.core.json JsonObject getString
public String getString(String key)
From source file:io.github.cdelmas.spike.vertx.infrastructure.auth.FacebookOauthTokenVerifier.java
License:Apache License
@Override public void authenticate(JsonObject credentials, Handler<AsyncResult<User>> resultHandler) { String token = credentials.getString("token"); httpClient.getAbs("https://graph.facebook.com:443/v2.4/me?access_token=" + token) .handler(response -> response.bodyHandler(buffer -> { JsonObject json = new JsonObject(buffer.toString()); if (response.statusCode() != 200) { String message = json.getJsonObject("error").getString("message"); resultHandler.handle(Future.failedFuture(message)); } else { resultHandler.handle(Future.succeededFuture( new MyUser(Long.parseLong(json.getString("id")), json.getString("name"), token))); }//from w ww.j av a 2s .co m })).exceptionHandler(error -> resultHandler.handle(Future.failedFuture(error.getMessage()))).end(); }
From source file:io.gravitee.am.gateway.handler.vertx.auth.provider.ClientAuthenticationProvider.java
License:Apache License
@Override public void authenticate(JsonObject credentials, Handler<AsyncResult<User>> authHandler) { String clientId = credentials.getString(USERNAME_FIELD); String clientSecret = credentials.getString(PASSWORD_FIELD); logger.debug("Trying to authenticate a client: clientId[{}]", clientId); clientService.findByClientId(clientId).subscribe(client -> { if (client.getClientSecret().equals(clientSecret)) { authHandler.handle(Future.succeededFuture(new Client(client))); } else {/* w w w .j av a 2 s . c om*/ authHandler.handle(Future.failedFuture(new BadClientCredentialsException())); } }, error -> { logger.error("Unexpected error while looking for a client: clientId[{}]", clientId, error); authHandler.handle(Future.failedFuture(error)); }, () -> authHandler.handle(Future.failedFuture(new BadClientCredentialsException()))); }
From source file:io.gravitee.am.gateway.handler.vertx.auth.provider.OAuth2ClientAuthenticationProvider.java
License:Apache License
@Override public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) { identityProviderManager.get(authInfo.getString(PROVIDER_PARAMETER)).flatMap(authenticationProvider -> { String username = authInfo.getString(USERNAME_PARAMETER); String password = authInfo.getString(PASSWORD_PARAMETER); EndUserAuthentication endUserAuthentication = new EndUserAuthentication(username, password); endUserAuthentication.setAdditionalInformation(Collections.singletonMap(OAuth2Constants.REDIRECT_URI, authInfo.getString(OAuth2Constants.REDIRECT_URI))); return authenticationProvider.loadUserByUsername(endUserAuthentication); }).switchIfEmpty(Maybe.error(new BadCredentialsException())).flatMapSingle(user -> { // set source and client for the current authenticated end-user Map<String, Object> additionalInformation = user.getAdditionalInformation() == null ? new HashMap<>() : new HashMap<>(user.getAdditionalInformation()); additionalInformation.put("source", authInfo.getString(PROVIDER_PARAMETER)); additionalInformation.put(OAuth2Constants.CLIENT_ID, authInfo.getString(OAuth2Constants.CLIENT_ID)); ((DefaultUser) user).setAdditonalInformation(additionalInformation); return userService.findOrCreate(user); }).subscribe(//from w w w. jav a 2 s . c om user -> resultHandler.handle( Future.succeededFuture(new io.gravitee.am.gateway.handler.vertx.auth.user.User(user))), error -> { logger.error("Unable to authenticate oauth2 provider", error); resultHandler.handle(Future.failedFuture(error)); }); }
From source file:io.gravitee.am.gateway.handler.vertx.auth.provider.UserAuthenticationProvider.java
License:Apache License
@Override public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) { String username = authInfo.getString(USERNAME_PARAMETER); String password = authInfo.getString(PASSWORD_PARAMETER); String clientId = authInfo.getString(OAuth2Constants.CLIENT_ID); userAuthenticationManager.authenticate(clientId, new EndUserAuthentication(username, password)).subscribe( user -> resultHandler.handle( Future.succeededFuture(new io.gravitee.am.gateway.handler.vertx.auth.user.User(user))), error -> resultHandler.handle(Future.failedFuture(error))); }
From source file:io.gravitee.am.identityprovider.github.authentication.GithubAuthenticationProvider.java
License:Apache License
private User createUser(JsonObject jsonObject) { User user = new DefaultUser(jsonObject.getString(GithubUser.LOGIN)); // set additional information Map<String, Object> additionalInformation = new HashMap<>(); additionalInformation.put("sub", jsonObject.getValue(GithubUser.LOGIN)); additionalInformation.put(GithubUser.AVATAR_URL, jsonObject.getValue(GithubUser.AVATAR_URL)); additionalInformation.put(GithubUser.GRAVATAR_ID, jsonObject.getValue(GithubUser.GRAVATAR_ID)); additionalInformation.put(GithubUser.URL, jsonObject.getValue(GithubUser.URL)); additionalInformation.put(GithubUser.HTML_URL, jsonObject.getValue(GithubUser.HTML_URL)); additionalInformation.put(GithubUser.FOLLOWERS_URL, jsonObject.getValue(GithubUser.FOLLOWERS_URL)); additionalInformation.put(GithubUser.FOLLOWING_URL, jsonObject.getValue(GithubUser.FOLLOWING_URL)); additionalInformation.put(GithubUser.GISTS_URL, jsonObject.getValue(GithubUser.GISTS_URL)); additionalInformation.put(GithubUser.STARRED_URL, jsonObject.getValue(GithubUser.STARRED_URL)); additionalInformation.put(GithubUser.SUBSCRIPTIONS_URL, jsonObject.getValue(GithubUser.SUBSCRIPTIONS_URL)); additionalInformation.put(GithubUser.ORGANIZATIONS_URL, jsonObject.getValue(GithubUser.ORGANIZATIONS_URL)); additionalInformation.put(GithubUser.REPOS_URL, jsonObject.getValue(GithubUser.REPOS_URL)); additionalInformation.put(GithubUser.EVENTS_URL, jsonObject.getValue(GithubUser.EVENTS_URL)); additionalInformation.put(GithubUser.RECEIVED_EVENTS_URL, jsonObject.getValue(GithubUser.RECEIVED_EVENTS_URL)); additionalInformation.put(GithubUser.SITE_ADMIN, jsonObject.getBoolean(GithubUser.SITE_ADMIN)); additionalInformation.put(GithubUser.NAME, jsonObject.getValue(GithubUser.NAME)); additionalInformation.put(GithubUser.COMPANY, jsonObject.getValue(GithubUser.COMPANY)); additionalInformation.put(GithubUser.LOCATION, jsonObject.getValue(GithubUser.LOCATION)); additionalInformation.put(GithubUser.EMAIL, jsonObject.getValue(GithubUser.EMAIL)); additionalInformation.put(GithubUser.PUBLIC_REPOS, jsonObject.getValue(GithubUser.PUBLIC_REPOS)); additionalInformation.put(GithubUser.PUBLIC_GISTS, jsonObject.getValue(GithubUser.PUBLIC_GISTS)); additionalInformation.put(GithubUser.FOLLOWERS, jsonObject.getValue(GithubUser.FOLLOWERS)); additionalInformation.put(GithubUser.FOLLOWING, jsonObject.getValue(GithubUser.FOLLOWING)); additionalInformation.put(GithubUser.LOCATION, jsonObject.getValue(GithubUser.LOCATION)); additionalInformation.put(GithubUser.EMAIL, jsonObject.getValue(GithubUser.EMAIL)); ((DefaultUser) user).setAdditonalInformation(additionalInformation); return user;//from w w w . jav a 2 s .c o m }
From source file:io.gravitee.am.identityprovider.oauth2.authentication.OAuth2GenericAuthenticationProvider.java
License:Apache License
private Maybe<String> authenticate(Authentication authentication) { return io.reactivex.Maybe.create(emitter -> { // prepare body request parameters List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId())); urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret())); urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI))); urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials())); urlParameters.add(new BasicNameValuePair(GRANT_TYPE, "authorization_code")); String bodyRequest = URLEncodedUtils.format(urlParameters); URI requestUri = URI.create(configuration.getAccessTokenUri()); final int port = requestUri.getPort() != -1 ? requestUri.getPort() : (HTTPS_SCHEME.equals(requestUri.getScheme()) ? 443 : 80); boolean ssl = HTTPS_SCHEME.equalsIgnoreCase(requestUri.getScheme()); HttpClientRequest request = client.post(new RequestOptions().setHost(requestUri.getHost()).setPort(port) .setSsl(ssl).setURI(requestUri.toString()), response -> { if (response.statusCode() != 200) { emitter.onError(new BadCredentialsException(response.statusMessage())); } else { response.bodyHandler(body -> { JsonObject bodyResponse = body.toJsonObject(); emitter.onSuccess(bodyResponse.getString("access_token")); });/*from w w w . j a v a 2 s .c o m*/ } }).setChunked(true).putHeader(HttpHeaders.CONTENT_TYPE, URLEncodedUtils.CONTENT_TYPE); request.write(bodyRequest); request.end(); }); }
From source file:io.gravitee.am.identityprovider.oauth2.authentication.OAuth2GenericAuthenticationProvider.java
License:Apache License
private User createUser(JsonObject jsonNode) { User user = new DefaultUser(jsonNode.getString(CLAIMS_SUB)); // set additional information Map<String, Object> additionalInformation = new HashMap<>(); additionalInformation.put(CLAIMS_SUB, jsonNode.getValue(CLAIMS_SUB)); if (this.mapper.getMappers() != null) { this.mapper.getMappers().forEach((k, v) -> { if (jsonNode.getValue(v) != null) { additionalInformation.put(k, jsonNode.getValue(v)); }/*from w w w . ja v a2s . co m*/ }); } ((DefaultUser) user).setAdditonalInformation(additionalInformation); return user; }
From source file:io.helixservice.feature.health.HealthController.java
License:Open Source License
private void parseJsonVersionFile(JsonObject json) { this.commitId = json.getString(GIT_COMMIT_ID); this.remoteUrl = json.getString(GIT_REMOTE_URL); this.appVersion = json.getString(NAMED_APP_VERSION); }
From source file:io.knotx.adapter.common.http.HttpAdapterConfiguration.java
License:Apache License
public HttpAdapterConfiguration(JsonObject config) { address = config.getString("address"); services = config.getJsonArray("services").stream().map(item -> (JsonObject) item).map(item -> { ServiceMetadata metadata = new ServiceMetadata(); metadata.path = item.getString("path"); metadata.domain = item.getString("domain"); metadata.port = item.getInteger("port"); metadata.allowedRequestHeaderPatterns = item.getJsonArray("allowedRequestHeaders", new JsonArray()) .stream().map(object -> (String) object).map(new StringToPatternFunction()) .collect(Collectors.toList()); return metadata; }).collect(Collectors.toList()); clientOptions = config.getJsonObject("clientOptions", new JsonObject()); }
From source file:io.knotx.adapter.common.http.HttpClientFacade.java
License:Apache License
/** * Method responsible for building request to the service. * <br>/*from w ww . j av a 2 s. com*/ * <br> * The responsibility of the method is to build ClientRequest based on the original Http * Request<br> * - It must set path property of the request based on the params<br> * - It might set headers of the request if needed.<br> * <br> * In case of headers created modified in this method, ensure that your service configuration * allows passing those headers to the target service. See 'allowedRequestHeaders' section * of the configuration <br> * * @param originalRequest - ClientRequest representing original request comming to the Knot.x * @param params - JsonObject of the params to be used to build request. * @return ClientRequest representing Http request to the target service */ protected ClientRequest buildServiceRequest(ClientRequest originalRequest, JsonObject params) { return new ClientRequest(originalRequest) .setPath(UriTransformer.resolveServicePath(params.getString(PATH_PROPERTY_KEY), originalRequest)); }