Skip to content

Commit 0ce381e

Browse files
authored
Merge pull request #35216 from appsmithorg/cherry-pick/26-jul
Cherry pick/26 jul
2 parents f4073fc + 9f4d559 commit 0ce381e

File tree

5 files changed

+80
-19
lines changed

5 files changed

+80
-19
lines changed

app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/ce/CustomOAuth2UserServiceCEImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import com.appsmith.server.domains.LoginSource;
44
import com.appsmith.server.domains.User;
55
import com.appsmith.server.domains.UserState;
6+
import com.appsmith.server.exceptions.AppsmithException;
7+
import com.appsmith.server.exceptions.AppsmithOAuth2AuthenticationException;
68
import com.appsmith.server.repositories.UserRepository;
79
import com.appsmith.server.services.UserService;
810
import lombok.extern.slf4j.Slf4j;
911
import org.springframework.beans.factory.annotation.Autowired;
1012
import org.springframework.security.oauth2.client.userinfo.DefaultReactiveOAuth2UserService;
1113
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
1214
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
15+
import org.springframework.security.oauth2.core.OAuth2Error;
1316
import org.springframework.security.oauth2.core.user.OAuth2User;
1417
import reactor.core.publisher.Mono;
1518

@@ -65,6 +68,12 @@ private Mono<User> checkAndCreateUser(OAuth2User oAuth2User, OAuth2UserRequest u
6568
return repository.save(user);
6669
}
6770
return Mono.just(user);
68-
});
71+
})
72+
.onErrorMap(
73+
AppsmithException.class,
74+
// Throwing an AppsmithOAuth2AuthenticationException in case of an AppsmithException
75+
// This is to differentiate between Appsmith exceptions and OAuth2 exceptions
76+
error -> new AppsmithOAuth2AuthenticationException(
77+
new OAuth2Error(error.getAppErrorCode().toString(), error.getMessage(), "")));
6978
}
7079
}

app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/ce/CustomOidcUserServiceCEImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.appsmith.server.domains.User;
55
import com.appsmith.server.domains.UserState;
66
import com.appsmith.server.exceptions.AppsmithException;
7+
import com.appsmith.server.exceptions.AppsmithOAuth2AuthenticationException;
78
import com.appsmith.server.repositories.UserRepository;
89
import com.appsmith.server.services.UserService;
910
import lombok.extern.slf4j.Slf4j;
@@ -76,7 +77,9 @@ public Mono<User> checkAndCreateUser(OidcUser oidcUser, OidcUserRequest userRequ
7677
})
7778
.onErrorMap(
7879
AppsmithException.class,
79-
error -> new OAuth2AuthenticationException(
80+
// Throwing an AppsmithOAuth2AuthenticationException in case of an AppsmithException
81+
// This is to differentiate between Appsmith exceptions and OAuth2 exceptions
82+
error -> new AppsmithOAuth2AuthenticationException(
8083
new OAuth2Error(error.getAppErrorCode().toString(), error.getMessage(), "")));
8184
}
8285
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.appsmith.server.exceptions;
2+
3+
import lombok.Getter;
4+
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
5+
import org.springframework.security.oauth2.core.OAuth2Error;
6+
7+
@Getter
8+
public class AppsmithOAuth2AuthenticationException extends OAuth2AuthenticationException {
9+
10+
private final OAuth2Error error;
11+
/**
12+
* Constructs an {@code AppsmithOAuth2AuthenticationException} using the provided parameters.
13+
* @param error the {@link OAuth2Error OAuth 2.0 Error}
14+
*/
15+
public AppsmithOAuth2AuthenticationException(OAuth2Error error) {
16+
this(error, error.getDescription(), null);
17+
}
18+
19+
/**
20+
* Constructs an {@code AppsmithOAuth2AuthenticationException} using the provided parameters.
21+
* @param error the {@link OAuth2Error OAuth 2.0 Error}
22+
* @param message the detail message
23+
* @param cause the root cause
24+
*/
25+
public AppsmithOAuth2AuthenticationException(OAuth2Error error, String message, Throwable cause) {
26+
super(error, message, cause);
27+
this.error = error;
28+
}
29+
}

deploy/docker/fs/opt/appsmith/entrypoint.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,19 @@ init_postgres() {
437437

438438
}
439439

