private static void checkPermission(boolean preview, boolean hasScanPerm, boolean hasBrowsePerm) { if (!hasBrowsePerm && !hasScanPerm) { throw new ForbiddenException(Messages.NO_PERMISSION); } if (!preview && !hasScanPerm) { throw new ForbiddenException("You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. " + "Please contact your SonarQube administrator."); } if (preview && !hasBrowsePerm) { throw new ForbiddenException("You don't have the required permissions to access this project. Please contact your SonarQube administrator."); } }
public static void checkRequest(boolean expression, List<String> messages) { if (!expression) { throw BadRequestException.create(messages); } }
public static Message of(String msg, Object... arguments) { return new Message(msg, arguments); }
private static NotFoundException analysisNotFoundException(String analysis) { return new NotFoundException(format("Analysis '%s' not found", analysis)); } }
public UserSession get() { UserSession session = DELEGATE.get(); if (session != null) { return session; } throw new UnauthorizedException("User is not authenticated"); }
@Test public void fail_when_message_is_null() { expectedException.expect(IllegalArgumentException.class); Message.of(null); }
/** * @throws BadRequestException */ public static void checkRequest(boolean expression, String message, Object... messageArguments) { if (!expression) { throw BadRequestException.create(format(message, messageArguments)); } }
public static ForbiddenException insufficientPrivilegesException() { return new ForbiddenException(INSUFFICIENT_PRIVILEGES_MESSAGE); }
/** * @throws NotFoundException if the value if null * @return the value */ public static <T> T checkFound(@Nullable T value, String message, Object... messageArguments) { if (value == null) { throw new NotFoundException(format(message, messageArguments)); } return value; }
@Override public final UserSession checkLoggedIn() { if (!isLoggedIn()) { throw new UnauthorizedException(AUTHENTICATION_IS_REQUIRED_MESSAGE); } return this; }
public static BadRequestException create(String... errorMessages) { return create(asList(errorMessages)); }
@Override public UserSession checkIsRoot() { if (!isRoot()) { throw new ForbiddenException(INSUFFICIENT_PRIVILEGES_MESSAGE); } return this; }
/** * @throws NotFoundException if the value is not present * @return the value */ public static <T> T checkFoundWithOptional(Optional<T> value, String message, Object... messageArguments) { if (!value.isPresent()) { throw new NotFoundException(format(message, messageArguments)); } return value.get(); }
private ProfileImporter getProfileImporter(String importerKey) { for (ProfileImporter importer : importers) { if (StringUtils.equals(importerKey, importer.getKey())) { return importer; } } throw BadRequestException.create("No such importer : " + importerKey); }
@Override public final UserSession checkComponentPermission(String projectPermission, ComponentDto component) { if (!hasComponentPermission(projectPermission, component)) { throw new ForbiddenException(INSUFFICIENT_PRIVILEGES_MESSAGE); } return this; }
public static <T> T checkFoundWithOptional(java.util.Optional<T> value, String message, Object... messageArguments) { if (!value.isPresent()) { throw new NotFoundException(format(message, messageArguments)); } return value.get(); }
static Long parseId(Request request, String paramName) { try { return Long.valueOf(request.mandatoryParam(paramName)); } catch (NumberFormatException badFormat) { throw BadRequestException.create(paramName + " must be a valid long value"); } }
@Override public final UserSession checkPermission(OrganizationPermission permission, String organizationUuid) { if (!hasPermission(permission, organizationUuid)) { throw new ForbiddenException(INSUFFICIENT_PRIVILEGES_MESSAGE); } return this; }
private ProfileExporter findExporter(String exporterKey) { for (ProfileExporter e : exporters) { if (exporterKey.equals(e.getKey())) { return e; } } throw new NotFoundException("Unknown quality profile exporter: " + exporterKey); }
@Override public final UserSession checkComponentUuidPermission(String permission, String componentUuid) { if (!hasComponentUuidPermission(permission, componentUuid)) { throw new ForbiddenException(INSUFFICIENT_PRIVILEGES_MESSAGE); } return this; }