Lines 46-53
Link Here
|
46 |
|
46 |
|
47 |
import java.io.File; |
47 |
import java.io.File; |
48 |
import java.io.IOException; |
48 |
import java.io.IOException; |
49 |
import java.util.concurrent.ExecutionException; |
|
|
50 |
import java.util.concurrent.TimeoutException; |
51 |
import java.util.logging.Logger; |
49 |
import java.util.logging.Logger; |
52 |
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; |
50 |
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; |
53 |
import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; |
51 |
import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; |
Lines 67-83
Link Here
|
67 |
import java.util.List; |
65 |
import java.util.List; |
68 |
import java.util.Map; |
66 |
import java.util.Map; |
69 |
import java.util.Set; |
67 |
import java.util.Set; |
70 |
import java.util.concurrent.Callable; |
|
|
71 |
import java.util.concurrent.CopyOnWriteArrayList; |
68 |
import java.util.concurrent.CopyOnWriteArrayList; |
72 |
import java.util.concurrent.Future; |
|
|
73 |
import java.util.concurrent.TimeUnit; |
74 |
import java.util.logging.Level; |
69 |
import java.util.logging.Level; |
75 |
import javax.swing.SwingUtilities; |
|
|
76 |
import org.netbeans.api.annotations.common.CheckForNull; |
70 |
import org.netbeans.api.annotations.common.CheckForNull; |
77 |
import org.netbeans.api.annotations.common.NonNull; |
71 |
import org.netbeans.api.annotations.common.NonNull; |
78 |
import org.netbeans.api.annotations.common.NullAllowed; |
72 |
import org.netbeans.api.annotations.common.NullAllowed; |
79 |
import org.netbeans.api.keyring.Keyring; |
73 |
import org.netbeans.api.keyring.Keyring; |
80 |
import org.netbeans.api.progress.ProgressUtils; |
|
|
81 |
import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; |
74 |
import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; |
82 |
import org.netbeans.modules.j2ee.deployment.plugins.api.AlreadyRegisteredException; |
75 |
import org.netbeans.modules.j2ee.deployment.plugins.api.AlreadyRegisteredException; |
83 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory; |
76 |
import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory; |
Lines 87-93
Link Here
|
87 |
import org.openide.filesystems.FileEvent; |
80 |
import org.openide.filesystems.FileEvent; |
88 |
import org.openide.filesystems.FileObject; |
81 |
import org.openide.filesystems.FileObject; |
89 |
import org.openide.filesystems.FileUtil; |
82 |
import org.openide.filesystems.FileUtil; |
90 |
import org.openide.util.RequestProcessor; |
|
|
91 |
|
83 |
|
92 |
public final class ServerRegistry implements java.io.Serializable { |
84 |
public final class ServerRegistry implements java.io.Serializable { |
93 |
|
85 |
|
Lines 99-106
Link Here
|
99 |
public static final String TARGETNAME_ATTR = "targetName"; //NOI18N |
91 |
public static final String TARGETNAME_ATTR = "targetName"; //NOI18N |
100 |
public static final String SERVER_NAME = "serverName"; //NOI18N |
92 |
public static final String SERVER_NAME = "serverName"; //NOI18N |
101 |
|
93 |
|
102 |
private static final RequestProcessor KEYRING_ACCESS = new RequestProcessor(); |
|
|
103 |
|
104 |
private static ServerRegistry instance = null; |
94 |
private static ServerRegistry instance = null; |
105 |
public synchronized static ServerRegistry getInstance() { |
95 |
public synchronized static ServerRegistry getInstance() { |
106 |
if(instance == null) instance = new ServerRegistry(); |
96 |
if(instance == null) instance = new ServerRegistry(); |
Lines 424-435
Link Here
|
424 |
LOGGER.log(Level.INFO, null, ioe); |
414 |
LOGGER.log(Level.INFO, null, ioe); |
425 |
} |
415 |
} |
426 |
} |
416 |
} |
427 |
KEYRING_ACCESS.post(new Runnable() { |
417 |
|
428 |
@Override |
418 |
Keyring.delete(getPasswordKey(url)); |
429 |
public void run() { |
|
|
430 |
Keyring.delete(getPasswordKey(url)); |
431 |
} |
432 |
}); |
433 |
} |
419 |
} |
434 |
|
420 |
|
435 |
/** |
421 |
/** |
Lines 651-747
Link Here
|
651 |
public static Profiler getProfiler() { |
637 |
public static Profiler getProfiler() { |
652 |
return (Profiler)Lookup.getDefault().lookup(Profiler.class); |
638 |
return (Profiler)Lookup.getDefault().lookup(Profiler.class); |
653 |
} |
639 |
} |
654 |
|
640 |
|
655 |
@CheckForNull |
641 |
@CheckForNull |
656 |
static String readPassword(@NonNull final String url) { |
642 |
static String readPassword(@NonNull final String url) { |
657 |
Callable<String> call = new Callable<String>() { |
643 |
char[] passwordChars = Keyring.read(getPasswordKey(url)); |
658 |
@Override |
644 |
if (passwordChars != null) { |
659 |
public String call() throws Exception { |
645 |
String password = String.valueOf(passwordChars); |
660 |
char[] passwordChars = Keyring.read(getPasswordKey(url)); |
646 |
Arrays.fill(passwordChars, ' '); |
661 |
if (passwordChars != null) { |
647 |
return password; |
662 |
String password = String.valueOf(passwordChars); |
648 |
} |
663 |
Arrays.fill(passwordChars, ' '); |
649 |
return null; |
664 |
return password; |
|
|
665 |
} |
666 |
return null; |
667 |
} |
668 |
}; |
669 |
return readPassword(call); |
670 |
} |
650 |
} |
671 |
|
651 |
|
672 |
static void savePassword(@NonNull final String url, @NullAllowed final String password, |
652 |
static void savePassword(@NonNull final String url, @NullAllowed final String password, |
673 |
@NullAllowed final String displayName) { |
653 |
@NullAllowed final String displayName) { |
674 |
|
654 |
|
675 |
Runnable run = new Runnable() { |
655 |
if (password == null) { |
676 |
@Override |
656 |
return; |
677 |
public void run() { |
657 |
} |
678 |
if (password == null) { |
658 |
Keyring.save(getPasswordKey(url), password.toCharArray(), displayName); |
679 |
return; |
|
|
680 |
} |
681 |
Keyring.save(getPasswordKey(url), password.toCharArray(), displayName); |
682 |
} |
683 |
}; |
684 |
KEYRING_ACCESS.post(run); |
685 |
} |
659 |
} |
686 |
|
660 |
|
687 |
static void savePassword(@NonNull final FileObject fo, @NullAllowed final String password, |
661 |
static void savePassword(@NonNull final FileObject fo, @NullAllowed final String password, |
688 |
@NullAllowed final String displayName) { |
662 |
@NullAllowed final String displayName) { |
689 |
|
663 |
|
690 |
Runnable run = new Runnable() { |
664 |
if (password == null) { |
691 |
|
665 |
return; |
692 |
@Override |
666 |
} |
693 |
public void run() { |
667 |
String url = (String) fo.getAttribute(InstanceProperties.URL_ATTR); |
694 |
if (password == null) { |
668 |
if (url == null) { |
695 |
return; |
669 |
return; |
696 |
} |
670 |
} |
697 |
String url = (String) fo.getAttribute(InstanceProperties.URL_ATTR); |
671 |
Keyring.save(getPasswordKey(url), password.toCharArray(), displayName); |
698 |
if (url == null) { |
|
|
699 |
return; |
700 |
} |
701 |
Keyring.save(getPasswordKey(url), password.toCharArray(), displayName); |
702 |
try { |
703 |
fo.setAttribute(InstanceProperties.PASSWORD_ATTR, null); |
704 |
} catch (IOException ex) { |
705 |
LOGGER.log(Level.INFO, null, ex); |
706 |
} |
707 |
} |
708 |
}; |
709 |
KEYRING_ACCESS.post(run); |
710 |
} |
711 |
|
712 |
private static String readPassword(Callable<String> readTask) { |
713 |
try { |
672 |
try { |
714 |
final Future<String> result = KEYRING_ACCESS.submit(readTask); |
673 |
fo.setAttribute(InstanceProperties.PASSWORD_ATTR, null); |
715 |
if (SwingUtilities.isEventDispatchThread()) { |
674 |
} catch (IOException ex) { |
716 |
if (!result.isDone()) { |
|
|
717 |
try { |
718 |
// lets wait in awt to avoid flashing dialogs |
719 |
result.get(50, TimeUnit.MILLISECONDS); |
720 |
} catch (TimeoutException ex) { |
721 |
ProgressUtils.showProgressDialogAndRun(new Runnable() { |
722 |
|
723 |
@Override |
724 |
public void run() { |
725 |
try { |
726 |
result.get(); |
727 |
} catch (InterruptedException ex) { |
728 |
Thread.currentThread().interrupt(); |
729 |
} catch (ExecutionException ex) { |
730 |
LOGGER.log(Level.INFO, null, ex); |
731 |
} |
732 |
} |
733 |
}, NbBundle.getMessage(ServerRegistry.class, "MSG_KeyringAccess")); |
734 |
} |
735 |
} |
736 |
} |
737 |
return result.get(); |
738 |
} catch (InterruptedException ex) { |
739 |
Thread.currentThread().interrupt(); |
740 |
} catch (ExecutionException ex) { |
741 |
LOGGER.log(Level.INFO, null, ex); |
675 |
LOGGER.log(Level.INFO, null, ex); |
742 |
} |
676 |
} |
743 |
return null; |
677 |
} |
744 |
} |
|
|
745 |
|
678 |
|
746 |
private static String getPasswordKey(String url) { |
679 |
private static String getPasswordKey(String url) { |
747 |
StringBuilder builder = new StringBuilder("j2eeserver:"); |
680 |
StringBuilder builder = new StringBuilder("j2eeserver:"); |