public AuthenticatorWindow() { SESecurityManager.addPasswordListener(this); // System.out.println( "AuthenticatorWindow"); Map cache = COConfigurationManager.getMapParameter(CONFIG_PARAM, new HashMap()); try { Iterator it = cache.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String key = (String) entry.getKey(); Map value = (Map) entry.getValue(); String user = new String((byte[]) value.get("user"), "UTF-8"); char[] pw = new String((byte[]) value.get("pw"), "UTF-8").toCharArray(); auth_cache.put(key, new authCache(key, new PasswordAuthentication(user, pw), true)); } } catch (Throwable e) { COConfigurationManager.setParameter(CONFIG_PARAM, new HashMap()); Debug.printStackTrace(e); } }
/** Set the focus to the editor containing {@link AttributeNames#QUERY}, if possible. */ @Override public boolean setFocus() { if (editors.containsKey(AttributeNames.QUERY)) { editors.get(AttributeNames.QUERY).setFocus(); return true; } else return false; }
void onValueChanged(String ov, String nv) { String[] vs = (String[]) propertiesHash.get(nv); if (vs == null) vs = new String[0]; String[] ovs = getSelectedProperties(); if (ov != null && ovs != null) propertiesHash.put(ov, ovs); setSelectedProperties(vs); propertyListEditor.updateBar(); }
Accessible childRowToOs(int childID) { if (childID == ACC.CHILDID_SELF) { return tableAccessible; } /* Check cache for childID, if found, return corresponding osChildID. */ AccessibleTableRow childRef = (AccessibleTableRow) childRowToIdMap.get(Integer.valueOf(childID)); if (childRef == null) { childRef = new AccessibleTableRow(tableAccessible, childID); childRowToIdMap.put(Integer.valueOf(childID), childRef); } return childRef; }
public void setAuthenticationOutcome( String realm, String protocol, String host, int port, boolean success) { try { this_mon.enter(); String tracker = protocol + "://" + host + ":" + port + "/"; String auth_key = realm + ":" + tracker; authCache cache = (authCache) auth_cache.get(auth_key); if (cache != null) { cache.setOutcome(success); } } finally { this_mon.exit(); } }
/** @return a map connecting IPath to the resolved bundles in that path */ private Map getFileBundleMapping() { if (fFileBundleMapping != null) { return fFileBundleMapping; } // Map the bundles into their file locations fFileBundleMapping = new HashMap(); for (Iterator iterator = fAllBundles.iterator(); iterator.hasNext(); ) { IResolvedBundle currentBundle = (IResolvedBundle) iterator.next(); IPath parentPath = getParentPath(currentBundle); List bundles = (List) fFileBundleMapping.get(parentPath); if (bundles == null) { bundles = new ArrayList(); bundles.add(currentBundle); fFileBundleMapping.put(parentPath, bundles); } else { bundles.add(currentBundle); } } return fFileBundleMapping; }
/** Sets the <code>key</code> editor's current value to <code>value</code>. */ public void setAttribute(String key, Object value) { final IAttributeEditor editor = editors.get(key); if (editor != null) { editor.setValue(value); } }
/** Create internal GUI. */ private void createComponents(Map<String, Object> currentValues) { /* * Sort alphabetically by label. */ final Locale locale = Locale.getDefault(); final Map<String, String> labels = Maps.newHashMap(); for (Map.Entry<String, AttributeDescriptor> entry : attributeDescriptors.entrySet()) { labels.put(entry.getKey(), getLabel(entry.getValue()).toLowerCase(locale)); } final Collator collator = Collator.getInstance(locale); final List<String> sortedKeys = Lists.newArrayList(labels.keySet()); Collections.sort( sortedKeys, new Comparator<String>() { public int compare(String a, String b) { return collator.compare(labels.get(a), labels.get(b)); } }); /* * Create editors and inquire about their layout needs. */ editors = Maps.newHashMap(); final Map<String, AttributeEditorInfo> editorInfos = Maps.newHashMap(); int maxColumns = 1; for (String key : sortedKeys) { final AttributeDescriptor descriptor = attributeDescriptors.get(key); IAttributeEditor editor = null; try { editor = EditorFactory.getEditorFor(this.componentClazz, descriptor); final AttributeEditorInfo info = editor.init(bindable, descriptor, globalEventsProvider, currentValues); editorInfos.put(key, info); maxColumns = Math.max(maxColumns, info.columns); } catch (EditorNotFoundException ex) { Utils.logError( "No editor for attribute: " + descriptor.key + " (class: " + descriptor.type + ")", false); /* * Skip editor. */ editor = null; } editors.put(key, editor); } /* * Prepare the layout for this editor. */ final GridLayout layout = GUIFactory.zeroMarginGridLayout(); layout.makeColumnsEqualWidth = false; layout.numColumns = maxColumns; this.setLayout(layout); /* * Create visual components for editors. */ final GridDataFactory labelFactory = GridDataFactory.fillDefaults().span(maxColumns, 1); boolean firstEditor = true; for (String key : sortedKeys) { final AttributeDescriptor descriptor = attributeDescriptors.get(key); final IAttributeEditor editor = editors.get(key); final AttributeEditorInfo editorInfo = editorInfos.get(key); if (editor == null) { // Skip attributes without the editor. continue; } final Object defaultValue; if (currentValues != null && currentValues.get(key) != null) { defaultValue = currentValues.get(key); } else { defaultValue = attributeDescriptors.get(key).defaultValue; } // Add label to editors that do not have it. if (!editorInfo.displaysOwnLabel) { final Label label = new Label(this, SWT.LEAD); final GridData gd = labelFactory.create(); if (!firstEditor) { gd.verticalIndent = SPACE_BEFORE_LABEL; } label.setLayoutData(gd); label.setText(getLabel(descriptor) + (descriptor.requiredAttribute ? " (required)" : "")); /* * Add validation overlay. */ addValidationOverlay(descriptor, editor, defaultValue, label); AttributeInfoTooltip.attach(label, descriptor); } // Add the editor, if available. editor.createEditor(this, maxColumns); // Set the default value for the editor. editor.setValue(defaultValue); editors.put(editor.getAttributeKey(), editor); /* * Forward events from this editor to all our listeners. */ editor.addAttributeListener(forwardListener); firstEditor = false; } }
public PasswordAuthentication getAuthentication( String realm, String protocol, String host, int port) { try { this_mon.enter(); String tracker = protocol + "://" + host + ":" + port + "/"; InetAddress bind_ip = NetworkAdmin.getSingleton().getSingleHomedServiceBindAddress(); String self_addr; // System.out.println( "auth req for " + realm + " - " + tracker ); if (bind_ip == null || bind_ip.isAnyLocalAddress()) { self_addr = "127.0.0.1"; } else { self_addr = bind_ip.getHostAddress(); } // when the tracker is connected to internally we don't want to prompt // for the password. Here we return a special user and the password hash // which is picked up in the tracker auth code - search for "<internal>"! // also include the tracker IP as well as for scrapes these can occur on // a raw torrent which hasn't been modified to point to localhost if (host.equals(self_addr) || host.equals(COConfigurationManager.getStringParameter("Tracker IP", ""))) { try { byte[] pw = COConfigurationManager.getByteParameter("Tracker Password", new byte[0]); String str_pw = new String(Base64.encode(pw)); return (new PasswordAuthentication("<internal>", str_pw.toCharArray())); } catch (Throwable e) { Debug.printStackTrace(e); } } String auth_key = realm + ":" + tracker; authCache cache = (authCache) auth_cache.get(auth_key); if (cache != null) { PasswordAuthentication auth = cache.getAuth(); if (auth != null) { return (auth); } } String[] res = getAuthenticationDialog(realm, tracker); if (res == null) { return (null); } else { PasswordAuthentication auth = new PasswordAuthentication(res[0], res[1].toCharArray()); boolean save_pw = res[2].equals("true"); boolean old_entry_existed = auth_cache.put(auth_key, new authCache(auth_key, auth, save_pw)) != null; if (save_pw || old_entry_existed) { saveAuthCache(); } return (auth); } } finally { this_mon.exit(); } }