public static void checkThirdPartyTransferSuccessful(boolean isSuccessful, String template, Object...arguments) throws ThirdPartyTransferFailedCacheException { Exceptions.genericCheck(isSuccessful, ThirdPartyTransferFailedCacheException::new, template, arguments); }
public Principal buildPrincipal(String value) throws GplazmaParseMapFileException { try { if (GroupPrincipal.class.isAssignableFrom(groupType)) { List<String> parts = Splitter.on(',').splitToList(value); checkFormat(parts.size() < 3, "Too many commas in \"%s\" for %s", value, label); boolean isPrimary = parts.size() == 2 ? Boolean.parseBoolean(parts.get(1)) : false; return groupType.getConstructor(String.class, Boolean.TYPE) .newInstance(parts.get(0), isPrimary); } else { return groupType.getConstructor(String.class).newInstance(value); } } catch (NoSuchMethodException|IllegalAccessException|InstantiationException e) { throw new RuntimeException("Failed to create principal: " + e); } catch (InvocationTargetException e) { throw new GplazmaParseMapFileException("Failed to create " + label + " principal \"" + value + "\": " + Exceptions.messageOrClassName((Exception)e.getCause())); } }
public synchronized Map<PrincipalMatcher,Set<Principal>> mapping() throws AuthenticationException { if (!Instant.now().isBefore(nextStat)) { nextStat = Instant.now().plusMillis(100); try { Instant mtime = Files.readAttributes(file, BasicFileAttributes.class) .lastModifiedTime().toInstant(); if (!lastLoaded.equals(mtime)) { lastLoaded = mtime; map = parseMapFile(); } } catch (IOException e) { throw new AuthenticationException("failed to read " + file + ": " + Exceptions.messageOrClassName(e)); } } return map; }
public static void checkResourceNotMissing(boolean isOK, String format, Object...arguments) throws MissingResourceCacheException { genericCheck(isOK, MissingResourceCacheException::new, format, arguments); }
public static void checkFormat(boolean isOK, String template, Object...args) throws GplazmaParseMapFileException { Exceptions.genericCheck(isOK, GplazmaParseMapFileException::new, template, args); }
/** * A utility method that throws an exception if the first argument is false. * @param isAuthenticated boolean value. * @param message an explanation of why the exception was thrown. * @throws AuthenticationException if isAuthenticated is false */ public static void checkAuthentication(boolean isAuthenticated, String message) throws AuthenticationException { genericCheck(isAuthenticated, AuthenticationException::new, message); } }
public static <E extends Exception> void checkChildName(String name, Function<String,E> toException) throws E { genericCheck(!name.isEmpty(), toException, "Name must be non-empty."); genericCheck(!name.contains("/"), toException, "Name must not contain '/'."); genericCheck(!name.equals("."), toException, "Name must not be '.'."); genericCheck(!name.equals(".."), toException, "Name must not be '..'."); }
public static void checkCommand(boolean isOK, String format, Object... arguments) throws CommandException { genericCheck(isOK, m -> new CommandException(m), format, arguments); } }