Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Implement HTTP Authentication provider and allow ApiKey authentication by default. (#58126) #58860

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions x-pack/legacy/plugins/security/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ export const security = kibana =>
const xpackInfo = server.plugins.xpack_main.info;
securityPlugin.__legacyCompat.registerLegacyAPI({
auditLogger: new AuditLogger(server, 'security', config, xpackInfo),
serverConfig: {
protocol: server.info.protocol,
hostname: config.get('server.host'),
port: config.get('server.port'),
},
});

// Legacy xPack Info endpoint returns whatever we return in a callback for `registerLicenseCheckResultsGenerator`
Expand Down
41 changes: 15 additions & 26 deletions x-pack/plugins/case/server/routes/api/__fixtures__/authc_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { Authentication } from '../../../../../security/server';
import { AuthenticatedUser } from '../../../../../security/server';
import { securityMock } from '../../../../../security/server/mocks';

const getCurrentUser = jest.fn().mockReturnValue({
username: 'awesome',
full_name: 'Awesome D00d',
});
const getCurrentUserThrow = jest.fn().mockImplementation(() => {
throw new Error('Bad User - the user is not authenticated');
});
function createAuthenticationMock({
currentUser,
}: { currentUser?: AuthenticatedUser | null } = {}) {
const { authc } = securityMock.createSetup();
authc.getCurrentUser.mockReturnValue(
currentUser !== undefined
? currentUser
: ({ username: 'awesome', full_name: 'Awesome D00d' } as AuthenticatedUser)
);
return authc;
}

export const authenticationMock = {
create: (): jest.Mocked<Authentication> => ({
login: jest.fn(),
createAPIKey: jest.fn(),
getCurrentUser,
invalidateAPIKey: jest.fn(),
isAuthenticated: jest.fn(),
logout: jest.fn(),
getSessionInfo: jest.fn(),
}),
createInvalid: (): jest.Mocked<Authentication> => ({
login: jest.fn(),
createAPIKey: jest.fn(),
getCurrentUser: getCurrentUserThrow,
invalidateAPIKey: jest.fn(),
isAuthenticated: jest.fn(),
logout: jest.fn(),
getSessionInfo: jest.fn(),
}),
create: () => createAuthenticationMock(),
createInvalid: () => createAuthenticationMock({ currentUser: null }),
};
10 changes: 2 additions & 8 deletions x-pack/plugins/case/server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,8 @@ export class CaseService {
}
},
getUser: async ({ request, response }: GetUserArgs) => {
let user;
try {
this.log.debug(`Attempting to authenticate a user`);
user = await authentication!.getCurrentUser(request);
} catch (error) {
this.log.debug(`Error on GET user: ${error}`);
throw error;
}
this.log.debug(`Attempting to authenticate a user`);
const user = authentication!.getCurrentUser(request);
if (!user) {
this.log.debug(`Error on GET user: Bad User`);
throw new Error('Bad User - the user is not authenticated');
Expand Down
Loading