@@ -74,12 +74,12 @@ public void authenticate(AuthenticationFlowContext context) {
74
74
TrackRequest request = new TrackRequest ();
75
75
request .action = actionCode (context );
76
76
77
- request .userId = context .getUser ().getId ();
78
77
request .attributes = new TrackAttributes ();
79
78
request .attributes .redirectUrl = redirectUrl ;
80
79
request .attributes .ipAddress = context .getConnection ().getRemoteAddr ();
81
80
request .attributes .userAgent =
82
81
context .getHttpRequest ().getHttpHeaders ().getHeaderString ("User-Agent" );
82
+ request .userId = context .getUser ().getId ();
83
83
84
84
try {
85
85
CompletableFuture <TrackResponse > responseFuture = authsignalClient .track (request );
@@ -150,21 +150,41 @@ public void close() {
150
150
// Cleanup if needed
151
151
}
152
152
153
+ private String generateConfigErrorMessage (String prefix ) {
154
+ return prefix + " Add provider details in your Keycloak admin portal." ;
155
+ }
156
+
153
157
private String secretKey (AuthenticationFlowContext context ) {
154
158
AuthenticatorConfigModel config = context .getAuthenticatorConfig ();
155
159
if (config == null ) {
156
- return "" ;
160
+ throw new IllegalStateException (
161
+ generateConfigErrorMessage ("Authsignal provider config is missing." ));
157
162
}
158
- return String .valueOf (config .getConfig ().get (AuthsignalAuthenticatorFactory .PROP_SECRET_KEY ));
163
+ Object secretKeyObj = config .getConfig ().get (AuthsignalAuthenticatorFactory .PROP_SECRET_KEY );
164
+ String tenantSecretKey = (secretKeyObj != null ) ? secretKeyObj .toString () : null ;
165
+
166
+ if (tenantSecretKey == null || tenantSecretKey .isEmpty ()) {
167
+ throw new IllegalStateException (
168
+ generateConfigErrorMessage ("Authsignal Tenant Secret Key is not configured." ));
169
+ }
170
+ return tenantSecretKey ;
159
171
}
160
172
161
173
private String baseUrl (AuthenticationFlowContext context ) {
162
174
AuthenticatorConfigModel config = context .getAuthenticatorConfig ();
163
175
if (config == null ) {
164
- return "" ;
176
+ throw new IllegalStateException (
177
+ generateConfigErrorMessage ("Authsignal provider config is missing." ));
178
+ }
179
+ Object apiUrlObj =
180
+ config .getConfig ().get (AuthsignalAuthenticatorFactory .PROP_API_HOST_BASE_URL );
181
+ String apiUrl = (apiUrlObj != null ) ? apiUrlObj .toString () : null ;
182
+
183
+ if (apiUrl == null || apiUrl .isEmpty ()) {
184
+ throw new IllegalStateException (
185
+ generateConfigErrorMessage ("Authsignal API URL is not configured." ));
165
186
}
166
- return String
167
- .valueOf (config .getConfig ().get (AuthsignalAuthenticatorFactory .PROP_API_HOST_BASE_URL ));
187
+ return apiUrl ;
168
188
}
169
189
170
190
private String actionCode (AuthenticationFlowContext context ) {
0 commit comments