private static void setLocales(final SavedRequest savedRequest, final List<Locale> locales) { if(locales != null && !locales.isEmpty()) { for (final Locale locale : locales) { savedRequest.addLocale(locale); } } }
private static void setHeaders(final SavedRequest obj, final Map<String, List<String>> headers) { if(headers != null) { for (final Entry<String, List<String>> entry : headers.entrySet()) { final List<String> values = entry.getValue(); for (final String value : values) { obj.addHeader(entry.getKey(), value); } } } }
AuthConfigFactory.setFactory(new AuthConfigFactoryImpl()); DigestAuthenticator authenticator = new DigestAuthenticator(); authenticator.setNonceValidity(10 * 1000L); // Shorten from 5 minutes to 10 seconds authenticator.setNonceCacheSize(20000); // Increase from 1000 to 20000 context.getPipeline().addValve(authenticator);
@SuppressWarnings("unchecked") private static SavedRequest deserializeSavedRequest( final byte[] data ) { ByteArrayInputStream bis = null; ObjectInputStream ois = null; try { bis = new ByteArrayInputStream( data ); ois = new ObjectInputStream( bis ); final SavedRequest savedRequest = new SavedRequest(); savedRequest.setBody((ByteChunk) ois.readObject()); savedRequest.setContentType((String) ois.readObject()); // no cookies support setCookies(savedRequest, ois.readObject()); setHeaders(savedRequest, (Map<String, List<String>>) ois.readObject()); setLocales(savedRequest, (List<Locale>) ois.readObject()); savedRequest.setMethod((String) ois.readObject()); savedRequest.setQueryString((String) ois.readObject()); savedRequest.setRequestURI((String) ois.readObject()); savedRequest.setDecodedRequestURI((String) ois.readObject()); return savedRequest; } catch ( final IOException e ) { throw new IllegalArgumentException( "Could not deserialize SavedRequest", e ); } catch ( final ClassNotFoundException e ) { throw new IllegalArgumentException( "Could not deserialize SavedRequest", e ); } finally { closeSilently( bis ); closeSilently( ois ); } }
private static byte[] serializeSavedRequest( final Object obj ) { if(obj == null) { return null; } final SavedRequest savedRequest = (SavedRequest) obj; ByteArrayOutputStream bos = null; ObjectOutputStream oos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream( bos ); oos.writeObject(savedRequest.getBody()); oos.writeObject(savedRequest.getContentType()); // Cookies not cloneable... omit for now - oos.writeObject(newArrayList(savedRequest.getCookies())); oos.writeObject(getHeaders(savedRequest)); oos.writeObject(newArrayList(savedRequest.getLocales())); oos.writeObject(savedRequest.getMethod()); // obj.getParameters() are not used in tc6 and not existing in tc7 // -> we omit them here oos.writeObject(savedRequest.getQueryString()); oos.writeObject(savedRequest.getRequestURI()); oos.writeObject(savedRequest.getDecodedRequestURI()); oos.flush(); return bos.toByteArray(); } catch ( final IOException e ) { throw new IllegalArgumentException( "Non-serializable object", e ); } finally { closeSilently( bos ); closeSilently( oos ); } }
@Test public void testSerializeSessionFieldsIncludesFormRequestNote() { final MemcachedBackupSession session = (MemcachedBackupSession) _manager.createSession( null ); final SavedRequest saved = new SavedRequest(); saved.setQueryString("foo=bar"); saved.setRequestURI("http://www.foo.org"); session.setNote(Constants.FORM_REQUEST_NOTE, saved); final byte[] data = TranscoderService.serializeSessionFields( session ); final MemcachedBackupSession deserialized = TranscoderService.deserializeSessionFields(data, _manager ).getSession(); final SavedRequest actual = (SavedRequest) deserialized.getNote(Constants.FORM_REQUEST_NOTE); assertNotNull(actual); assertDeepEquals(actual, saved); }
@Override public synchronized void start() throws LifecycleException { super.start(); // Generate a random secret key if (getKey() == null) { setKey(generateSessionId()); } // Generate the opaque string the same way if (getOpaque() == null) { setOpaque(generateSessionId()); } }
private static Map<String, List<String>> getHeaders(final SavedRequest obj) { final Map<String, List<String>> result = new HashMap<String, List<String>>(); final Iterator<String> namesIter = obj.getHeaderNames(); while (namesIter.hasNext()) { final String name = namesIter.next(); final List<String> values = new ArrayList<String>(); result.put(name, values); final Iterator<String> valuesIter = obj.getHeaderValues(name); while (valuesIter.hasNext()) { final String value = valuesIter.next(); values.add(value); } } return result; }
/** * Removes the quotes on a string. * * @param quotedString The quoted string * @return The unquoted string */ protected static String removeQuotes(String quotedString) { return removeQuotes(quotedString, false); }
/** * Associate the specified single sign on identifier with the * specified Session. * * @param ssoId Single sign on identifier * @param session Session to be associated */ protected void associate(String ssoId, Session session) { if (sso == null) return; sso.associate(ssoId, session); }
/** * Look up and return the cached SingleSignOn entry associated with this * sso id value, if there is one; otherwise return <code>null</code>. * * @param ssoId Single sign on identifier to look up * @param ssoVersion Single sign on version to look up */ protected SingleSignOnEntry lookup(String ssoId, long ssoVersion) { return lookup(ssoId); }
/** * Initialize the database we will be using for client verification * and certificate validation (if any). * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ public void start() throws LifecycleException { super.start(); }
/** * Return the entropy increaser value, or compute a semi-useful value * if this String has not yet been set. */ public String getEntropy() { // Calculate a semi-useful value if this has not been set if (this.entropy == null) setEntropy(this.toString()); return (this.entropy); }
private boolean length() { // No need to retain the length - just need to consume it and make // sure it is valid. int len = lengthAsInt(); return pos + len == token.length; }
/** * Removes the quotes on a string. */ protected static String removeQuotes(String quotedString) { return removeQuotes(quotedString, false); }
/** * Associate the specified single sign on identifier with the * specified Session. * * @param ssoId Single sign on identifier * @param session Session to be associated */ protected void associate(String ssoId, Session session) { if (sso == null) return; sso.associate(ssoId, session); }
/** * Initialize the database we will be using for client verification * and certificate validation (if any). * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ public void start() throws LifecycleException { super.start(); }
/** * Return the entropy increaser value, or compute a semi-useful value * if this String has not yet been set. */ public String getEntropy() { // Calculate a semi-useful value if this has not been set if (this.entropy == null) setEntropy(this.toString()); return (this.entropy); }
/** * Removes the quotes on a string. */ protected static String removeQuotes(String quotedString) { return removeQuotes(quotedString, false); }
/** * Removes the quotes on a string. */ protected static String removeQuotes(String quotedString) { return removeQuotes(quotedString, false); }