55 */
66
77import { resolve } from 'path' ;
8- import { getUserProvider } from './server/lib/get_user' ;
98import { initAuthenticateApi } from './server/routes/api/v1/authenticate' ;
109import { initUsersApi } from './server/routes/api/v1/users' ;
1110import { initExternalRolesApi } from './server/routes/api/external/roles' ;
@@ -16,10 +15,7 @@ import { initOverwrittenSessionView } from './server/routes/views/overwritten_se
1615import { initLoginView } from './server/routes/views/login' ;
1716import { initLogoutView } from './server/routes/views/logout' ;
1817import { initLoggedOutView } from './server/routes/views/logged_out' ;
19- import { validateConfig } from './server/lib/validate_config' ;
20- import { authenticateFactory } from './server/lib/auth_redirect' ;
2118import { checkLicense } from './server/lib/check_license' ;
22- import { initAuthenticator } from './server/lib/authentication/authenticator' ;
2319import { SecurityAuditLogger } from './server/lib/audit_logger' ;
2420import { AuditLogger } from '../../server/lib/audit_logger' ;
2521import {
@@ -34,6 +30,7 @@ import { watchStatusAndLicenseToInitialize } from '../../server/lib/watch_status
3430import { SecureSavedObjectsClientWrapper } from './server/lib/saved_objects_client/secure_saved_objects_client_wrapper' ;
3531import { deepFreeze } from './server/lib/deep_freeze' ;
3632import { createOptionalPlugin } from '../../server/lib/optional_plugin' ;
33+ import { KibanaRequest } from '../../../../src/core/server' ;
3734
3835export const security = ( kibana ) => new kibana . Plugin ( {
3936 id : 'security' ,
@@ -42,23 +39,12 @@ export const security = (kibana) => new kibana.Plugin({
4239 require : [ 'kibana' , 'elasticsearch' , 'xpack_main' ] ,
4340
4441 config ( Joi ) {
45- const providerOptionsSchema = ( providerName , schema ) => Joi . any ( )
46- . when ( 'providers' , {
47- is : Joi . array ( ) . items ( Joi . string ( ) . valid ( providerName ) . required ( ) , Joi . string ( ) ) ,
48- then : schema ,
49- otherwise : Joi . any ( ) . forbidden ( ) ,
50- } ) ;
51-
5242 return Joi . object ( {
5343 enabled : Joi . boolean ( ) . default ( true ) ,
54- cookieName : Joi . string ( ) . default ( 'sid' ) ,
55- encryptionKey : Joi . when ( Joi . ref ( '$dist' ) , {
56- is : true ,
57- then : Joi . string ( ) ,
58- otherwise : Joi . string ( ) . default ( 'a' . repeat ( 32 ) ) ,
59- } ) ,
60- sessionTimeout : Joi . number ( ) . allow ( null ) . default ( null ) ,
61- secureCookies : Joi . boolean ( ) . default ( false ) ,
44+ cookieName : Joi . any ( ) . description ( 'This key is handled in the new platform security plugin ONLY' ) ,
45+ encryptionKey : Joi . any ( ) . description ( 'This key is handled in the new platform security plugin ONLY' ) ,
46+ sessionTimeout : Joi . any ( ) . description ( 'This key is handled in the new platform security plugin ONLY' ) ,
47+ secureCookies : Joi . any ( ) . description ( 'This key is handled in the new platform security plugin ONLY' ) ,
6248 authorization : Joi . object ( {
6349 legacyFallback : Joi . object ( {
6450 enabled : Joi . boolean ( ) . default ( true ) // deprecated
@@ -67,11 +53,7 @@ export const security = (kibana) => new kibana.Plugin({
6753 audit : Joi . object ( {
6854 enabled : Joi . boolean ( ) . default ( false )
6955 } ) . default ( ) ,
70- authc : Joi . object ( {
71- providers : Joi . array ( ) . items ( Joi . string ( ) ) . default ( [ 'basic' ] ) ,
72- oidc : providerOptionsSchema ( 'oidc' , Joi . object ( { realm : Joi . string ( ) . required ( ) } ) . required ( ) ) ,
73- saml : providerOptionsSchema ( 'saml' , Joi . object ( { realm : Joi . string ( ) . required ( ) } ) . required ( ) ) ,
74- } ) . default ( )
56+ authc : Joi . any ( ) . description ( 'This key is handled in the new platform security plugin ONLY' )
7557 } ) . default ( ) ;
7658 } ,
7759
@@ -112,15 +94,18 @@ export const security = (kibana) => new kibana.Plugin({
11294 'plugins/security/hacks/on_unauthorized_response'
11395 ] ,
11496 home : [ 'plugins/security/register_feature' ] ,
115- injectDefaultVars : function ( server ) {
116- const config = server . config ( ) ;
97+ injectDefaultVars : ( server ) => {
98+ const securityPlugin = server . newPlatform . setup . plugins . security ;
99+ if ( ! securityPlugin ) {
100+ throw new Error ( 'New Platform XPack Security plugin is not available.' ) ;
101+ }
117102
118103 return {
119- secureCookies : config . get ( 'xpack.security. secureCookies' ) ,
120- sessionTimeout : config . get ( 'xpack.security. sessionTimeout' ) ,
121- enableSpaceAwarePrivileges : config . get ( 'xpack.spaces.enabled' ) ,
104+ secureCookies : securityPlugin . config . secureCookies ,
105+ sessionTimeout : securityPlugin . config . sessionTimeout ,
106+ enableSpaceAwarePrivileges : server . config ( ) . get ( 'xpack.spaces.enabled' ) ,
122107 } ;
123- }
108+ } ,
124109 } ,
125110
126111 async postInit ( server ) {
@@ -138,28 +123,29 @@ export const security = (kibana) => new kibana.Plugin({
138123 } ,
139124
140125 async init ( server ) {
141- const plugin = this ;
126+ const securityPlugin = server . newPlatform . setup . plugins . security ;
127+ if ( ! securityPlugin ) {
128+ throw new Error ( 'New Platform XPack Security plugin is not available.' ) ;
129+ }
142130
143- const config = server . config ( ) ;
144131 const xpackMainPlugin = server . plugins . xpack_main ;
145132 const xpackInfo = xpackMainPlugin . info ;
133+ securityPlugin . registerLegacyAPI ( {
134+ xpackInfo,
135+ isSystemAPIRequest : server . plugins . kibana . systemApi . isSystemApiRequest . bind (
136+ server . plugins . kibana . systemApi
137+ ) ,
138+ } ) ;
146139
140+ const plugin = this ;
141+ const config = server . config ( ) ;
147142 const xpackInfoFeature = xpackInfo . feature ( plugin . id ) ;
148143
149144 // Register a function that is called whenever the xpack info changes,
150145 // to re-compute the license check results for this plugin
151146 xpackInfoFeature . registerLicenseCheckResultsGenerator ( checkLicense ) ;
152147
153- validateConfig ( config , message => server . log ( [ 'security' , 'warning' ] , message ) ) ;
154-
155- // Create a Hapi auth scheme that should be applied to each request.
156- server . auth . scheme ( 'login' , ( ) => ( { authenticate : authenticateFactory ( server ) } ) ) ;
157-
158- server . auth . strategy ( 'session' , 'login' ) ;
159-
160- // The default means that the `session` strategy that is based on `login` schema defined above will be
161- // automatically assigned to all routes that don't contain an auth config.
162- server . auth . default ( 'session' ) ;
148+ server . expose ( { getUser : request => securityPlugin . authc . getCurrentUser ( KibanaRequest . from ( request ) ) } ) ;
163149
164150 const { savedObjects } = server ;
165151
@@ -203,20 +189,17 @@ export const security = (kibana) => new kibana.Plugin({
203189 return client ;
204190 } ) ;
205191
206- getUserProvider ( server ) ;
207-
208- await initAuthenticator ( server ) ;
209- initAuthenticateApi ( server ) ;
192+ initAuthenticateApi ( securityPlugin , server ) ;
210193 initAPIAuthorization ( server , authorization ) ;
211194 initAppAuthorization ( server , xpackMainPlugin , authorization ) ;
212- initUsersApi ( server ) ;
195+ initUsersApi ( securityPlugin , server ) ;
213196 initExternalRolesApi ( server ) ;
214197 initIndicesApi ( server ) ;
215198 initPrivilegesApi ( server ) ;
216199 initGetBuiltinPrivilegesApi ( server ) ;
217- initLoginView ( server , xpackMainPlugin ) ;
200+ initLoginView ( securityPlugin , server , xpackMainPlugin ) ;
218201 initLogoutView ( server ) ;
219- initLoggedOutView ( server ) ;
202+ initLoggedOutView ( securityPlugin , server ) ;
220203 initOverwrittenSessionView ( server ) ;
221204
222205 server . injectUiAppVars ( 'login' , ( ) => {
0 commit comments