public class HostPageUtils { private static final native String getSerializedUser() /*-{ return $wnd.serialized_user; }-*/; public static User getUser() { final String serializedUser = getSerializedUser(); StorageSerializer storageSerializer = GWT.create(StorageSerializer.class); try { return storageSerializer.deserialize(User.class, serializedUser); } catch (Exception e) { throw new RuntimeException(); } } }
/** * Get the record value, using a custom deserialization process. * * @param serializer a custom (de)serialization process to apply * @param context context of record * @param key key of record * @return the record value * @throws IOException if deserialization fails */ @Nonnull public Type getValue(@Nonnull final StorageSerializer<Type> serializer, @Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key) throws IOException { return serializer.deserialize(version, context, key, value, expiration); }
/** {@inheritDoc} */ @Override @Nonnull public AuthenticationResult deserialize(final long version, @Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nonnull final Long expiration) throws IOException { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); // Back the expiration off by the inactivity timeout to recover the last activity time. return resultSerializer.deserialize(version, context, key, value, (expiration != null) ? expiration - inactivityTimeout - STORAGE_EXPIRATION_OFFSET : null); }
/** * Decode a ticket. * * @param ticketClass class of ticket * @param id ticket ID * @param prefix ticket ID prefix * @param <T> type of ticket * * @return decoded ticket */ private <T extends Ticket> T decode(final Class<T> ticketClass, final String id, final String prefix) { try { final String decrypted = dataSealer.unwrap(id.substring(prefix.length() + 1)); return serializer(ticketClass).deserialize(0, NOT_USED, id, decrypted, 0L); } catch (final Exception e) { log.warn("Ticket decoding failed with error: " + e.getMessage()); log.debug("Ticket decoding failed", e); } return null; } }
return spSessionSerializer.deserialize( 1, "session", "key", decrypted.substring(pos + 1), System.currentTimeMillis()); } catch (final ClassNotFoundException | IOException | DataSealerException e) {
/** {@inheritDoc} */ @Override @Nullable public AuthenticationResultPrincipal deserialize(@Nonnull @NotEmpty final String value) throws IOException { final JsonReader reader = getJsonReader(new StringReader(value)); JsonStructure st = null; try { st = reader.read(); } finally { reader.close(); } if (!(st instanceof JsonObject)) { throw new IOException("Found invalid data structure while parsing AuthenticationResultPrincipal"); } final JsonObject obj = (JsonObject) st; final JsonValue str = obj.get(PRINCIPAL_NAME_FIELD); if (str != null && str instanceof JsonString) { return new AuthenticationResultPrincipal( resultSerializer.deserialize(1, "context", "key", ((JsonString) str).getString(), null)); } else { log.warn("Skipping non-string principal value"); } return null; }
return spSessionSerializer.deserialize( record.getVersion(), getId(), key, record.getValue().substring(pos + 1), record.getExpiration());