use of com.networknt.status.Status in project light-rest-4j by networknt.
the class JwtVerifyHandlerTest method testUnmatchedScopeInIdToken.
@Test
public void testUnmatchedScopeInIdToken() throws Exception {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI("http://localhost:8080"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/v1/pets/111").setMethod(Methods.GET);
request.getRequestHeaders().put(Headers.AUTHORIZATION, "Bearer eyJraWQiOiIxMDAiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ1cm46Y29tOm5ldHdvcmtudDpvYXV0aDI6djEiLCJhdWQiOiJ1cm46Y29tLm5ldHdvcmtudCIsImV4cCI6MTgwNTEzNjU1MSwianRpIjoiTVJiZHdlQ295eG13a2ZUM3lVWGloQSIsImlhdCI6MTQ4OTc3NjU1MSwibmJmIjoxNDg5Nzc2NDMxLCJ2ZXJzaW9uIjoiMS4wIiwidXNlcl9pZCI6ImVyaWMiLCJ1c2VyX3R5cGUiOiJFTVBMT1lFRSIsImNsaWVudF9pZCI6ImY3ZDQyMzQ4LWM2NDctNGVmYi1hNTJkLTRjNTc4NzQyMWU3MiIsInNjb3BlIjpbIkFUTVAxMDAwLnciLCJBVE1QMTAwMC5yIl19.VOEggO6UIMHNJLrxShGivCh7sGyHiz7h9FqDjlKwywGP9xKbVTTODy2-FitUaS1Y2vjiHlJ0TNyxmj1SO11YwYnJlW1zn-6vfKWKI70DyvRwsvSX_8Z2fj0jPUiBqezwKRtLCHSsmiEpMrW6YQHYw0qzZ9kkMhiH2uFpZNCekOQWL1piRn1xVQkUmeFiTDvJQESHadFzw-9x0klO7-SxgKeHHDroxnpbLv2j795oMTB1gM_wJP6HO_M-gK6N1Uh6zssfnbyFReRNWkhZFOp3Y8DvwpfKhqXIVGUc_5WsO9M-y66icClVNl5zwLSmjsrNtqZkmeBCwQ6skBnRLfMocQ");
connection.sendRequest(request, client.createClientCallback(reference, latch));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
Assert.assertEquals(403, statusCode);
if (statusCode == 403) {
Status status = Config.getInstance().getMapper().readValue(reference.get().getAttachment(Http2Client.RESPONSE_BODY), Status.class);
Assert.assertNotNull(status);
Assert.assertEquals("ERR10005", status.getCode());
}
}
use of com.networknt.status.Status in project light-rest-4j by networknt.
the class RequestValidator method validateRequest.
/**
* Validate the request against the given API operation
* @param requestPath normalised path
* @param exchange The HttpServerExchange to validate
* @param openApiOperation OpenAPI operation
* @return A validation report containing validation errors
*/
public Status validateRequest(final NormalisedPath requestPath, HttpServerExchange exchange, OpenApiOperation openApiOperation) {
requireNonNull(requestPath, "A request path is required");
requireNonNull(exchange, "An exchange is required");
requireNonNull(openApiOperation, "An OpenAPI operation is required");
Status status = validatePathParameters(requestPath, openApiOperation);
if (status != null)
return status;
status = validateQueryParameters(exchange, openApiOperation);
if (status != null)
return status;
status = validateHeader(exchange, openApiOperation);
if (status != null)
return status;
Object body = exchange.getAttachment(BodyHandler.REQUEST_BODY);
status = validateRequestBody(body, openApiOperation);
return status;
}
use of com.networknt.status.Status in project light-rest-4j by networknt.
the class SchemaValidator method doValidate.
private Status doValidate(final Object value, final JsonNode schema) {
requireNonNull(schema, "A schema is required");
Status status = null;
Set<ValidationMessage> processingReport = null;
try {
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schema);
final JsonNode content = Config.getInstance().getMapper().valueToTree(value);
processingReport = jsonSchema.validate(content);
} catch (Exception e) {
e.printStackTrace();
}
if (processingReport != null && processingReport.size() > 0) {
ValidationMessage vm = processingReport.iterator().next();
status = new Status(VALIDATOR_SCHEMA, vm.getMessage());
}
return status;
}
use of com.networknt.status.Status in project light-4j by networknt.
the class FailbackRegistry method register.
@Override
public void register(URL url) {
failedRegistered.remove(url);
failedUnregistered.remove(url);
try {
super.register(url);
} catch (Exception e) {
if (isCheckingUrls(getUrl(), url)) {
throw new FrameworkException(new Status(REGISTER_ERROR, registryClassName, url, getUrl()), e);
}
failedRegistered.add(url);
}
}
use of com.networknt.status.Status in project light-4j by networknt.
the class CommandServiceManager method notifyService.
@Override
public void notifyService(URL serviceUrl, URL registryUrl, List<URL> urls) {
if (registry == null) {
throw new FrameworkException(new Status(REGISTRY_IS_NULL));
}
URL urlCopy = serviceUrl.createCopy();
String groupName = urlCopy.getParameter(URLParamType.group.getName(), URLParamType.group.getValue());
groupServiceCache.put(groupName, urls);
List<URL> finalResult = new ArrayList<URL>();
if (logger.isInfoEnabled())
logger.info("command cache is null. service:" + serviceUrl.toSimpleString());
// if no command cache, return group
finalResult.addAll(discoverOneGroup(refUrl));
for (NotifyListener notifyListener : notifySet) {
notifyListener.notify(registry.getUrl(), finalResult);
}
}
Aggregations