/** * This fires during the Render Response phase, saving state. */ public static final String construct(Object object, ExternalContext ctx){ byte[] bytes = getAsByteArray(object, ctx); if( enableCompression(ctx) ) bytes = compress(bytes); if(isSecure(ctx)) bytes = encrypt(bytes, ctx); bytes = encode(bytes); try { return new String(bytes, ZIP_CHARSET); } catch (UnsupportedEncodingException e) { throw new FacesException(e); } }
/** * This fires during the Restore View phase, restoring state. */ public static final Object reconstruct(String string, ExternalContext ctx){ byte[] bytes; try { bytes = string.getBytes(ZIP_CHARSET); bytes = decode(bytes); if(isSecure(ctx)) bytes = decrypt(bytes, ctx); if( enableCompression(ctx) ) bytes = decompress(bytes); return getAsObject(bytes, ctx); } catch (UnsupportedEncodingException e) { throw new FacesException(e); } }
throw new NullPointerException("ExternalContext ctx"); testConfiguration(ctx); String _algorithm = findAlgorithm(ctx); String _algorithmParams = findAlgorithmParams(ctx); byte[] iv = findInitializationVector(ctx); + "in application scope using the key '" + INIT_SECRET_KEY_CACHE + "'"); return symmetric(data, (SecretKey)object, _algorithm, _algorithmParams, iv, mode);
/** * Does nothing if the user has disabled the SecretKey cache. This is * useful when dealing with a JCA provider whose SecretKey * implementation is not thread safe. * * Instantiates a SecretKey instance based upon what the user has * specified in the deployment descriptor. The SecretKey is then * stored in application scope where it can be used for all requests. */ public static void initSecret(ServletContext ctx){ if(ctx == null) throw new NullPointerException("ServletContext ctx"); if (log.isDebugEnabled()) log.debug("Storing SecretKey @ " + INIT_SECRET_KEY_CACHE); // you want to create this as few times as possible ctx.setAttribute(INIT_SECRET_KEY_CACHE, new SecretKeySpec(findSecret(ctx), findAlgorithm(ctx))); }
throw new NullPointerException("ExternalContext ctx"); testConfiguration(ctx); SecretKey secretKey = (SecretKey) getSecret(ctx); String algorithm = findAlgorithm(ctx); String algorithmParams = findAlgorithmParams(ctx); byte[] iv = findInitializationVector(ctx); SecretKey macSecretKey = (SecretKey) getMacSecret(ctx); String macAlgorithm = findMacAlgorithm(ctx);
String algorithm = findAlgorithm(ctx); ctx.setAttribute(INIT_SECRET_KEY_CACHE, new SecretKeySpec(findSecret(ctx, algorithm), algorithm)); String macAlgorithm = findMacAlgorithm(ctx); ctx.setAttribute(INIT_MAC_SECRET_KEY_CACHE, new SecretKeySpec(findMacSecret(ctx, macAlgorithm), macAlgorithm));
private static String findAlgorithm(ServletContext ctx) { return findAlgorithm( ctx.getInitParameter(INIT_ALGORITHM) ); }
@Override public String getViewState(FacesContext facesContext, Object baseState) { if (baseState == null) { return null; } Object state = null; if (isHandlingStateCachingMechanics(facesContext)) { state = getStateCache(facesContext).saveSerializedView(facesContext, baseState); } else { state = baseState; } Object[] savedState = new Object[2]; if (state != null) { savedState[STATE_PARAM] = state; } savedState[VIEWID_PARAM] = facesContext.getViewRoot().getViewId(); return StateUtils.construct(savedState, facesContext.getExternalContext()); }
/** * Utility method for generating base 64 encoded strings. * * @param args * @throws UnsupportedEncodingException */ public static void main (String[] args) throws UnsupportedEncodingException { byte[] bytes = encode(args[0].getBytes(ZIP_CHARSET)); System.out.println(new String(bytes, ZIP_CHARSET)); }
throw new NullPointerException("ExternalContext ctx"); testConfiguration(ctx); SecretKey secretKey = (SecretKey) getSecret(ctx); String algorithm = findAlgorithm(ctx); String algorithmParams = findAlgorithmParams(ctx); byte[] iv = findInitializationVector(ctx); SecretKey macSecretKey = (SecretKey) getMacSecret(ctx); String macAlgorithm = findMacAlgorithm(ctx);
String algorithm = findAlgorithm(ctx); ctx.setAttribute(INIT_SECRET_KEY_CACHE, new SecretKeySpec(findSecret(ctx, algorithm), algorithm)); String macAlgorithm = findMacAlgorithm(ctx); ctx.setAttribute(INIT_MAC_SECRET_KEY_CACHE, new SecretKeySpec(findMacSecret(ctx, macAlgorithm), macAlgorithm));
String algorithm = findAlgorithm(ctx); secretKey = new SecretKeySpec(findSecret(ctx, algorithm), algorithm);
private static String findAlgorithm(ServletContext ctx) { String algorithm = ctx.getInitParameter(INIT_ALGORITHM); if (algorithm == null) { algorithm = ctx.getInitParameter(INIT_ALGORITHM.toLowerCase()); } return findAlgorithm( algorithm ); }
return StateUtils.construct(savedState, facesContext.getExternalContext());
/** * Utility method for generating base 63 encoded strings. * * @param args * @throws UnsupportedEncodingException */ public static void main (String[] args) throws UnsupportedEncodingException { byte[] bytes = encode(args[0].getBytes(ZIP_CHARSET)); System.out.println(new String(bytes, ZIP_CHARSET)); }
throw new NullPointerException("ExternalContext ctx"); testConfiguration(ctx); SecretKey secretKey = (SecretKey) getSecret(ctx); String algorithm = findAlgorithm(ctx); String algorithmParams = findAlgorithmParams(ctx); byte[] iv = findInitializationVector(ctx); SecretKey macSecretKey = (SecretKey) getMacSecret(ctx); String macAlgorithm = findMacAlgorithm(ctx);
/** * This fires during the Render Response phase, saving state. */ public static final String construct(Object object, ExternalContext ctx){ byte[] bytes = getAsByteArray(object, ctx); if( enableCompression(ctx) ) bytes = compress(bytes); if(isSecure(ctx)) bytes = encrypt(bytes, ctx); bytes = encode(bytes); try { return new String(bytes, ZIP_CHARSET); } catch (UnsupportedEncodingException e) { throw new FacesException(e); } }
/** * This fires during the Restore View phase, restoring state. */ public static final Object reconstruct(String string, ExternalContext ctx) { byte[] bytes; try { if(log.isLoggable(Level.FINE)) log.fine("Processing state : "+string); bytes = string.getBytes(ZIP_CHARSET); bytes = decode(bytes); if(isSecure(ctx)) bytes = decrypt(bytes, ctx); if( enableCompression(ctx) ) bytes = decompress(bytes); return getAsObject(bytes, ctx); } catch (Throwable e) { if (log.isLoggable(Level.SEVERE)) { log.log(Level.SEVERE, "View State cannot be reconstructed", e); } return null; } }
String algorithm = findAlgorithm(ctx); secretKey = new SecretKeySpec(findSecret(ctx, algorithm), algorithm);
private static String findAlgorithm(ServletContext ctx) { String algorithm = ctx.getInitParameter(INIT_ALGORITHM); if (algorithm == null) { algorithm = ctx.getInitParameter(INIT_ALGORITHM.toLowerCase()); } return findAlgorithm( algorithm ); }