1 11 package org.eclipse.update.internal.ui.security; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.jface.dialogs.*; 17 import org.eclipse.swt.widgets.*; 18 import org.eclipse.update.core.*; 19 import org.eclipse.update.internal.core.*; 20 import org.eclipse.update.internal.ui.*; 21 24 public class JarVerificationService implements IVerificationListener { 25 26 30 31 private Shell shell; 32 private int lastVerifyCode = -1; 34 35 39 private Map processed=new HashMap (); 40 41 44 public JarVerificationService() { 45 this(null); 46 } 47 48 51 public JarVerificationService(Shell aShell) { 52 shell = aShell; 53 54 if (shell == null) { 56 final Display disp = Display.getDefault(); 57 if (disp == null) { 58 shell = new Shell(new Display()); 59 } else { 60 disp.syncExec(new Runnable () { 61 public void run() { 62 shell = disp.getActiveShell(); 63 } 64 }); 65 } 66 } 67 } 68 69 72 private int openWizard(IVerificationResult result) { 73 int code; 74 IDialogPage page = new JarVerificationPage(result); 75 JarVerificationDialog dialog = 76 new JarVerificationDialog(shell,page,result); 77 dialog.create(); 78 dialog.getShell().setSize(600, 500); 79 dialog.getShell().setText(UpdateUIMessages.JarVerificationDialog_wtitle); 80 dialog.open(); 81 if (dialog.getReturnCode() == JarVerificationDialog.OK) { 82 code = CHOICE_INSTALL_TRUST_ONCE; 83 } else if (dialog.getReturnCode() == JarVerificationDialog.INSTALL_ALL) { 84 code = CHOICE_INSTALL_TRUST_ALWAYS; 85 } else { 86 code = CHOICE_ABORT; 87 } 88 return code; 89 90 } 91 92 95 public int prompt(final IVerificationResult verificationResult){ 96 if (!UpdateCore.getPlugin().getPluginPreferences().getBoolean(UpdateCore.P_CHECK_SIGNATURE)) 97 return CHOICE_INSTALL_TRUST_ALWAYS; 98 99 if (verificationResult.alreadySeen()) return CHOICE_INSTALL_TRUST_ALWAYS; 100 101 if(see(verificationResult)) return CHOICE_INSTALL_TRUST_ALWAYS; 102 103 if (lastVerifyCode == CHOICE_INSTALL_TRUST_ALWAYS) return CHOICE_INSTALL_TRUST_ALWAYS; 104 105 switch (verificationResult.getVerificationCode()) { 106 case IVerificationResult.UNKNOWN_ERROR : 107 return CHOICE_ERROR; 108 109 case IVerificationResult.VERIFICATION_CANCELLED: 110 return CHOICE_ABORT; 111 112 case IVerificationResult.TYPE_ENTRY_UNRECOGNIZED: 114 return CHOICE_INSTALL_TRUST_ALWAYS; 115 116 default : 117 { 118 shell.getDisplay().syncExec(new Runnable () { 119 public void run() { 120 lastVerifyCode = openWizard(verificationResult); 121 } 122 }); 123 return lastVerifyCode; 124 } 125 } 126 } 127 128 134 private boolean see(final IVerificationResult verificationResult) { 135 String key = verificationResult.getFeature().getVersionedIdentifier().toString() 136 +"/"+verificationResult.getContentReference().getIdentifier(); Long value = new Long (verificationResult.getContentReference().getLastModified()); 138 Long cachedValue = (Long )processed.get(key); 139 if(value.equals(cachedValue)){ 140 return true; 141 }else{ 142 processed.put(key, value); 143 return false; 144 } 145 } 146 } 147 | Popular Tags |