Skip to content

Commit

Permalink
Switch Kerberos authentication provider to a dedicated _kerberos gr…
Browse files Browse the repository at this point in the history
…ant. Introduce `Tokens` for common access/refresh token tasks. (#39366) (#40101)

* Switch Kerberos authentication provider to a dedicated `_kerberos` grant. Introduce `Tokens` for common access/refresh token tasks.

* Review#1: improve/fix code comments, properly log the case when token invalidation failed.
  • Loading branch information
kobelb authored Jul 1, 2019
1 parent 5e4d6af commit 9d86c55
Show file tree
Hide file tree
Showing 16 changed files with 930 additions and 859 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DeauthenticationResult } from './deauthentication_result';
import { Session } from './session';
import { LoginAttempt } from './login_attempt';
import { AuthenticationProviderSpecificOptions } from './providers/base';
import { Tokens } from './tokens';

interface ProviderSession {
provider: string;
Expand Down Expand Up @@ -56,15 +57,18 @@ function assertRequest(request: Legacy.Request) {
*/
function getProviderOptions(server: Legacy.Server) {
const config = server.config();
const client = getClient(server);
const log = server.log.bind(server);

return {
client: getClient(server),
log: server.log.bind(server),
client,
log,

protocol: server.info.protocol,
hostname: config.get<string>('server.host'),
port: config.get<number>('server.port'),
basePath: config.get<string>('server.basePath'),
tokens: new Tokens({ client, log }),

...config.get('xpack.security.public'),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { stub } from 'sinon';
import { stub, createStubInstance } from 'sinon';
import { Tokens } from '../tokens';
import { AuthenticationProviderOptions } from './base';

export function mockAuthenticationProviderOptions(
providerOptions: Partial<AuthenticationProviderOptions> = {}
providerOptions: Partial<Pick<AuthenticationProviderOptions, 'basePath'>> = {}
) {
const client = { callWithRequest: stub(), callWithInternalUser: stub() };
const log = stub();

return {
hostname: 'test-hostname',
port: 1234,
protocol: 'test-protocol',
client: { callWithRequest: stub(), callWithInternalUser: stub() },
log: stub(),
client,
log,
basePath: '/base-path',
tokens: createStubInstance(Tokens),
...providerOptions,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Legacy } from 'kibana';
import { AuthenticationResult } from '../authentication_result';
import { DeauthenticationResult } from '../deauthentication_result';
import { LoginAttempt } from '../login_attempt';
import { Tokens } from '../tokens';

/**
* Describes a request complemented with `loginAttempt` method.
Expand All @@ -26,6 +27,7 @@ export interface AuthenticationProviderOptions {
basePath: string;
client: Legacy.Plugins.elasticsearch.Cluster;
log: (tags: string[], message: string) => void;
tokens: PublicMethodsOf<Tokens>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('BasicAuthenticationProvider', () => {
let callWithRequest: sinon.SinonStub;
beforeEach(() => {
const providerOptions = mockAuthenticationProviderOptions();
callWithRequest = providerOptions.client.callWithRequest as sinon.SinonStub;
callWithRequest = providerOptions.client.callWithRequest;
provider = new BasicAuthenticationProvider(providerOptions);
});

Expand Down
Loading

0 comments on commit 9d86c55

Please sign in to comment.