@@ -82,9 +82,15 @@ public List<WebAuthInfo> authenticateSession() throws DBException {
8282 @ SuppressWarnings ("unchecked" )
8383 private List <WebAuthInfo > finishWebSessionAuthorization (SMAuthInfo authInfo ) throws DBException {
8484 boolean configMode = WebAppUtils .getWebApplication ().isConfigurationMode ();
85- boolean resetUserStateOnError = webSession .getUser () == null ;
85+ boolean alreadyLoggedIn = webSession .getUser () != null ;
86+ boolean resetUserStateOnError = !alreadyLoggedIn ;
8687
8788 try {
89+ if (configMode && alreadyLoggedIn ) {
90+ for (String providerId : authInfo .getAuthData ().keySet ()) {
91+ webSession .removeAuthInfo (providerId );
92+ }
93+ }
8894 webSession .updateSMAuthInfo (authInfo );
8995 WebUser curUser = webSession .getUser ();
9096 if (curUser == null ) {
@@ -117,18 +123,11 @@ private List<WebAuthInfo> finishWebSessionAuthorization(SMAuthInfo authInfo) thr
117123 }
118124
119125 SMSession authSession ;
120- if (configMode ) {
121- if (webSession .getUser () != null ) {
122- // Already logged in - remove auth token
123- webSession .removeAuthInfo (providerId );
124- webSession .resetAuthToken ();
125- }
126- } else {
127- if (authProviderExternal != null ) {
128- // We may need to associate new credentials with active user
129- if (linkWithActiveUser ) {
130- securityController .setUserCredentials (userId , authProviderDescriptor .getId (), userCredentials );
131- }
126+
127+ if (authProviderExternal != null && !configMode && !alreadyLoggedIn ) {
128+ // We may need to associate new credentials with active user
129+ if (linkWithActiveUser ) {
130+ securityController .setUserCredentials (userId , authProviderDescriptor .getId (), userCredentials );
132131 }
133132 }
134133
0 commit comments