本文整理汇总了TypeScript中Boom.forbidden函数的典型用法代码示例。如果您正苦于以下问题:TypeScript forbidden函数的具体用法?TypeScript forbidden怎么用?TypeScript forbidden使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forbidden函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: requestIsValid
public requestIsValid(request: any): boolean {
const license = this.adapter.getLicenseType();
if (license === null) {
throw Boom.badRequest('Missing license information');
}
if (!supportedLicenses.some(licenseType => licenseType === license)) {
throw Boom.forbidden('License not supported');
}
if (this.adapter.licenseIsActive() === false) {
throw Boom.forbidden('License not active');
}
return this.checkRequest(request);
}
示例2: registerClusterCheckupRoutes
export function registerClusterCheckupRoutes(server: Legacy.Server) {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const isCloudEnabled = _.get(server.plugins, 'cloud.config.isCloudEnabled', false);
server.route({
path: '/api/upgrade_assistant/status',
method: 'GET',
options: {
pre: [EsVersionPrecheck],
},
async handler(request) {
try {
return await getUpgradeAssistantStatus(callWithRequest, request, isCloudEnabled);
} catch (e) {
if (e.status === 403) {
return Boom.forbidden(e.message);
}
return Boom.boomify(e, {
statusCode: 500,
});
}
},
});
}
示例3: function
handler: async function (req, res, next) {
const payload: Requests.UpdatePassword = req.validatedBody;
let user = await UserDb.get(req.user._id);
// Ensure the user's current password is correct
if (!compareSync(payload.old_password, user.hashed_password)) {
return next(boom.forbidden(`Your current password is incorrect.`));
}
// Change the user's password
user.hashed_password = hashSync(payload.new_password);
try {
const updateResult = await UserDb.put(user._id, user, user._rev);
user._rev = updateResult.rev
} catch (e) {
inspect("Failed to update user's password.", e);
return next(e);
}
await res.withSessionToken(user);
return next();
}
示例4: checkRequest
private checkRequest(request: any): boolean {
const authenticated = get(request, 'auth.isAuthenticated', null);
if (authenticated === null) {
throw Boom.forbidden('Missing authentication');
}
return authenticated;
}
示例5: forbidApiAccess
return function forbidApiAccess(request: any) {
const licenseCheckResults = xpackMainPlugin.info.feature(pluginId).getLicenseCheckResults();
if (!licenseCheckResults.showSpaces) {
return Boom.forbidden(licenseCheckResults.linksMessage);
} else {
return '';
}
};
示例6: wrapEsError
export function wrapEsError(err: any) {
const statusCode = err.statusCode;
if (statusCode === 403) {
return Boom.forbidden('Insufficient user permissions for managing Beats configuration');
}
return Boom.boomify(err, { statusCode: err.statusCode });
}
示例7: async
export const readOnlyMiddleware = async (resolve, root, args, context: Context, info) => {
const operationType = get(info, 'operation.operation');
if (!context.readOnly || (context.readOnly && operationType === 'query')) {
return resolve(root, args, context, info);
}
// readOnly true, but operation is one of mutation or subscription
throw Boom.forbidden('Only query allowed in readonly request', {code: ErrorCodes.MUTATION_IN_READONLY});
};
示例8: async
return async ({ ctx }: { ctx: Context }) => {
const authorization = ctx.get('authorization');
if (!authorization) {
throw Boom.forbidden('authorization header required', {code: ErrorCodes.AUTH_HEADER_MISSING});
}
const accessToken = authorization.replace('Bearer ', '');
if (!accessToken) {
throw Boom.forbidden('access token required', {code: ErrorCodes.ACCESSTOKEN_MISSING});
}
// check with authHandler
const authContext = await authHandler(accessToken);
return {
...authContext
};
};
示例9: ensureAuthorizedGlobally
private async ensureAuthorizedGlobally(action: string, method: string, forbiddenMessage: string) {
const checkPrivileges = this.authorization.checkPrivilegesWithRequest(this.request);
const { username, hasAllRequested } = await checkPrivileges.globally(action);
if (hasAllRequested) {
this.auditLogger.spacesAuthorizationSuccess(username, method);
return;
} else {
this.auditLogger.spacesAuthorizationFailure(username, method);
throw Boom.forbidden(forbiddenMessage);
}
}
示例10: handleError
function handleError(exportType: any, err: Error) {
if (err instanceof esErrors['401']) {
return boom.unauthorized(`Sorry, you aren't authenticated`);
}
if (err instanceof esErrors['403']) {
return boom.forbidden(`Sorry, you are not authorized to create ${exportType} reports`);
}
if (err instanceof esErrors['404']) {
return boom.boomify(err, { statusCode: 404 });
}
return err;
}