protected final String checkRequiredParameter(final HttpServletRequest request, final String parameterName, final Map<String, Message> errorMessages, final String messageKey) { if (StringUtils.isBlank(request.getParameter(parameterName))) { errorMessages.put(parameterName, messageFactory.newI18nMessage(messageKey)); } return request.getParameter(parameterName); }
private String[] extractParams(final HttpServletRequest request) { final String[] pathParams = StringUtils.split(request.getPathInfo(), '/'); if (pathParams.length < 2) { throw new AbstractApplinksServlet.BadRequestException(messageFactory.newLocalizedMessage( "Servlet URL should be of form /listEntityLinks/{entity-type}/{entity-key}")); } return pathParams; } }
private void parsePathParams(final String typeId) { if (!internalHostApplication.doesEntityExist(key, typeAccessor.loadEntityType(typeId).getClass())) { throw new AbstractApplinksServlet.BadRequestException(messageFactory.newLocalizedMessage( String.format("No entity exists with key %s of type %s", key, typeId))); } final EntityType entityType = typeAccessor.loadEntityType(typeId); assertPermission(entityType.getClass(), key); final EntityReference entityReference = internalHostApplication.toEntityReference(key, entityType.getClass()); type = typeId; typeLabel = messageFactory.newI18nMessage(entityType.getShortenedI18nKey()).toString(); name = entityReference.getName(); }
protected String getRequiredParameter(final HttpServletRequest request, final String name) throws BadRequestException { final String value = request.getParameter(name); if (StringUtils.isBlank(value)) { throw new BadRequestException(messageFactory.newI18nMessage("auth.config.parameter.missing", name)); } else { return value; } }
/** * Examines the request for a "method" parameter and invokes either {@link #doDelete(HttpServletRequest, HttpServletResponse)} or {@link * #doPut(HttpServletRequest, HttpServletResponse)} appropriately. * * @param req the HTTP request * @param resp the HTTP response * @throws BadRequestException Thrown if the "method" parameter is not provided. * @throws IllegalArgumentException Thrown if the method requested is not "DELETE or "PUT". * @throws IOException Thrown if rendering fails for the invoked method. */ @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { String method = getRequiredParameter(req, "method"); if ("PUT".equals(method)) { doPut(req, resp); } else if ("DELETE".equals(method)) { doDelete(req, resp); } else { throw new BadRequestException(messageFactory.newLocalizedMessage("Invalid method: " + method)); } }
public static String getRequiredParameter(final HttpServletRequest request, final MessageFactory messageFactory, final String name) throws BadRequestException { final String value = request.getParameter(name); if (StringUtils.isBlank(value)) { throw new BadRequestException(messageFactory.newI18nMessage("auth.config.parameter.missing", name)); } else { return value; } } }
private String relativitize(String uri, final URI supposedlyBaseUri, final String parameterName, final String messageKey, Map<String, Message> errorMessages) throws IllegalArgumentException { try { return relativitize(uri, supposedlyBaseUri); } catch (IllegalArgumentException iae) { errorMessages.put(parameterName, messageFactory.newI18nMessage(messageKey)); return uri; } }
private AbstractApplinksServlet.BadRequestException createBadRequestException(final String redirectUri) { return new AbstractApplinksServlet.BadRequestException(messageFactory.newI18nMessage("auth.config.parameter.callback.invalid", redirectUri)); } }
protected String getRequiredParameter(final HttpServletRequest request, final String name) throws BadRequestException { final String value = request.getParameter(name); if (StringUtils.isBlank(value)) { throw new BadRequestException(messageFactory.newI18nMessage("auth.config.parameter.missing", name)); } else { return value; } }
private AbstractApplinksServlet.BadRequestException createBadRequestException(final String redirectUri) { return new AbstractApplinksServlet.BadRequestException(messageFactory.newI18nMessage("auth.config.parameter.callback.invalid", redirectUri)); } }
public static String getRequiredParameter(final HttpServletRequest request, final MessageFactory messageFactory, final String name) throws BadRequestException { final String value = request.getParameter(name); if (StringUtils.isBlank(value)) { throw new BadRequestException(messageFactory.newI18nMessage("auth.config.parameter.missing", name)); } else { return value; } } }
@Override protected void handleUnauthorizedAccess(HttpServletRequest request) { if (request.getUserPrincipal() != null) { throw new UnauthorizedException(messageFactory.newI18nMessage("applinks.error.only.sysadmin.operation")); } else { throw new UnauthorizedBecauseUnauthenticatedException(); } } }
@Override protected void handleUnauthorizedAccess(HttpServletRequest request) { if (request.getUserPrincipal() != null) { throw new UnauthorizedException(messageFactory.newI18nMessage("applinks.error.only.admin")); } else { throw new UnauthorizedBecauseUnauthenticatedException(); } } }
@Override protected void handleUnauthorizedAccess(HttpServletRequest request) { if (request.getUserPrincipal() != null) { throw new UnauthorizedException(messageFactory.newI18nMessage("applinks.error.only.sysadmin.operation")); } else { throw new UnauthorizedBecauseUnauthenticatedException(); } } }
@Override protected void handleUnauthorizedAccess(HttpServletRequest request) { if (request.getUserPrincipal() != null) { throw new UnauthorizedException(messageFactory.newI18nMessage("applinks.error.only.admin")); } else { throw new UnauthorizedBecauseUnauthenticatedException(); } } }
private void assertPermission(final Class<? extends EntityType> entityType, final String key) { if (!internalHostApplication.canManageEntityLinksFor( internalHostApplication.toEntityReference(key, entityType))) { throw new AbstractApplinksServlet.UnauthorizedException(messageFactory.newI18nMessage("applinks.entity.list.no.permission")); } }
protected Action getAction(final HttpServletRequest request) { final String value = getRequiredParameter(request, "action"); try { return Action.valueOf(value); } catch (IllegalArgumentException e) { throw new BadRequestException(messageFactory.newI18nMessage("auth.trusted.config.reciprocal.action.missing", value)); } }
private void processPeerResponse(final HttpServletRequest request, final HttpServletResponse response, final ApplicationLink link) throws IOException { // returned from peer final RendererContextBuilder contextBuilder = new RendererContextBuilder(); if (!peerWasSuccessful(request)) { contextBuilder.put("error", messageFactory.newI18nMessage("auth.trusted.config.consumer.save.peer.failed", request.getParameter("message"))); } render(link, request, response, contextBuilder.build()); }
logger.warn(String.format("Unable to load ApplicationLink %s due to uninstalled type definition (%s).", id.toString(), e.getType()), e); throw new NotFoundException(messageFactory.newI18nMessage("auth.config.applink.notfound", id.toString())); throw new BadRequestException(messageFactory.newI18nMessage("auth.config.applinkpath.missing"));
logger.warn(String.format("Unable to load ApplicationLink %s due to uninstalled type definition (%s).", id.toString(), e.getType()), e); throw new AbstractApplinksServlet.NotFoundException(messageFactory.newI18nMessage("auth.config.applink.notfound", id.toString())); throw new AbstractApplinksServlet.BadRequestException(messageFactory.newI18nMessage("auth.config.applinkpath.missing"));