(credentials: any) => AuthResult
| Authentication is successful with given credentials, allow request to pass through |
+| [authenticated](./kibana-plugin-server.authtoolkit.authenticated.md) | (state: object) => AuthResult
| Authentication is successful with given credentials, allow request to pass through |
| [redirected](./kibana-plugin-server.authtoolkit.redirected.md) | (url: string) => AuthResult
| Authentication requires to interrupt request handling and redirect to a configured url |
| [rejected](./kibana-plugin-server.authtoolkit.rejected.md) | (error: Error, options?: {`` statusCode?: number;`` }) => AuthResult
| Authentication is unsuccessful, fail the request with specified error. |
diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.http.md b/docs/development/core/server/kibana-plugin-server.coresetup.http.md
index 8c547ca2a42a9..8cb25af29e4ba 100644
--- a/docs/development/core/server/kibana-plugin-server.coresetup.http.md
+++ b/docs/development/core/server/kibana-plugin-server.coresetup.http.md
@@ -8,8 +8,9 @@
```typescript
http: {
+ registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];
registerAuth: HttpServiceSetup['registerAuth'];
- registerOnRequest: HttpServiceSetup['registerOnRequest'];
+ registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
getBasePathFor: HttpServiceSetup['getBasePathFor'];
setBasePathFor: HttpServiceSetup['setBasePathFor'];
};
diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.md b/docs/development/core/server/kibana-plugin-server.coresetup.md
index fe6d3ee71edc8..7b46817842def 100644
--- a/docs/development/core/server/kibana-plugin-server.coresetup.md
+++ b/docs/development/core/server/kibana-plugin-server.coresetup.md
@@ -17,5 +17,5 @@ export interface CoreSetup
| Property | Type | Description |
| --- | --- | --- |
| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | {`` adminClient$: Observable<ClusterClient>;`` dataClient$: Observable<ClusterClient>;`` }
| |
-| [http](./kibana-plugin-server.coresetup.http.md) | {`` registerAuth: HttpServiceSetup['registerAuth'];`` registerOnRequest: HttpServiceSetup['registerOnRequest'];`` getBasePathFor: HttpServiceSetup['getBasePathFor'];`` setBasePathFor: HttpServiceSetup['setBasePathFor'];`` }
| |
+| [http](./kibana-plugin-server.coresetup.http.md) | {`` registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];`` registerAuth: HttpServiceSetup['registerAuth'];`` registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];`` getBasePathFor: HttpServiceSetup['getBasePathFor'];`` setBasePathFor: HttpServiceSetup['setBasePathFor'];`` }
| |
diff --git a/docs/development/core/server/kibana-plugin-server.kibanarequest.md b/docs/development/core/server/kibana-plugin-server.kibanarequest.md
index f7f7707b5657e..f93e4c073eb21 100644
--- a/docs/development/core/server/kibana-plugin-server.kibanarequest.md
+++ b/docs/development/core/server/kibana-plugin-server.kibanarequest.md
@@ -20,6 +20,7 @@ export declare class KibanaRequeststring
| |
| [query](./kibana-plugin-server.kibanarequest.query.md) | | Query
| |
+| [url](./kibana-plugin-server.kibanarequest.url.md) | | Url
| |
## Methods
diff --git a/docs/development/core/server/kibana-plugin-server.kibanarequest.url.md b/docs/development/core/server/kibana-plugin-server.kibanarequest.url.md
new file mode 100644
index 0000000000000..d552ba55a2b0e
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-server.kibanarequest.url.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [KibanaRequest](./kibana-plugin-server.kibanarequest.md) > [url](./kibana-plugin-server.kibanarequest.url.md)
+
+## KibanaRequest.url property
+
+Signature:
+
+```typescript
+readonly url: Url;
+```
diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md
index c078a5fdc983f..843f2a65e9562 100644
--- a/docs/development/core/server/kibana-plugin-server.md
+++ b/docs/development/core/server/kibana-plugin-server.md
@@ -34,7 +34,8 @@ The plugin integrates with the core system via lifecycle events: `setup`
| [Logger](./kibana-plugin-server.logger.md) | Logger exposes all the necessary methods to log any type of information and this is the interface used by the logging consumers including plugins. |
| [LoggerFactory](./kibana-plugin-server.loggerfactory.md) | The single purpose of LoggerFactory
interface is to define a way to retrieve a context-based logger instance. |
| [LogMeta](./kibana-plugin-server.logmeta.md) | Contextual metadata |
-| [OnRequestToolkit](./kibana-plugin-server.onrequesttoolkit.md) | A tool set defining an outcome of OnRequest interceptor for incoming request. |
+| [OnPostAuthToolkit](./kibana-plugin-server.onpostauthtoolkit.md) | A tool set defining an outcome of OnPostAuth interceptor for incoming request. |
+| [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md) | A tool set defining an outcome of OnPreAuth interceptor for incoming request. |
| [Plugin](./kibana-plugin-server.plugin.md) | The interface that should be returned by a PluginInitializer
. |
| [PluginInitializerContext](./kibana-plugin-server.plugininitializercontext.md) | Context that's available to plugins during initialization stage. |
| [PluginsServiceSetup](./kibana-plugin-server.pluginsservicesetup.md) | |
@@ -49,7 +50,8 @@ The plugin integrates with the core system via lifecycle events: `setup`
| [ElasticsearchClientConfig](./kibana-plugin-server.elasticsearchclientconfig.md) | |
| [Headers](./kibana-plugin-server.headers.md) | |
| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | |
-| [OnRequestHandler](./kibana-plugin-server.onrequesthandler.md) | |
+| [OnPostAuthHandler](./kibana-plugin-server.onpostauthhandler.md) | |
+| [OnPreAuthHandler](./kibana-plugin-server.onpreauthhandler.md) | |
| [PluginInitializer](./kibana-plugin-server.plugininitializer.md) | The plugin
export at the root of a plugin's server
directory should conform to this interface. |
| [PluginName](./kibana-plugin-server.pluginname.md) | Dedicated type for plugin name/id that is supposed to make Map/Set/Arrays that use it as a key or value more obvious. |
diff --git a/docs/development/core/server/kibana-plugin-server.onpostauthhandler.md b/docs/development/core/server/kibana-plugin-server.onpostauthhandler.md
new file mode 100644
index 0000000000000..83de25e3f3d6d
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-server.onpostauthhandler.md
@@ -0,0 +1,12 @@
+
+
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnPostAuthHandler](./kibana-plugin-server.onpostauthhandler.md)
+
+## OnPostAuthHandler type
+
+
+Signature:
+
+```typescript
+export declare type OnPostAuthHandler() => OnPostAuthResult
| To pass request to the next handler |
+| [redirected](./kibana-plugin-server.onpostauthtoolkit.redirected.md) | (url: string) => OnPostAuthResult
| To interrupt request handling and redirect to a configured url |
+| [rejected](./kibana-plugin-server.onpostauthtoolkit.rejected.md) | (error: Error, options?: {`` statusCode?: number;`` }) => OnPostAuthResult
| Fail the request with specified error. |
+
diff --git a/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.next.md b/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.next.md
new file mode 100644
index 0000000000000..26b4562974e41
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.next.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnPostAuthToolkit](./kibana-plugin-server.onpostauthtoolkit.md) > [next](./kibana-plugin-server.onpostauthtoolkit.next.md)
+
+## OnPostAuthToolkit.next property
+
+To pass request to the next handler
+
+Signature:
+
+```typescript
+next: () => OnPostAuthResult;
+```
diff --git a/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.redirected.md b/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.redirected.md
new file mode 100644
index 0000000000000..23cef2f97e32b
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.redirected.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnPostAuthToolkit](./kibana-plugin-server.onpostauthtoolkit.md) > [redirected](./kibana-plugin-server.onpostauthtoolkit.redirected.md)
+
+## OnPostAuthToolkit.redirected property
+
+To interrupt request handling and redirect to a configured url
+
+Signature:
+
+```typescript
+redirected: (url: string) => OnPostAuthResult;
+```
diff --git a/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.rejected.md b/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.rejected.md
new file mode 100644
index 0000000000000..a7767dac727a0
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-server.onpostauthtoolkit.rejected.md
@@ -0,0 +1,15 @@
+
+
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnPostAuthToolkit](./kibana-plugin-server.onpostauthtoolkit.md) > [rejected](./kibana-plugin-server.onpostauthtoolkit.rejected.md)
+
+## OnPostAuthToolkit.rejected property
+
+Fail the request with specified error.
+
+Signature:
+
+```typescript
+rejected: (error: Error, options?: {
+ statusCode?: number;
+ }) => OnPostAuthResult;
+```
diff --git a/docs/development/core/server/kibana-plugin-server.onpreauthhandler.md b/docs/development/core/server/kibana-plugin-server.onpreauthhandler.md
new file mode 100644
index 0000000000000..606ed21dc6463
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-server.onpreauthhandler.md
@@ -0,0 +1,12 @@
+
+
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnPreAuthHandler](./kibana-plugin-server.onpreauthhandler.md)
+
+## OnPreAuthHandler type
+
+
+Signature:
+
+```typescript
+export declare type OnPreAuthHandler() => OnPreAuthResult
| To pass request to the next handler |
+| [redirected](./kibana-plugin-server.onpreauthtoolkit.redirected.md) | (url: string, options?: {`` forward: boolean;`` }) => OnPreAuthResult
| To interrupt request handling and redirect to a configured url. If "options.forwarded" = true, request will be forwarded to another url right on the server. |
+| [rejected](./kibana-plugin-server.onpreauthtoolkit.rejected.md) | (error: Error, options?: {`` statusCode?: number;`` }) => OnPreAuthResult
| Fail the request with specified error. |
+
diff --git a/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.next.md b/docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.next.md
similarity index 52%
rename from docs/development/core/server/kibana-plugin-server.onrequesttoolkit.next.md
rename to docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.next.md
index 976e3b1a2db87..86369f70ac1d9 100644
--- a/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.next.md
+++ b/docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.next.md
@@ -1,13 +1,13 @@
-[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnRequestToolkit](./kibana-plugin-server.onrequesttoolkit.md) > [next](./kibana-plugin-server.onrequesttoolkit.next.md)
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md) > [next](./kibana-plugin-server.onpreauthtoolkit.next.md)
-## OnRequestToolkit.next property
+## OnPreAuthToolkit.next property
To pass request to the next handler
Signature:
```typescript
-next: () => OnRequestResult;
+next: () => OnPreAuthResult;
```
diff --git a/docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.redirected.md b/docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.redirected.md
new file mode 100644
index 0000000000000..65c0512b9367b
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.redirected.md
@@ -0,0 +1,15 @@
+
+
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md) > [redirected](./kibana-plugin-server.onpreauthtoolkit.redirected.md)
+
+## OnPreAuthToolkit.redirected property
+
+To interrupt request handling and redirect to a configured url. If "options.forwarded" = true, request will be forwarded to another url right on the server.
+
+Signature:
+
+```typescript
+redirected: (url: string, options?: {
+ forward: boolean;
+ }) => OnPreAuthResult;
+```
diff --git a/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.rejected.md b/docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.rejected.md
similarity index 59%
rename from docs/development/core/server/kibana-plugin-server.onrequesttoolkit.rejected.md
rename to docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.rejected.md
index 447d9b3fb9be5..b267a03b6f934 100644
--- a/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.rejected.md
+++ b/docs/development/core/server/kibana-plugin-server.onpreauthtoolkit.rejected.md
@@ -1,8 +1,8 @@
-[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnRequestToolkit](./kibana-plugin-server.onrequesttoolkit.md) > [rejected](./kibana-plugin-server.onrequesttoolkit.rejected.md)
+[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md) > [rejected](./kibana-plugin-server.onpreauthtoolkit.rejected.md)
-## OnRequestToolkit.rejected property
+## OnPreAuthToolkit.rejected property
Fail the request with specified error.
@@ -11,5 +11,5 @@ Fail the request with specified error.
```typescript
rejected: (error: Error, options?: {
statusCode?: number;
- }) => OnRequestResult;
+ }) => OnPreAuthResult;
```
diff --git a/docs/development/core/server/kibana-plugin-server.onrequesthandler.md b/docs/development/core/server/kibana-plugin-server.onrequesthandler.md
deleted file mode 100644
index 5d90e399db676..0000000000000
--- a/docs/development/core/server/kibana-plugin-server.onrequesthandler.md
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnRequestHandler](./kibana-plugin-server.onrequesthandler.md)
-
-## OnRequestHandler type
-
-
-Signature:
-
-```typescript
-export declare type OnRequestHandler() => OnRequestResult
| To pass request to the next handler |
-| [redirected](./kibana-plugin-server.onrequesttoolkit.redirected.md) | (url: string) => OnRequestResult
| To interrupt request handling and redirect to a configured url |
-| [rejected](./kibana-plugin-server.onrequesttoolkit.rejected.md) | (error: Error, options?: {`` statusCode?: number;`` }) => OnRequestResult
| Fail the request with specified error. |
-| [setUrl](./kibana-plugin-server.onrequesttoolkit.seturl.md) | (newUrl: string | Url) => void
| Change url for an incoming request. |
-
diff --git a/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.redirected.md b/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.redirected.md
deleted file mode 100644
index 311398845bd59..0000000000000
--- a/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.redirected.md
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnRequestToolkit](./kibana-plugin-server.onrequesttoolkit.md) > [redirected](./kibana-plugin-server.onrequesttoolkit.redirected.md)
-
-## OnRequestToolkit.redirected property
-
-To interrupt request handling and redirect to a configured url
-
-Signature:
-
-```typescript
-redirected: (url: string) => OnRequestResult;
-```
diff --git a/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.seturl.md b/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.seturl.md
deleted file mode 100644
index 0f20cbdb18d96..0000000000000
--- a/docs/development/core/server/kibana-plugin-server.onrequesttoolkit.seturl.md
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-[Home](./index) > [kibana-plugin-server](./kibana-plugin-server.md) > [OnRequestToolkit](./kibana-plugin-server.onrequesttoolkit.md) > [setUrl](./kibana-plugin-server.onrequesttoolkit.seturl.md)
-
-## OnRequestToolkit.setUrl property
-
-Change url for an incoming request.
-
-Signature:
-
-```typescript
-setUrl: (newUrl: string | Url) => void;
-```
diff --git a/src/core/server/http/auth_state_storage.ts b/src/core/server/http/auth_state_storage.ts
new file mode 100644
index 0000000000000..eafe755b79eea
--- /dev/null
+++ b/src/core/server/http/auth_state_storage.ts
@@ -0,0 +1,51 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. 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.
+ */
+import { Request } from 'hapi';
+import { KibanaRequest } from './router';
+
+export enum AuthStatus {
+ authenticated = 'authenticated',
+ unauthenticated = 'unauthenticated',
+ unknown = 'unknown',
+}
+
+const toKey = (request: KibanaRequest | Request) =>
+ request instanceof KibanaRequest ? request.unstable_getIncomingMessage() : request.raw.req;
+
+export class AuthStateStorage {
+ private readonly storage = new WeakMap | false;
+
+ /**
+ * A flag shows that authentication for a route:
+ * enabled when true
+ * disabled when false
+ *
+ * Enabled by default.
+ */
+ authRequired?: boolean;
}
export type RouteValidateFactory<
diff --git a/src/core/server/http/router/router.ts b/src/core/server/http/router/router.ts
index a640a413fd81b..2a1a169e0931d 100644
--- a/src/core/server/http/router/router.ts
+++ b/src/core/server/http/router/router.ts
@@ -27,6 +27,7 @@ import { RouteConfig, RouteMethod, RouteSchemas } from './route';
export interface RouterRoute {
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
path: string;
+ authRequired: boolean;
handler: (req: Request, responseToolkit: ResponseToolkit) => Promise ,
handler: RequestHandler
) {
+ const { path, authRequired = true } = route;
const routeSchemas = this.routeSchemasFromRouteConfig(route, 'GET');
this.routes.push({
handler: async (req, responseToolkit) =>
await this.handle(routeSchemas, req, responseToolkit, handler),
method: 'GET',
- path: route.path,
+ path,
+ authRequired,
});
}
@@ -59,12 +62,14 @@ export class Router {
route: RouteConfig ,
handler: RequestHandler
) {
+ const { path, authRequired = true } = route;
const routeSchemas = this.routeSchemasFromRouteConfig(route, 'POST');
this.routes.push({
handler: async (req, responseToolkit) =>
await this.handle(routeSchemas, req, responseToolkit, handler),
method: 'POST',
- path: route.path,
+ path,
+ authRequired,
});
}
@@ -75,12 +80,14 @@ export class Router {
route: RouteConfig ,
handler: RequestHandler
) {
+ const { path, authRequired = true } = route;
const routeSchemas = this.routeSchemasFromRouteConfig(route, 'POST');
this.routes.push({
handler: async (req, responseToolkit) =>
await this.handle(routeSchemas, req, responseToolkit, handler),
method: 'PUT',
- path: route.path,
+ path,
+ authRequired,
});
}
@@ -91,12 +98,14 @@ export class Router {
route: RouteConfig ,
handler: RequestHandler
) {
+ const { path, authRequired = true } = route;
const routeSchemas = this.routeSchemasFromRouteConfig(route, 'DELETE');
this.routes.push({
handler: async (req, responseToolkit) =>
await this.handle(routeSchemas, req, responseToolkit, handler),
method: 'DELETE',
- path: route.path,
+ path,
+ authRequired,
});
}
diff --git a/src/core/server/index.ts b/src/core/server/index.ts
index d3223674eb00c..e144c0f2568f8 100644
--- a/src/core/server/index.ts
+++ b/src/core/server/index.ts
@@ -54,8 +54,10 @@ export {
AuthenticationHandler,
AuthToolkit,
KibanaRequest,
- OnRequestHandler,
- OnRequestToolkit,
+ OnPreAuthHandler,
+ OnPreAuthToolkit,
+ OnPostAuthHandler,
+ OnPostAuthToolkit,
Router,
} from './http';
export { Logger, LoggerFactory, LogMeta, LogRecord, LogLevel } from './logging';
@@ -79,8 +81,9 @@ export interface CoreSetup {
dataClient$: Observable