io.vertx.rxjava.ext.web.handler.SimpleAuthenticationHandler Maven / Gradle / Ivy
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.vertx.rxjava.ext.web.handler;
import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;
/**
 * A user customizable authentication handler.
 * 
 * An auth handler allows your application to provide authentication support. The handler is not fully functional
 * without a authentication function. This function takes the  as input and returns a .
 *
 * The future should return a non null user object. In the {@link io.vertx.rxjava.ext.web.handler.SimpleAuthenticationHandler#authenticate} you have full control
 * on the request, so all operations like redirect, next, fail are allowed. There are some rules that need to be followed
 * in order to allow this handler to properly interop with {@link io.vertx.rxjava.ext.web.handler.ChainAuthHandler}.
 *
 * 
 * NOTE: This class has been automatically generated from the {@link io.vertx.ext.web.handler.SimpleAuthenticationHandler original} non RX-ified interface using Vert.x codegen.
 */
@RxGen(io.vertx.ext.web.handler.SimpleAuthenticationHandler.class)
public class SimpleAuthenticationHandler implements io.vertx.rxjava.ext.web.handler.AuthenticationHandler, Handler {
  @Override
  public String toString() {
    return delegate.toString();
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    SimpleAuthenticationHandler that = (SimpleAuthenticationHandler) o;
    return delegate.equals(that.delegate);
  }
  
  @Override
  public int hashCode() {
    return delegate.hashCode();
  }
  public static final TypeArg __TYPE_ARG = new TypeArg<>(    obj -> new SimpleAuthenticationHandler((io.vertx.ext.web.handler.SimpleAuthenticationHandler) obj),
    SimpleAuthenticationHandler::getDelegate
  );
  private final io.vertx.ext.web.handler.SimpleAuthenticationHandler delegate;
  
  public SimpleAuthenticationHandler(io.vertx.ext.web.handler.SimpleAuthenticationHandler delegate) {
    this.delegate = delegate;
  }
  public SimpleAuthenticationHandler(Object delegate) {
    this.delegate = (io.vertx.ext.web.handler.SimpleAuthenticationHandler)delegate;
  }
  public io.vertx.ext.web.handler.SimpleAuthenticationHandler getDelegate() {
    return delegate;
  }
  /**
   * Something has happened, so handle it.
   * @param event the event to handle
   */
  public void handle(io.vertx.rxjava.ext.web.RoutingContext event) { 
    delegate.handle(event.getDelegate());
  }
  /**
   * Creates a new instance of the simple authentication handler.
   * @return a new instance.
   */
  public static io.vertx.rxjava.ext.web.handler.SimpleAuthenticationHandler create() { 
    io.vertx.rxjava.ext.web.handler.SimpleAuthenticationHandler ret = io.vertx.rxjava.ext.web.handler.SimpleAuthenticationHandler.newInstance((io.vertx.ext.web.handler.SimpleAuthenticationHandler)io.vertx.ext.web.handler.SimpleAuthenticationHandler.create());
    return ret;
  }
  /**
   * This function will allow you to perform authentication the way you intended to. The process should be self
   * explanatory, for example if the request contains a given property completing the function with a non null
   *  object is enough to allow the handler to continue.
   *
   * In order to signal errors, you should not call  or .
   *
   * Errors should be signaled using the {@link io.vertx.ext.web.handler.HttpException} type. Any other kind of errors will be wrapped as a 401
   * error. For example forbidden access should be signaled with: new HttpException(403). This is required when
   * working with {@link io.vertx.rxjava.ext.web.handler.ChainAuthHandler}. By using exceptions to signal failures instead of immediately terminating
   * the request, it allows the chain to proceed to the next handler if needed.
   * @param authenticationFunction the authentication function.
   * @return self
   */
  public io.vertx.rxjava.ext.web.handler.SimpleAuthenticationHandler authenticate(java.util.function.Function> authenticationFunction) { 
    delegate.authenticate(new Function>() {
      public io.vertx.core.Future apply(io.vertx.ext.web.RoutingContext arg) {
        io.vertx.core.Future ret = authenticationFunction.apply(io.vertx.rxjava.ext.web.RoutingContext.newInstance((io.vertx.ext.web.RoutingContext)arg));
        return ret.map(val -> val.getDelegate());
      }
    });
    return this;
  }
  public static SimpleAuthenticationHandler newInstance(io.vertx.ext.web.handler.SimpleAuthenticationHandler arg) {
    return arg != null ? new SimpleAuthenticationHandler(arg) : null;
  }
}
          © 2015 - 2025 Weber Informatics LLC | Privacy Policy