title: Authentication in spring cloud gateway
body: <p>I am newbie to spring cloud. I am trying to integrate spring cloud gateway(<strong>spring cloud Finchley.SR1</strong>) just to authenticate and route my requests.</p>
  <blockquote>
  <p>My Application stack is as follows</p>
  </blockquote>
  <ul>
  <li><strong>Main Dashboard Application</strong> built using spring mvc and angular. It has login page and a dashboard. Authentication is integrated in it which authenticates user credentials against database. I also use <strong>hazelcast</strong> for session replication in this app.</li>
  <li>Set of <strong>Downstream services</strong> which will be invoked once user logs into above dashboard and navigates inside it.</li>
  <li>An <strong>API Gateway</strong> built using spring cloud gateway: For now it does only routing.</li>
  </ul>
  <pre><code>  cloud:
      gateway:
        routes:
          - id: customers
            uri: http://localhost:8282/customers
            predicates:
            - Path=/customers/**
            - Header=employeeId, \d+
            filters:
            - RewritePath=/customers/(?&lt;segment&gt;.*), /$\{segment}
          - id: rates
            uri: http://localhost:8383/rates
            predicates:
            - Path=/rates/**
            filters:
            - RewritePath=/rates/(?&lt;segment&gt;.*), /$\{segment}
  </code></pre>
  <blockquote>
  <p>Need to implement following</p>
  </blockquote>
  <ul>
  <li><em>First request will come to gateway I need to check if user is authenticated or not, if not authenticated then I need to show login page of Dashboard Application(i.e first app) or else allow user to proceed.</em></li>
  <li>Once user logged in and navigating inside dashboard then api requests to downstream services will also go through <strong>api gateway</strong> I need authenticate these requests as well and send 403 status if user is not authenticated.</li>
  </ul>
  <blockquote>
  <p>I am not able to figure out how to handle these authentications in <strong>spring cloud gateway app</strong>. Is it possible to leverage hazelcast session replication that I added in <strong>Main Dashboard App</strong>, use it validate the user in gateway?</p>
  </blockquote>
  <blockquote>
  <p>Or is there any better approach using spring cloud suite tools that I can use it here. A sample app will be useful</p>
  </blockquote>