List of usage examples for java.util Hashtable put
public synchronized V put(K key, V value)
From source file:com.flexive.shared.FxArrayUtils.java
/** * Removes dupicated entries from the list. * * @param list the list//w ww . j a v a 2 s . c o m * @return the list without any duplicated entries */ public static int[] removeDuplicates(int[] list) { if (list == null || list.length == 0) { return new int[0]; } Hashtable<Integer, Boolean> tbl = new Hashtable<Integer, Boolean>(list.length); for (int ele : list) { tbl.put(ele, Boolean.FALSE); } int[] result = new int[tbl.size()]; int pos = 0; for (Enumeration e = tbl.keys(); e.hasMoreElements();) { result[pos++] = (Integer) e.nextElement(); } return result; }
From source file:fr.iphc.grid.jobmonitor.CeList.java
static public ArrayList<URL> AvailableLdapCe() throws Exception { ArrayList<URL> CeList = new ArrayList<URL>(); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://cclcgtopbdii01.in2p3.fr:2170"); env.put("java.naming.ldap.attributes.binary", "objectSID"); try {/*from w ww .j ava 2s . c o m*/ // Create initial context DirContext ctx = new InitialDirContext(env); SearchControls contraints = new SearchControls(); contraints.setSearchScope(SearchControls.SUBTREE_SCOPE); String[] attributIDs = { "GlueCEUniqueID" }; contraints.setReturningAttributes(attributIDs); String BASE_SEARCH = "Mds-Vo-name=local,o=grid"; String filter = "(&(objectClass=GlueCE)(GlueCEImplementationName=CREAM)(GlueCEAccessControlBaseRule=VO:biomed))"; NamingEnumeration<SearchResult> answer = ctx.search(BASE_SEARCH, filter, contraints); // int index = 0; Random rand = new Random(); while (answer.hasMore()) { // index++; SearchResult result = answer.next(); // Attributes attrs = result.getAttributes(); // NamingEnumeration f = attrs.getAll(); // Attribute attr = (Attribute) f.next(); String line = "cream://" + result.getAttributes().get("GlueCEUniqueID").get() + "?delegationId=" + rand.nextLong(); URL serviceURL = URLFactory.createURL(line); CeList.add(serviceURL); } // Close the context when we're done ctx.close(); } catch (Exception e) { e.printStackTrace(); } ; return CeList; }
From source file:net.hardisonbrewing.signingserver.service.SigStatusService.java
public static Hashtable parse(JSONArray sigs) throws JSONException { int length = sigs.length(); if (length == 0) { return null; }//from w w w.java 2s . co m Hashtable result = new Hashtable(); for (int i = 0; i < length; i++) { JSONObject sig = sigs.getJSONObject(i); SigStatus _status = new SigStatus(); _status.sig = sig.getString("sig"); _status.success = sig.getBoolean("success"); _status.repeat = sig.getInt("repeat"); _status.speed = sig.getDouble("speed"); _status.aspeed = sig.getDouble("aspeed"); _status.date = sig.getLong("date"); result.put(_status.sig, _status); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("Received sig["); stringBuffer.append(_status.sig); stringBuffer.append("], success["); stringBuffer.append(_status.success); stringBuffer.append("], repeat["); stringBuffer.append(_status.repeat); stringBuffer.append("], speed["); stringBuffer.append(_status.speed); stringBuffer.append("], aspeed["); stringBuffer.append(_status.aspeed); stringBuffer.append("], date["); stringBuffer.append(_status.date); stringBuffer.append("]"); SigservApplication.logEvent(stringBuffer.toString()); } return result; }
From source file:edu.lafayette.metadb.model.userman.UserManDAO.java
/** * Get the LDAP DN for a user./*from ww w . ja v a 2 s . co m*/ * @param searchUser * @param searchPassword * @param userName * @return */ @SuppressWarnings("unchecked") private static String getDN(String searchUser, String searchPassword, String userName) { // The resultant DN String result; // Set up environment for creating initial context Hashtable env = new Hashtable(11); env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(javax.naming.Context.PROVIDER_URL, Global.LDAP_URL); // Use admin credencials for search// Authenticate env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "Simple"); env.put(javax.naming.Context.SECURITY_PRINCIPAL, searchUser); env.put(javax.naming.Context.SECURITY_CREDENTIALS, searchPassword); DirContext ctx = null; try { // Create initial context ctx = new InitialDirContext(env); //MetaDbHelper.note("Created LDAP context"); Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute(Global.LDAP_ID, userName)); //MetaDbHelper.note("Created attributes"); // look up attributes try { //MetaDbHelper.note("Setting up query"); SearchControls ctrls = new SearchControls(); ctrls.setSearchScope(Global.LDAP_SCOPE); NamingEnumeration<SearchResult> answer = ctx.search(Global.LDAP_URL + Global.LDAP_CONTEXT, "(&({0}={1}))", new Object[] { Global.LDAP_ID, userName }, ctrls); //MetaDbHelper.note("NamingEnumeration retrieved"); while (answer.hasMoreElements()) { SearchResult sr = answer.next(); if (StringUtils.isEmpty(Global.LDAP_CONTEXT)) { result = sr.getName(); } else { result = (sr.getName() + "," + Global.LDAP_CONTEXT); } //MetaDbHelper.note("Got DN: "+result); return result; } } catch (NamingException e) { MetaDbHelper.logEvent(e); //MetaDbHelper.note("LDAP Error: Failed Search"); } } catch (NamingException e) { MetaDbHelper.logEvent(e); //MetaDbHelper.note("LDAP Error: Failed authentication"); } finally { // Close the context when we're done try { if (ctx != null) ctx.close(); } catch (NamingException e) { } } // No DN match found return null; }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UmlsCommon.LoadRRFToDB.java
private static Hashtable readMRCols(URI rrfLocation) throws MalformedURLException, IOException { Hashtable result = new Hashtable(); BufferedReader reader = getReader(rrfLocation.resolve("MRCOLS.RRF")); String line = reader.readLine(); while (line != null) { String[] vals = stringToArray(line, '|'); String key = vals[0] + "|" + vals[6]; result.put(key, vals[7]); line = reader.readLine();/*from w ww.j a v a 2 s. co m*/ } reader.close(); return result; }
From source file:edu.lafayette.metadb.model.userman.UserManDAO.java
/** * Perform LDAP authentication for a user. * @param userName The username to authenticate. * @param password The password to authenticate. * @return true if the user was successfully authenticated by LDAP, false otherwise. *///from w ww.j a v a 2s . c o m private static boolean authLDAP(String userName, String password) { String searchUser = Global.LDAP_BROWSE_USERNAME; String searchPassword = Global.LDAP_BROWSE_PASSWORD; String dn = null; if (searchUser.equals("") || searchPassword.equals("") || searchUser == null || searchPassword == null) dn = Global.LDAP_ID + "=" + userName + "," + Global.LDAP_CONTEXT; else { dn = getDN(searchUser, searchPassword, userName); // Check a DN was found if ((dn == null) || (dn.trim().equals(""))) { //MetaDbHelper.note("Hierarchical LDAP Authentication Error: No DN found for user "+userName); return false; } } boolean success = false; // Set up environment for creating initial context Hashtable<String, String> env = new Hashtable<String, String>(); env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(javax.naming.Context.PROVIDER_URL, Global.LDAP_URL); // Authenticate env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "Simple"); env.put(javax.naming.Context.SECURITY_PRINCIPAL, dn); env.put(javax.naming.Context.SECURITY_CREDENTIALS, password); env.put(javax.naming.Context.AUTHORITATIVE, "true"); env.put(javax.naming.Context.REFERRAL, "follow"); DirContext ctx = null; try { // Try to bind ctx = new InitialDirContext(env); success = true; //MetaDbHelper.note("User "+userName+" logged in with LDAP"); //MetaDbHelper.note("Context name: "+ctx.getNameInNamespace()); //MetaDbHelper.note(ctx.toString()); } catch (NamingException e) { MetaDbHelper.note("Error: Failed to authenticate " + userName + ".\n" + e); success = false; } finally { // Close the context when we're done try { if (ctx != null) ctx.close(); //MetaDbHelper.note("LDAP connection closed"); } catch (NamingException e) { MetaDbHelper.logEvent(e); //MetaDbHelper.note("Error: Failed to establish context."); } } return success; }
From source file:edu.harvard.hul.ois.fits.tools.utils.XsltTransformMap.java
public static Hashtable getMap(String config) throws FitsConfigurationException { Hashtable mappings = new Hashtable(); XMLConfiguration conf = null;//w w w. j av a 2 s . co m try { conf = new XMLConfiguration(config); } catch (ConfigurationException e) { throw new FitsConfigurationException("Error reading " + config + "fits.xml", e); } List fields = conf.configurationsAt("map"); for (Iterator it = fields.iterator(); it.hasNext();) { HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next(); // sub contains now all data about a single field String format = sub.getString("[@format]"); String transform = sub.getString("[@transform]"); mappings.put(format, transform); } return mappings; }
From source file:fr.paris.lutece.plugins.search.solr.web.SolrSearchApp.java
private static void isSwitched(String strFacetQuery, Hashtable<String, Boolean> tabType) { if (strFacetQuery != null && tabType != null && tabType.containsKey(strFacetQuery) && tabType.get(strFacetQuery) == Boolean.FALSE) { tabType.remove(strFacetQuery);// w w w. j a v a 2 s .c o m tabType.put(strFacetQuery, Boolean.TRUE); } }
From source file:fr.paris.lutece.plugins.search.solr.web.SolrSearchApp.java
private static Hashtable<String, Boolean> getSwitched() { Hashtable<String, Boolean> tabFromSwitch = new Hashtable<String, Boolean>(); for (Field tmpField : SolrFieldManager.getFacetList().values()) { if (tmpField.getEnableFacet() && "SWITCH".equalsIgnoreCase(tmpField.getOperator())) { tabFromSwitch.put(tmpField.getName(), Boolean.FALSE); }/*from w w w .j a va2 s.c o m*/ } return tabFromSwitch; }
From source file:edu.ucsb.nceas.metacat.util.RequestUtil.java
/** * Get a cookie from a request by the cookie name * /*from w w w.j av a 2s.c om*/ * @param request * the request from which to get the cookie * @param cookieName * the name of the cookie to look for */ @SuppressWarnings("unchecked") public static Hashtable<String, String[]> getParameters(HttpServletRequest request) { Hashtable<String, String[]> params = new Hashtable<String, String[]>(); Enumeration<String> paramlist = (Enumeration<String>) request.getParameterNames(); while (paramlist.hasMoreElements()) { String name = (String) paramlist.nextElement(); String[] value = request.getParameterValues(name); params.put(name, value); } return params; }