Codota Logo
CorsHandler.allowCredentials
Code IndexAdd Codota to your IDE (free)

How to use
allowCredentials
method
in
io.vertx.ext.web.handler.CorsHandler

Best Java code snippets using io.vertx.ext.web.handler.CorsHandler.allowCredentials (Showing top 20 results out of 315)

  • Common ways to obtain CorsHandler
private void myMethod () {
CorsHandler c =
  • Codota IconCorsHandler corsHandler;corsHandler.maxAgeSeconds(maxAgeSeconds)
  • Smart code suggestions by Codota
}
origin: vert-x3/vertx-web

@Test
public void testUnsecureCorsShouldNotBeAllowed() throws Exception {
 try {
  CorsHandler.create("*").allowCredentials(true);
  fail("Should not be allowed!");
 } catch (IllegalStateException e) {
  // OK
 }
}
origin: io.vertx/vertx-rx-java

/**
 * Set whether credentials are allowed. Note that user agents will block
 * requests that use a wildcard as origin and include credentials.
 *
 * From the MDN documentation you can read:
 *
 * <blockquote>
 * Important note: when responding to a credentialed request,
 * server must specify a domain, and cannot use wild carding.
 * </blockquote>
 * @param allow true if allowed
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.handler.CorsHandler allowCredentials(boolean allow) { 
 delegate.allowCredentials(allow);
 return this;
}
origin: vert-x3/vertx-rx

/**
 * Set whether credentials are allowed. Note that user agents will block
 * requests that use a wildcard as origin and include credentials.
 *
 * From the MDN documentation you can read:
 *
 * <blockquote>
 * Important note: when responding to a credentialed request,
 * server must specify a domain, and cannot use wild carding.
 * </blockquote>
 * @param allow true if allowed
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.handler.CorsHandler allowCredentials(boolean allow) { 
 delegate.allowCredentials(allow);
 return this;
}
origin: vert-x3/vertx-web

@Test
public void testRealRequestAllowCredentials() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "vertx.io", null, null, null, "true", null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testRealRequestCredentialsNoWildcardOrigin() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx.*").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "vertx.io", null, null, null, "true", null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testPreflightAllowCredentialsNoWildcardOrigin() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 // Make sure * isn't returned in access-control-allow-origin for credentials
 router.route().handler(CorsHandler.create("vertx.*").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", null, null, "true", null), 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testPreflightAllowCredentials() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", null, null, "true", null), 200, "OK", null);
}
origin: apache/servicecomb-java-chassis

/**
 * Support CORS
 */
void mountCorsHandler(Router mainRouter) {
 if (!TransportConfig.isCorsEnabled()) {
  return;
 }
 CorsHandler corsHandler = getCorsHandler(TransportConfig.getCorsAllowedOrigin());
 // Access-Control-Allow-Credentials
 corsHandler.allowCredentials(TransportConfig.isCorsAllowCredentials());
 // Access-Control-Allow-Headers
 corsHandler.allowedHeaders(TransportConfig.getCorsAllowedHeaders());
 // Access-Control-Allow-Methods
 Set<String> allowedMethods = TransportConfig.getCorsAllowedMethods();
 for (String method : allowedMethods) {
  corsHandler.allowedMethod(HttpMethod.valueOf(method));
 }
 // Access-Control-Expose-Headers
 corsHandler.exposedHeaders(TransportConfig.getCorsExposedHeaders());
 // Access-Control-Max-Age
 int maxAge = TransportConfig.getCorsMaxAge();
 if (maxAge >= 0) {
  corsHandler.maxAgeSeconds(maxAge);
 }
 LOGGER.info("mount CorsHandler");
 mainRouter.route().handler(corsHandler);
}
origin: zandero/rest.vertx

