static public HTTPAuthStore // public to allow testing getDeserializedStore(ObjectInputStream ois) throws HTTPException { List<Entry> entries = getDeserializedEntries(ois); HTTPAuthStore store = new HTTPAuthStore(); store.rows = entries; return store; }
public void print(PrintWriter p) throws IOException { List<Entry> elist = getAllRows(); for(int i = 0; i < elist.size(); i++) { Entry e = elist.get(i); p.printf("[%02d] %s%n", i, e.toString()); } }
static public void setGlobalCredentialsProvider(CredentialsProvider provider) { defineCredentialsProvider(ANY_PRINCIPAL, HTTPAuthScope.ANY, provider, HTTPAuthStore.getDefault()); }
synchronized public void deserialize(InputStream istream, String password) throws HTTPException { ObjectInputStream ois = null; try { ois = openobjectstream(istream, password); List<Entry> entries = getDeserializedEntries(ois); for(Entry e : entries) { insert(e); } } finally { if(ois != null) try { ois.close(); } catch (IOException e) {/*ignore*/} } }
static synchronized protected void defineCredentialsProvider(String principal, AuthScope scope, CredentialsProvider provider, HTTPAuthStore store) { // Add/remove entry to AuthStore try { if(provider == null) {//remove store.remove(new HTTPAuthStore.Entry(principal, scope, provider)); } else { // add store.insert(new HTTPAuthStore.Entry(principal, scope, provider)); } } catch (HTTPException he) { log.error("HTTPSession.setCredentialsProvider failed"); } }
/** * Search for all equivalent rows, then sort on the path. * * @param scope * @return list of matching entries */ synchronized public List<Entry> search(String principal, AuthScope scope) { List<Entry> matches; if(isdefault || DEFAULT == null) matches = new ArrayList<Entry>(); else matches = DEFAULT.search(principal, scope); if(scope == null || rows.size() == 0) return matches; for(Entry e : getAllRows()) { if(principal != ANY_PRINCIPAL && e.principal.equals(principal)) continue; if(HTTPAuthScope.equivalent(scope, e.scope)) matches.add(e); } Collections.sort(matches); return matches; }
/** * @param scope * @param provider * @return old provider if entry already existed and was replaced, else null. */ synchronized public CredentialsProvider insert(String principal, AuthScope scope, CredentialsProvider provider) throws HTTPException { return insert(new Entry(principal, scope, provider)); }
/** * @param entry * @return old entry if entry existed and was removed */ synchronized public Entry remove(Entry entry) throws HTTPException { Entry found = null; if(entry == null) throw new HTTPException("HTTPAuthStore.remove: invalid entry: " + entry); for(Entry e : rows) { if(equivalent(e, entry)) { found = e; break; } } if(found != null) rows.remove(found); return (found); }
public void print(PrintStream p) throws IOException { print(new PrintWriter(new OutputStreamWriter(p, Escape.utf8Charset), true)); }
public void clearState() { sessionClient.getCredentialsProvider().clear(); sessionClient.getCookieStore().clear(); execcontext = new BasicHttpContext(); localsettings.clear(); authlocal.clear(); }
try { AuthScope scope = new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, HTTPAuthPolicy.SSL); insert(new Entry(ANY_PRINCIPAL, scope, creds)); } catch (HTTPException he) { log.error("HTTPAuthStore: could not insert default SSL data");
/** * @param entry * @return old provider if entry already existed and was replaced, else null. */ synchronized public CredentialsProvider insert(Entry entry) throws HTTPException { Entry found = null; if(entry == null) throw new HTTPException("HTTPAuthStore.insert: invalid entry: " + entry); for(Entry e : rows) { if(equivalent(e, entry)) { found = e; break; } } // If the entry already exists, then overwrite it and return old CredentialsProvider old = null; if(found != null) { old = entry.provider; found.provider = entry.provider; } else { Entry newentry = new Entry(ANY_PRINCIPAL, entry.scope, entry.provider); rows.add(newentry); } return old; }
static public void setGlobalCredentialsProvider(AuthScope scope, CredentialsProvider provider) { defineCredentialsProvider(ANY_PRINCIPAL, scope, provider, HTTPAuthStore.getDefault()); }
synchronized public void serialize(OutputStream ostream, String password) throws HTTPException { try { // Create Key byte deskey[] = password.getBytes(Escape.utf8Charset); DESKeySpec desKeySpec = new DESKeySpec(deskey); //Coverity[RISKY_CRYPTO] SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey secretKey = keyFactory.generateSecret(desKeySpec); // Create Cipher Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); desCipher.init(Cipher.ENCRYPT_MODE, secretKey); // Create crypto stream BufferedOutputStream bos = new BufferedOutputStream(ostream); CipherOutputStream cos = new CipherOutputStream(bos, desCipher); ObjectOutputStream oos = new ObjectOutputStream(cos); oos.writeInt(getAllRows().size()); for(Entry e : getAllRows()) { oos.writeObject(e); } oos.flush(); oos.close(); } catch (Exception e) { throw new HTTPException(e); } }