SecurityUtils { public static String tryDecode(String value) { if (value != null && value.startsWith("~{") && value.endsWith("}")) { try { return decode(value.substring(2, value.length() - 1)); } catch (Exception e) { logger.error("failed to decode: " + value + ", " + e); } } return value; }  static User getCurrentUser(); static Integer getCurrentUserId(); static void setCurrentUser(User user); static void clearCurrentUser(); static String tryDecode(String value); static String tryEncode(String value);  }
@Test public void testTryDecode() throws IOException { String decoded = SecurityUtils.tryDecode(null); assertNull(decoded); decoded = SecurityUtils.tryDecode(""); assertEquals("", decoded); decoded = SecurityUtils.tryDecode("hello"); assertEquals("hello", decoded); decoded = SecurityUtils.tryDecode("~{d3b4f5e2a4b3c1a0622267e0b011b61150b0b0a5f913267ad}"); assertEquals("dp!@78()-=", decoded); decoded = SecurityUtils.tryDecode("~{hello}"); assertEquals("~{hello}", decoded); }