/**
 * Enables CORS
 *
 * @param allowedOriginPattern allowed origin
 * @param allowCredentials     allow credentials (true/false)
 * @param maxAge               in seconds
 * @param allowedHeaders       set of allowed headers
 * @param methods              list of methods ... if empty all methods are allowed  @return self
 * @return self
 */
public RestBuilder enableCors(String allowedOriginPattern,
               boolean allowCredentials,
               int maxAge,
               Set<String> allowedHeaders,
               HttpMethod... methods) {
  corsHandler = CorsHandler.create(allowedOriginPattern)
               .allowCredentials(allowCredentials)
               .maxAgeSeconds(maxAge);
  if (methods == null || methods.length == 0) { // if not given than all
    methods = HttpMethod.values();
  }
  for (HttpMethod method : methods) {
    corsHandler.allowedMethod(method);
  }
  if (allowedHeaders.size() > 0) {
    corsHandler.allowedHeaders(allowedHeaders);
  }
  return this;
}
origin: io.vertx/vertx-web

@Test
public void testUnsecureCorsShouldNotBeAllowed() throws Exception {
 try {
  CorsHandler.create("*").allowCredentials(true);
  fail("Should not be allowed!");
 } catch (IllegalStateException e) {
  // OK
 }
}
origin: zyclonite/nassh-relay

@Override
public void start(final Future<Void> startFuture) {
  final JsonObject config = config().getJsonObject("webservice");
  server = vertx.createHttpServer();
  final Router router = Router.router(vertx);
  router.route().handler(CorsHandler
    .create(".*")
    .allowCredentials(true)
  );
  router.route().handler(io.vertx.ext.web.handler.CookieHandler.create());
  router.get("/cookie").handler(new CookieHandler(config().getJsonObject("application").copy().put("auth", config().getJsonObject("google-sso"))));
  router.post("/cookie").handler(new CookiePostHandler(vertx, new JsonObject().put("auth", config().getJsonObject("google-sso"))));
  router.get("/proxy").handler(new ProxyHandler(vertx, config()));
  router.get("/write").handler(new WriteHandler(vertx));
  router.get("/read").handler(new ReadHandler(vertx));
  server.requestHandler(router);
  server.websocketHandler(new ConnectHandler(vertx));
  server.listen(config.getInteger("port", 8022), config.getString("hostname", "localhost"),
    result -> {
      if (result.succeeded()) {
        logger.info("nassh-relay listening on port " + result.result().actualPort());
        startFuture.complete();
      } else {
        startFuture.fail(result.cause());
      }
    }
  );
}
origin: zandero/rest.vertx

/**
 * @param router               to add handler to
 * @param allowedOriginPattern origin pattern
 * @param allowCredentials     allowed credentials
 * @param maxAge               in seconds
 * @param allowedHeaders       set of headers or null for none
 * @param methods              list of methods or empty for all
 */
public void enableCors(Router router,
            String allowedOriginPattern,
            boolean allowCredentials,
            int maxAge,
            Set<String> allowedHeaders,
            HttpMethod... methods) {
  CorsHandler handler = CorsHandler.create(allowedOriginPattern)
                   .allowCredentials(allowCredentials)
                   .maxAgeSeconds(maxAge);
  if (methods == null || methods.length == 0) { // if not given than all
    methods = HttpMethod.values();
  }
  for (HttpMethod method : methods) {
    handler.allowedMethod(method);
  }
  handler.allowedHeaders(allowedHeaders);
  router.route().handler(handler).order(ORDER_CORS_HANDLER);
}
origin: io.vertx/vertx-web

@Test
public void testRealRequestCredentialsNoWildcardOrigin() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx.*").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "vertx.io", null, null, null, "true", null), 200, "OK", null);
}
origin: io.vertx/vertx-web

@Test
public void testRealRequestAllowCredentials() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.GET, "/", req -> req.headers().add("origin", "vertx.io"), resp -> checkHeaders(resp, "vertx.io", null, null, null, "true", null), 200, "OK", null);
}
origin: io.vertx/vertx-web

