|
33 | 33 | import java.util.Locale; |
34 | 34 | import java.util.Map; |
35 | 35 | import java.util.Optional; |
| 36 | +import java.util.regex.Pattern; |
36 | 37 | import javax.swing.BorderFactory; |
37 | 38 | import javax.swing.Icon; |
38 | 39 | import javax.swing.ImageIcon; |
@@ -113,6 +114,7 @@ public class AuthTestDialog extends StandardFieldsDialog { |
113 | 114 | private static final String RECORD_DIAGNOSTICS_LABEL = |
114 | 115 | "authhelper.auth.test.dialog.label.recdiag"; |
115 | 116 | private static final String DIAGNOSTICS_LABEL = "authhelper.auth.test.dialog.label.diag"; |
| 117 | + private static final String DOMAINS_LABEL = "authhelper.auth.test.dialog.label.domains"; |
116 | 118 | private static final String COPY_LABEL = "authhelper.auth.test.dialog.label.copy"; |
117 | 119 |
|
118 | 120 | private static final String FOUND_STR = |
@@ -163,6 +165,7 @@ public AuthTestDialog(ExtensionAuthhelper ext, Frame owner) { |
163 | 165 | DisplayUtils.getScaledDimension(600, 550), |
164 | 166 | new String[] { |
165 | 167 | "authhelper.auth.test.dialog.tab.test", |
| 168 | + "authhelper.auth.test.dialog.tab.domains", |
166 | 169 | "authhelper.auth.test.dialog.tab.steps", |
167 | 170 | "authhelper.auth.test.dialog.tab.diag" |
168 | 171 | }); |
@@ -251,6 +254,10 @@ public AuthTestDialog(ExtensionAuthhelper ext, Frame owner) { |
251 | 254 | this.addPadding(0); |
252 | 255 |
|
253 | 256 | int tab = 1; |
| 257 | + |
| 258 | + addMultilineField(tab, DOMAINS_LABEL, params.getDomains()); |
| 259 | + |
| 260 | + tab++; |
254 | 261 | stepsPanel = new StepsPanel(this, true); |
255 | 262 | stepsPanel.setSteps(params.getSteps()); |
256 | 263 | setCustomTabPanel(tab, stepsPanel.getPanel()); |
@@ -468,6 +475,14 @@ private void authenticate() { |
468 | 475 | context.addIncludeInContextRegex( |
469 | 476 | SessionStructure.getHostName(new URI(loginUrl, false)) + ".*"); |
470 | 477 |
|
| 478 | + for (String dom : getDomains()) { |
| 479 | + if (dom.endsWith(".*")) { |
| 480 | + // Just in case the user has added this anyway |
| 481 | + dom = dom.substring(0, dom.length() - 2); |
| 482 | + } |
| 483 | + context.addIncludeInContextRegex(Pattern.quote(dom) + ".*"); |
| 484 | + } |
| 485 | + |
471 | 486 | JComboBox<?> browserCombo = (JComboBox<?>) this.getField(BROWSER_LABEL); |
472 | 487 | String browserId = ((BrowserUI) browserCombo.getSelectedItem()).getBrowser().getId(); |
473 | 488 |
|
@@ -692,6 +707,12 @@ public void counterInc(String site, String key) { |
692 | 707 | } |
693 | 708 | } |
694 | 709 |
|
| 710 | + private List<String> getDomains() { |
| 711 | + return List.of(this.getStringValue(DOMAINS_LABEL).split("\r?\n")).stream() |
| 712 | + .filter(StringUtils::isNotBlank) |
| 713 | + .toList(); |
| 714 | + } |
| 715 | + |
695 | 716 | private static void setTotp( |
696 | 717 | List<AuthenticationStep> steps, UsernamePasswordAuthenticationCredentials credentials) { |
697 | 718 | if (!TotpSupport.isTotpInCore()) { |
@@ -755,6 +776,7 @@ public JButton[] getExtraButtons() { |
755 | 776 | Constant.messages.getString( |
756 | 777 | "authhelper.auth.test.dialog.default-context")); |
757 | 778 | setFieldValue(LOGIN_URL_LABEL, ""); |
| 779 | + setFieldValue(DOMAINS_LABEL, ""); |
758 | 780 | setFieldValue(USERNAME_LABEL, ""); |
759 | 781 | setFieldValue(PASSWORD_LABEL, ""); |
760 | 782 | setFieldValue(LOGIN_WAIT_LABEL, AuthhelperParam.DEFAULT_WAIT); |
@@ -786,6 +808,7 @@ public void save() { |
786 | 808 | private void saveDetails() { |
787 | 809 | AuthhelperParam params = this.ext.getParam(); |
788 | 810 | params.setLoginUrl(this.getStringValue(LOGIN_URL_LABEL)); |
| 811 | + params.setDomains(this.getStringValue(DOMAINS_LABEL)); |
789 | 812 | params.setUsername(this.getStringValue(USERNAME_LABEL)); |
790 | 813 | JComboBox<?> browserCombo = (JComboBox<?>) this.getField(BROWSER_LABEL); |
791 | 814 | params.setBrowser(((BrowserUI) browserCombo.getSelectedItem()).getBrowser().getId()); |
@@ -815,6 +838,17 @@ public String validateFields() { |
815 | 838 | return Constant.messages.getString("authhelper.auth.test.dialog.error.nopassword"); |
816 | 839 | } |
817 | 840 | } |
| 841 | + for (String dom : this.getDomains()) { |
| 842 | + String domLc = dom.toLowerCase(Locale.ROOT); |
| 843 | + if (!domLc.startsWith("http://") && !domLc.startsWith("https://")) { |
| 844 | + return Constant.messages.getString("authhelper.auth.test.dialog.error.baddom", dom); |
| 845 | + } |
| 846 | + try { |
| 847 | + new URI(dom, false); |
| 848 | + } catch (Exception e) { |
| 849 | + return Constant.messages.getString("authhelper.auth.test.dialog.error.baddom", dom); |
| 850 | + } |
| 851 | + } |
818 | 852 | return null; |
819 | 853 | } |
820 | 854 |
|
|
0 commit comments