440-
safe_init_postgres(){
441-
runEmbeddedPostgres=1
442-
# fail safe to prevent entrypoint from exiting, and prevent postgres from starting
443-
init_postgres || runEmbeddedPostgres=0
440+
safe_init_postgres() {
441+
runEmbeddedPostgres=1
442+
# fail safe to prevent entrypoint from exiting, and prevent postgres from starting
443+
# when runEmbeddedPostgres=0 , postgres conf file for supervisord will not be copied
444+
# so postgres will not be started by supervisor. Explicit message helps us to know upgrade script failed.
445+
446+
if init_postgres; then
447+
tlog "init_postgres succeeded."
448+
else
449+
local exit_status=$?
450+
tlog "init_postgres failed with exit status $exit_status."
451+
runEmbeddedPostgres=0
452+
fi
444453
}
445454

446455
setup_caddy() {

deploy/docker/fs/opt/appsmith/pg-upgrade.sh

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ if [[ -z "$old_version" ]]; then
3737
exit
3838
fi
3939

40-
if [[ -f "$pg_data_dir/postmaster.pid" ]]; then
41-
tlog "Previous Postgres was not shutdown cleanly. Please start and stop Postgres $old_version properly with 'supervisorctl' only." >&2
42-
exit 1
43-
fi
44-
4540
top_available_version="$(postgres --version | grep -o '[[:digit:]]\+' | head -1)"
4641

4742
declare -a to_uninstall
@@ -55,14 +50,30 @@ if [[ "$old_version" == 13 && "$top_available_version" > "$old_version" ]]; then
5550
to_uninstall+=("postgresql-$old_version")
5651
fi
5752

58-
new_version="$((old_version + 1))"
59-
new_data_dir="$pg_data_dir-$new_version"
53+
if [[ -f "$pg_data_dir/postmaster.pid" ]]; then
54+
# Start old PostgreSQL using pg_ctl
55+
tlog "Stale postmaster.pid found. Starting old PostgreSQL $old_version using pg_ctl to cleanup."
56+
su postgres -c "$postgres_path/$old_version/bin/pg_ctl start -D '$pg_data_dir' "
57+
58+
# Wait for old PostgreSQL to be ready
59+
until su postgres -c "$postgres_path/$old_version/bin/pg_isready"; do
60+
tlog "Waiting for PostgreSQL $old_version to start..."
61+
sleep 1
62+
done
63+
64+
# Shut down PostgreSQL gracefully using pg_ctl
65+
su postgres -c "$postgres_path/$old_version/bin/pg_ctl stop -D '$pg_data_dir' -m smart"
66+
tlog "PostgreSQL $old_version has been shut down."
67+
fi
68+
69+
new_version="$((old_version + 1))"
70+
new_data_dir="$pg_data_dir-$new_version"
6071

61-
# `pg_upgrade` writes log to current folder. So change to a temp folder first.
62-
rm -rf "$TMP/pg_upgrade" "$new_data_dir"
63-
mkdir -p "$TMP/pg_upgrade" "$new_data_dir"
64-
chown -R postgres "$TMP/pg_upgrade" "$new_data_dir"
65-
cd "$TMP/pg_upgrade"
72+
# `pg_upgrade` writes log to current folder. So change to a temp folder first.
73+
rm -rf "$TMP/pg_upgrade" "$new_data_dir"
74+
mkdir -p "$TMP/pg_upgrade" "$new_data_dir"
75+
chown -R postgres "$TMP/pg_upgrade" "$new_data_dir"
76+
cd "$TMP/pg_upgrade"
6677

6778
# Required by the temporary Postgres server started by `pg_upgrade`.
6879
chown postgres /etc/ssl/private/ssl-cert-snakeoil.key
@@ -88,7 +99,7 @@ if [[ "$old_version" == 13 && "$top_available_version" > "$old_version" ]]; then
8899
fi
89100

90101
if [[ -n "${#to_uninstall[@]}" ]]; then
91-
apt-get purge "${to_uninstall[@]}"
102+
DEBIAN_FRONTEND=noninteractive apt-get purge --yes "${to_uninstall[@]}"
92103
apt-get clean
93104
fi
94105

0 commit comments

Comments
 (0)