@Test
public void testPreflightAllowCredentialsNoWildcardOrigin() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 // Make sure * isn't returned in access-control-allow-origin for credentials
 router.route().handler(CorsHandler.create("vertx.*").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", null, null, "true", null), 200, "OK", null);
}
origin: io.vertx/vertx-web

@Test
public void testPreflightAllowCredentials() throws Exception {
 Set<HttpMethod> allowedMethods = new LinkedHashSet<>(Arrays.asList(HttpMethod.PUT, HttpMethod.DELETE));
 router.route().handler(CorsHandler.create("vertx\\.io").allowedMethods(allowedMethods).allowCredentials(true));
 router.route().handler(context -> context.response().end());
 testRequest(HttpMethod.OPTIONS, "/", req -> {
  req.headers().add("origin", "vertx.io");
  req.headers().add("access-control-request-method", "PUT,DELETE");
 }, resp -> checkHeaders(resp, "vertx.io", "PUT,DELETE", null, null, "true", null), 200, "OK", null);
}
origin: org.apache.servicecomb/transport-rest-vertx

/**
 * Support CORS
 */
void mountCorsHandler(Router mainRouter) {
 if (!TransportConfig.isCorsEnabled()) {
  return;
 }
 CorsHandler corsHandler = getCorsHandler(TransportConfig.getCorsAllowedOrigin());
 // Access-Control-Allow-Credentials
 corsHandler.allowCredentials(TransportConfig.isCorsAllowCredentials());
 // Access-Control-Allow-Headers
 corsHandler.allowedHeaders(TransportConfig.getCorsAllowedHeaders());
 // Access-Control-Allow-Methods
 Set<String> allowedMethods = TransportConfig.getCorsAllowedMethods();
 for (String method : allowedMethods) {
  corsHandler.allowedMethod(HttpMethod.valueOf(method));
 }
 // Access-Control-Expose-Headers
 corsHandler.exposedHeaders(TransportConfig.getCorsExposedHeaders());
 // Access-Control-Max-Age
 int maxAge = TransportConfig.getCorsMaxAge();
 if (maxAge >= 0) {
  corsHandler.maxAgeSeconds(maxAge);
 }
 LOGGER.info("mount CorsHandler");
 mainRouter.route().handler(corsHandler);
}
origin: georocket/georocket

corsHandler.allowCredentials(true);
origin: cn.vertxup/vertx-up

.order(Orders.CORS)
.handler(CorsHandler.create("*")
    .allowCredentials(false)
    .allowedHeaders(new HashSet<String>() {
origin: silentbalanceyh/vertx-zero

.order(Orders.CORS)
.handler(CorsHandler.create("*")
    .allowCredentials(false)
    .allowedHeaders(new HashSet<String>() {
io.vertx.ext.web.handlerCorsHandlerallowCredentials

Javadoc

Set whether credentials are allowed. Note that user agents will block requests that use a wildcard as origin and include credentials. From the MDN documentation you can read:
Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding.

Popular methods of CorsHandler

  • create
    Create a CORS handler
  • allowedHeaders
    Add a set of allowed headers
  • allowedMethod
    Add an allowed method
  • allowedMethods
    Add a set of allowed methods
  • maxAgeSeconds
    Set how long the browser should cache the information
  • allowedHeader
    Add an allowed header
  • exposedHeader
    Add an exposed header
  • exposedHeaders
    Add a set of exposed headers
  • handle

Popular in Java

  • Running tasks concurrently on multiple threads
  • onRequestPermissionsResult (Fragment)
  • getSharedPreferences (Context)
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • Menu (java.awt)
  • IOException (java.io)
    Signals that an I/O exception of some sort has occurred. This class is the general class of exceptio
  • InputStreamReader (java.io)
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • Locale (java.util)
    A Locale object represents a specific geographical, political, or cultural region. An operation that
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now