Skip to content

Commit

Permalink
Drop /api/security/v1/saml route in favour of `/api/security/saml/c…
Browse files Browse the repository at this point in the history
…allback`. (elastic#47929)
  • Loading branch information
azasypkin authored and darnautov committed Oct 14, 2019
1 parent 31c9c5b commit 8e70571
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 51 deletions.
9 changes: 0 additions & 9 deletions x-pack/plugins/security/server/routes/authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ describe('SAML authentication routes', () => {
routeHandler = acsRouteHandler;
});

it('additionally registers BWC route', () => {
expect(
router.post.mock.calls.find(([{ path }]) => path === '/api/security/saml/callback')
).toBeDefined();
expect(
router.post.mock.calls.find(([{ path }]) => path === '/api/security/v1/saml')
).toBeDefined();
});

it('correctly defines route.', () => {
expect(routeConfig.options).toEqual({ authRequired: false });
expect(routeConfig.validate).toEqual({
Expand Down
72 changes: 30 additions & 42 deletions x-pack/plugins/security/server/routes/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,51 +107,39 @@ function defineSAMLRoutes({
}
);

// Generate two identical routes with new and deprecated URL and issue a warning if route with
// deprecated URL is ever used.
for (const path of ['/api/security/saml/callback', '/api/security/v1/saml']) {
router.post(
{
path,
validate: {
body: schema.object({
SAMLResponse: schema.string(),
RelayState: schema.maybe(schema.string()),
}),
},
options: { authRequired: false },
router.post(
{
path: '/api/security/saml/callback',
validate: {
body: schema.object({
SAMLResponse: schema.string(),
RelayState: schema.maybe(schema.string()),
}),
},
async (context, request, response) => {
try {
if (path === '/api/security/v1/saml') {
const serverBasePath = basePath.serverBasePath;
logger.warn(
`The "${serverBasePath}${path}" URL is deprecated and will stop working in the next major version, please use "${serverBasePath}/api/security/saml/callback" URL instead.`,
{ tags: ['deprecation'] }
);
}
options: { authRequired: false },
},
async (context, request, response) => {
try {
// When authenticating using SAML we _expect_ to redirect to the SAML Identity provider.
const authenticationResult = await authc.login(request, {
provider: 'saml',
value: {
step: SAMLLoginStep.SAMLResponseReceived,
samlResponse: request.body.SAMLResponse,
},
});

// When authenticating using SAML we _expect_ to redirect to the SAML Identity provider.
const authenticationResult = await authc.login(request, {
provider: 'saml',
value: {
step: SAMLLoginStep.SAMLResponseReceived,
samlResponse: request.body.SAMLResponse,
},
if (authenticationResult.redirected()) {
return response.redirected({
headers: { location: authenticationResult.redirectURL! },
});

if (authenticationResult.redirected()) {
return response.redirected({
headers: { location: authenticationResult.redirectURL! },
});
}

return response.unauthorized({ body: authenticationResult.error });
} catch (err) {
logger.error(err);
return response.internalError();
}

return response.unauthorized({ body: authenticationResult.error });
} catch (err) {
logger.error(err);
return response.internalError();
}
);
}
}
);
}

0 comments on commit 8e70571

Please sign in to comment.