CB-1580 Federated auth redesign

This commit is contained in:
Serge Rider
2022-02-04 10:20:26 +03:00
parent 0f4a275943
commit 84dab8a79c
@@ -737,24 +737,35 @@ public class WebSession implements DBASession, DBAAuthCredentialsProvider, IAdap
}
public void addAuthInfo(@NotNull WebAuthInfo authInfo) throws DBException {
WebUser newUser = authInfo.getUser();
addAuthTokens(authInfo);
}
public void addAuthTokens(@NotNull WebAuthInfo ... tokens) throws DBException {
WebUser newUser = null;
for (WebAuthInfo authInfo : tokens) {
if (newUser != null && newUser != authInfo.getUser()) {
throw new DBException("Different users specified in auth tokens: " + Arrays.toString(tokens));
}
newUser = authInfo.getUser();
}
if (this.user == null && newUser != null) {
forceUserRefresh(newUser);
} else if (!CommonUtils.equalObjects(this.user, newUser)) {
throw new DBException("Can't authorize different users in the single session");
}
WebAuthInfo oldAuthInfo = getAuthInfo(authInfo.getAuthProviderDescriptor().getId());
if (oldAuthInfo != null) {
removeAuthInfo(oldAuthInfo);
for (WebAuthInfo authInfo : tokens) {
WebAuthInfo oldAuthInfo = getAuthInfo(authInfo.getAuthProviderDescriptor().getId());
if (oldAuthInfo != null) {
removeAuthInfo(oldAuthInfo);
}
DBASession authSession = authInfo.getAuthSession();
if (authSession != null) {
getSessionContext().addSession(authSession);
}
}
DBASession authSession = authInfo.getAuthSession();
if (authSession != null) {
getSessionContext().addSession(authSession);
}
synchronized (authTokens) {
authTokens.add(authInfo);
Collections.addAll(authTokens, tokens);
}
}