55import ai .reveng .toolkit .ghidra .core .services .api .types .ApiInfo ;
66import ai .reveng .toolkit .ghidra .core .services .api .types .exceptions .InvalidAPIInfoException ;
77import ai .reveng .toolkit .ghidra .core .services .logging .ReaiLoggingService ;
8+ import ai .reveng .toolkit .ghidra .core .ui .wizard .CredentialValidator ;
89import ai .reveng .toolkit .ghidra .core .ui .wizard .SetupWizardStateKey ;
910import docking .wizard .AbstractMageJPanel ;
1011import docking .wizard .IllegalPanelStateException ;
@@ -26,6 +27,7 @@ public class UserCredentialsPanel extends AbstractMageJPanel<SetupWizardStateKey
2627 private JTextField tfApiHostname ;
2728 private JTextField tfPortalHostname ;
2829 private Boolean credentialsValidated = false ;
30+ private CredentialValidator credentialValidator = CredentialValidator .defaultValidator ();
2931
3032 private ReaiLoggingService loggingService ;
3133
@@ -73,6 +75,7 @@ public void changedUpdate(DocumentEvent e) {
7375 gbc .fill = GridBagConstraints .HORIZONTAL ;
7476 gbc .weightx = 1.0 ;
7577 tfApiKey = new JTextField (30 );
78+ tfApiKey .setName ("apiKey" );
7679 tfApiKey .getDocument ().addDocumentListener (documentListener );
7780 tfApiKey .setToolTipText ("API key from your account settings" );
7881 userDetailsPanel .add (tfApiKey , gbc );
@@ -89,6 +92,7 @@ public void changedUpdate(DocumentEvent e) {
8992 gbc .fill = GridBagConstraints .HORIZONTAL ;
9093 gbc .weightx = 1.0 ;
9194 tfApiHostname = new JTextField (30 );
95+ tfApiHostname .setName ("apiHostname" );
9296 tfApiHostname .getDocument ().addDocumentListener (documentListener );
9397 tfApiHostname .setToolTipText ("URL hosting the RevEng.AI Server" );
9498 tfApiHostname .setText ("https://api.reveng.ai" );
@@ -106,6 +110,7 @@ public void changedUpdate(DocumentEvent e) {
106110 gbc .fill = GridBagConstraints .HORIZONTAL ;
107111 gbc .weightx = 1.0 ;
108112 tfPortalHostname = new JTextField (30 );
113+ tfPortalHostname .setName ("portalHostname" );
109114 tfPortalHostname .getDocument ().addDocumentListener (documentListener );
110115 tfPortalHostname .setToolTipText ("URL hosting the RevEng.AI Portal" );
111116 tfPortalHostname .setText ("https://portal.reveng.ai" );
@@ -158,16 +163,13 @@ public void mouseClicked(java.awt.event.MouseEvent e) {
158163 runTestsButton .addActionListener (e -> {
159164 var apiInfo = new ApiInfo (tfApiHostname .getText (), tfPortalHostname .getText (), tfApiKey .getText ());
160165 try {
161- apiInfo . checkCredentials ( );
166+ credentialValidator . validate ( apiInfo );
162167 credentialsValidated = true ;
163- // TODO: Get the user for this key once the API exists
164168 notifyListenersOfValidityChanged ();
165-
166169 } catch (InvalidAPIInfoException ex ) {
167170 credentialsValidated = false ;
168171 notifyListenersOfStatusMessage ("Problem with user info:\n " + ex .getMessage ());
169172 }
170-
171173 });
172174 userDetailsPanel .add (runTestsButton , gbc );
173175 }
@@ -186,6 +188,12 @@ public WizardPanelDisplayability getPanelDisplayabilityAndUpdateState(WizardStat
186188
187189 @ Override
188190 public void enterPanel (WizardState <SetupWizardStateKey > state ) throws IllegalPanelStateException {
191+ // Pick up credential validator from state if provided (e.g. by tests)
192+ CredentialValidator validator = (CredentialValidator ) state .get (SetupWizardStateKey .CREDENTIAL_VALIDATOR );
193+ if (validator != null ) {
194+ this .credentialValidator = validator ;
195+ }
196+
189197 // Populate fields with existing state information if present
190198 String existingApiKey = (String ) state .get (SetupWizardStateKey .API_KEY );
191199 String existingHostname = (String ) state .get (SetupWizardStateKey .HOSTNAME );
@@ -213,11 +221,6 @@ public void enterPanel(WizardState<SetupWizardStateKey> state) throws IllegalPan
213221 }
214222 }
215223
216- private void validateCredentialsFromState () {
217- // This method is no longer used - validation state is preserved from wizard state
218- // Keeping for backwards compatibility but it should not be called
219- loggingService .warn ("validateCredentialsFromState() called - this should not happen with new validation logic" );
220- }
221224
222225 @ Override
223226 public void leavePanel (WizardState <SetupWizardStateKey > state ) {
0 commit comments