Skip to content

Commit

Permalink
Merge pull request #3962 from Coduz/fix-consoleGWTstatics
Browse files Browse the repository at this point in the history
Reverted `static` removal changes in Console GWT
  • Loading branch information
Coduz authored Feb 8, 2024
2 parents f913868 + 4ca84f6 commit 0828ec9
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

public class ChangePasswordDialog extends SimpleDialog {

private final GwtCredentialServiceAsync credentialService = GWT.create(GwtCredentialService.class);
private final ConsoleMessages consoleMessages = GWT.create(ConsoleMessages.class);
private static final ConsoleMessages CONSOLE_MESSAGES = GWT.create(ConsoleMessages.class);
private static final GwtCredentialServiceAsync GWT_CREDENTIAL_SERVICE = GWT.create(GwtCredentialService.class);

private TextField<String> oldPassword;
private TextField<String> newPassword;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void createBody() {
credentialFormPanel.add(confirmPassword);

passwordTooltip = new LabelField();
credentialService.getMinPasswordLength(currentSession.getAccountId(), new AsyncCallback<Integer>() {
GWT_CREDENTIAL_SERVICE.getMinPasswordLength(currentSession.getAccountId(), new AsyncCallback<Integer>() {

@Override
public void onFailure(Throwable caught) {
Expand Down Expand Up @@ -117,7 +117,7 @@ protected void addListeners() {

@Override
public void submit() {
credentialService.changePassword(xsrfToken, oldPassword.getValue(), newPassword.getValue(), code.getValue(), currentSession.getUserId(), currentSession.getAccountId(), new AsyncCallback<Void>() {
GWT_CREDENTIAL_SERVICE.changePassword(xsrfToken, oldPassword.getValue(), newPassword.getValue(), code.getValue(), currentSession.getUserId(), currentSession.getAccountId(), new AsyncCallback<Void>() {

@Override
public void onFailure(Throwable caught) {
Expand All @@ -130,17 +130,17 @@ public void onFailure(Throwable caught) {
GwtKapuaException gwtCaught = (GwtKapuaException) caught;
if (gwtCaught.getCode().equals(GwtKapuaErrorCode.INVALID_USERNAME_PASSWORD)) {
if (credentialFormPanel.findComponent(code) != null) {
ConsoleInfo.display(consoleMessages.error(), ActionDialog.MSGS.changePasswordError(MSGS.changePasswordErrorWrongOldPasswordOrMfaCode()));
ConsoleInfo.display(CONSOLE_MESSAGES.error(), ActionDialog.MSGS.changePasswordError(MSGS.changePasswordErrorWrongOldPasswordOrMfaCode()));
} else {
ConsoleInfo.display(consoleMessages.error(), ActionDialog.MSGS.changePasswordError(MSGS.changePasswordErrorWrongOldPassword()));
ConsoleInfo.display(CONSOLE_MESSAGES.error(), ActionDialog.MSGS.changePasswordError(MSGS.changePasswordErrorWrongOldPassword()));
oldPassword.markInvalid(MSGS.changePasswordErrorWrongOldPassword());
}
} else if (gwtCaught.getCode().equals(GwtKapuaErrorCode.UNAUTHENTICATED)) {
ConsoleInfo.display(consoleMessages.error(), ActionDialog.MSGS.changePasswordError(caught.getLocalizedMessage()));
ConsoleInfo.display(CONSOLE_MESSAGES.error(), ActionDialog.MSGS.changePasswordError(caught.getLocalizedMessage()));
hide();
TokenCleaner.cleanToken();
} else {
ConsoleInfo.display(consoleMessages.error(), ActionDialog.MSGS.changePasswordError(caught.getLocalizedMessage()));
ConsoleInfo.display(CONSOLE_MESSAGES.error(), ActionDialog.MSGS.changePasswordError(caught.getLocalizedMessage()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public class KapuaCloudConsole implements EntryPoint {

private static final Logger LOG = Logger.getLogger(KapuaCloudConsole.class.getName());

private final ConsoleMessages msgs = GWT.create(ConsoleMessages.class);
private final ConsoleCoreMessages coreMessages = GWT.create(ConsoleCoreMessages.class);
private static final ConsoleMessages CONSOLE_MESSAGES = GWT.create(ConsoleMessages.class);
private static final ConsoleCoreMessages CONSOLE_CORE_MESSAGES = GWT.create(ConsoleCoreMessages.class);

private final GwtAuthorizationServiceAsync gwtAuthorizationServiceAsync = GWT.create(GwtAuthorizationService.class);
private final GwtSettingsServiceAsync gwtSettingsServiceAsync = GWT.create(GwtSettingsService.class);
private static final GwtAuthorizationServiceAsync GWT_AUTHORIZATION_SERVICE = GWT.create(GwtAuthorizationService.class);
private static final GwtSettingsServiceAsync GWT_SETTINGS_SERVICE = GWT.create(GwtSettingsService.class);

// OpenID Connect single sign-on parameters
public static final String OPENID_ACCESS_TOKEN_PARAM = "access_token";
Expand Down Expand Up @@ -133,7 +133,7 @@ public void execute() {
* @since 1.0.0
*/
public void onModuleLoad2() {
gwtSettingsServiceAsync.getProductInformation(new AsyncCallback<GwtProductInformation>() {
GWT_SETTINGS_SERVICE.getProductInformation(new AsyncCallback<GwtProductInformation>() {

@Override
public void onFailure(Throwable caught) {
Expand All @@ -144,7 +144,7 @@ public void onFailure(Throwable caught) {
public void onSuccess(GwtProductInformation result) {
productInformation = result;
// Check if a session has already been established on the server-side
gwtAuthorizationServiceAsync.getCurrentSession(new AsyncCallback<GwtSession>() {
GWT_AUTHORIZATION_SERVICE.getCurrentSession(new AsyncCallback<GwtSession>() {

@Override
public void onFailure(Throwable t) {
Expand Down Expand Up @@ -360,7 +360,7 @@ private void renderLoginDialog() {
// Check if coming from failed OpenID Connect login (the user exists but she does not have the authorizations)
if (error != null && error.equals("access_denied")) {
LOG.info("Access denied, OpenID Connect login failed");
ConsoleInfo.display(coreMessages.loginSsoLoginError(), coreMessages.ssoClientAuthenticationFailed());
ConsoleInfo.display(CONSOLE_CORE_MESSAGES.loginSsoLoginError(), CONSOLE_CORE_MESSAGES.ssoClientAuthenticationFailed());
}
showLoginDialog(viewport);
}
Expand All @@ -380,7 +380,7 @@ public void handleEvent(ComponentEvent be) {
}
});

loginDialog.setHeading(coreMessages.loginTitle(productInformation.getProductName()));
loginDialog.setHeading(CONSOLE_CORE_MESSAGES.loginTitle(productInformation.getProductName()));

if (!UserAgentUtils.isIE()) {
Window.addResizeHandler(new ResizeHandler() {
Expand All @@ -399,14 +399,14 @@ private void performOpenIDLogin(final Viewport viewport, String accessToken, Str

// show wait dialog
final Dialog ssoLoginWaitDialog = new Dialog();
ssoLoginWaitDialog.setHeading(msgs.ssoWaitDialog_title());
ssoLoginWaitDialog.setHeading(CONSOLE_MESSAGES.ssoWaitDialog_title());
ssoLoginWaitDialog.setButtons("");
ssoLoginWaitDialog.setClosable(false);
ssoLoginWaitDialog.setResizable(false);
ssoLoginWaitDialog.setModal(true);
ssoLoginWaitDialog.setOnEsc(false);

Label label = new Label(msgs.ssoWaitDialog_text());
Label label = new Label(CONSOLE_MESSAGES.ssoWaitDialog_text());
ssoLoginWaitDialog.add(label);

ssoLoginWaitDialog.show();
Expand All @@ -415,19 +415,19 @@ private void performOpenIDLogin(final Viewport viewport, String accessToken, Str
// start login process
final GwtJwtIdToken gwtIdToken = new GwtJwtIdToken(idToken);
final GwtJwtCredential credentials = new GwtJwtCredential(accessToken);
gwtAuthorizationServiceAsync.login(credentials, gwtIdToken, new AsyncCallback<GwtSession>() {
GWT_AUTHORIZATION_SERVICE.login(credentials, gwtIdToken, new AsyncCallback<GwtSession>() {

@Override
public void onFailure(Throwable caught) {
ssoLoginWaitDialog.hide();

LOG.info("OpenID Connect login failed.");
ConsoleInfo.display(coreMessages.loginSsoLoginError(), caught.getLocalizedMessage());
ConsoleInfo.display(CONSOLE_CORE_MESSAGES.loginSsoLoginError(), caught.getLocalizedMessage());

// Invalidating the OpenID IdToken. We must use the OpenID logout here, since we don't have the KapuSession set yet, so we don't have the
// openIDidToken set inside. This means we cannot realy on the OpenIDLogoutListener to invalidate the OpenID session, instead we must do that
// as a 'real' user initiated logout.
gwtSettingsServiceAsync.getOpenIDLogoutUri(gwtIdToken.getIdToken(), new AsyncCallback<String>() {
GWT_SETTINGS_SERVICE.getOpenIDLogoutUri(gwtIdToken.getIdToken(), new AsyncCallback<String>() {

@Override
public void onFailure(Throwable caught) {
Expand Down Expand Up @@ -523,7 +523,7 @@ private void renderMainScreen(Viewport viewport, GwtSession session) {

// or else

ConsoleInfo.display(msgs.error(), coreMessages.loginError());
ConsoleInfo.display(CONSOLE_MESSAGES.error(), CONSOLE_CORE_MESSAGES.loginError());
showLoginDialog(viewport);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class KapuaViewport extends Viewport {

protected final ConsoleMessages consoleMessages = GWT.create(ConsoleMessages.class);
protected static final ConsoleMessages CONSOLE_MESSAGES = GWT.create(ConsoleMessages.class);

/**
* Minimum width of browser window.
Expand All @@ -42,7 +42,7 @@ public KapuaViewport() {
super();

setMonitorWindowResize(true);
infoPopup = new InfoPopup(consoleMessages.browserWindowTooSmall());
infoPopup = new InfoPopup(CONSOLE_MESSAGES.browserWindowTooSmall());
infoPopup.setGlassStyleName("kapua-PopupPanelGlass");
int clientHeight = Window.getClientHeight();
int clientWidth = Window.getClientWidth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
*/
public class LoginDialog extends Dialog {

private final ConsoleMessages consoleMessages = GWT.create(ConsoleMessages.class);
private final ConsoleCoreMessages consoleCoreMessages = GWT.create(ConsoleCoreMessages.class);
private static final ConsoleMessages CONSOLE_MESSAGES = GWT.create(ConsoleMessages.class);
private static final ConsoleCoreMessages CONSOLE_CORE_MESSAGES = GWT.create(ConsoleCoreMessages.class);

private final GwtAuthorizationServiceAsync gwtAuthorizationService = GWT.create(GwtAuthorizationService.class);
private final GwtSettingsServiceAsync gwtSettingService = GWT.create(GwtSettingsService.class);
private static final GwtAuthorizationServiceAsync GWT_AUTHORIZATION_SERVICE = GWT.create(GwtAuthorizationService.class);
private static final GwtSettingsServiceAsync GWT_SETTINGS_SERVICE = GWT.create(GwtSettingsService.class);

private GwtSession currentSession;
private TextField<String> username;
Expand Down Expand Up @@ -114,7 +114,7 @@ public void handleEvent(BaseEvent be) {
};

username = new TextField<String>();
username.setFieldLabel(consoleCoreMessages.loginUsername());
username.setFieldLabel(CONSOLE_CORE_MESSAGES.loginUsername());
username.addKeyListener(keyListener);
username.setAllowBlank(false);
username.addListener(Events.OnBlur, changeListener);
Expand All @@ -123,18 +123,18 @@ public void handleEvent(BaseEvent be) {

password = new TextField<String>();
password.setPassword(true);
password.setFieldLabel(consoleCoreMessages.loginPassword());
password.setFieldLabel(CONSOLE_CORE_MESSAGES.loginPassword());
password.addKeyListener(keyListener);
password.setAllowBlank(false);
password.addListener(Events.OnBlur, changeListener);

add(password);

gwtSettingService.getOpenIDEnabled(new AsyncCallback<Boolean>() {
GWT_SETTINGS_SERVICE.getOpenIDEnabled(new AsyncCallback<Boolean>() {

@Override
public void onFailure(Throwable caught) {
ConsoleInfo.display(consoleCoreMessages.loginSsoEnabledError(), caught.getLocalizedMessage());
ConsoleInfo.display(CONSOLE_CORE_MESSAGES.loginSsoEnabledError(), caught.getLocalizedMessage());
}

@Override
Expand Down Expand Up @@ -190,14 +190,14 @@ protected void createButtons() {
super.createButtons();

status = new Status();
status.setBusy(consoleMessages.waitMsg());
status.setBusy(CONSOLE_MESSAGES.waitMsg());
status.hide();
status.setAutoWidth(true);

getButtonBar().add(status);
getButtonBar().add(new FillToolItem());

reset = new Button(consoleCoreMessages.loginReset());
reset = new Button(CONSOLE_CORE_MESSAGES.loginReset());
reset.disable();

reset.addSelectionListener(new SelectionListener<ButtonEvent>() {
Expand All @@ -213,7 +213,7 @@ public void componentSelected(ButtonEvent ce) {
}
});

login = new Button(consoleCoreMessages.loginLogin());
login = new Button(CONSOLE_CORE_MESSAGES.loginLogin());
login.addSelectionListener(new SelectionListener<ButtonEvent>() {

@Override
Expand All @@ -222,7 +222,7 @@ public void componentSelected(ButtonEvent ce) {
}
});

ssoLogin = new Button(consoleCoreMessages.loginSsoLogin());
ssoLogin = new Button(CONSOLE_CORE_MESSAGES.loginSsoLogin());
ssoLogin.addSelectionListener(new SelectionListener<ButtonEvent>() {

@Override
Expand All @@ -239,11 +239,11 @@ public void componentSelected(ButtonEvent ce) {
}

protected void doSsoLogin() {
gwtSettingService.getOpenIDLoginUri(new AsyncCallback<String>() {
GWT_SETTINGS_SERVICE.getOpenIDLoginUri(new AsyncCallback<String>() {

@Override
public void onFailure(Throwable caught) {
ConsoleInfo.display(consoleCoreMessages.loginSsoLoginError(), caught.getLocalizedMessage());
ConsoleInfo.display(CONSOLE_CORE_MESSAGES.loginSsoLoginError(), caught.getLocalizedMessage());
}

@Override
Expand All @@ -265,12 +265,12 @@ protected void onRender(Element parent, int pos) {
*/
protected void onSubmit() {
if (username.getValue() == null && password.getValue() == null) {
ConsoleInfo.display(consoleMessages.dialogError(), consoleMessages.usernameAndPasswordRequired());
ConsoleInfo.display(CONSOLE_MESSAGES.dialogError(), CONSOLE_MESSAGES.usernameAndPasswordRequired());
password.markInvalid(password.getErrorMessage());
} else if (username.getValue() == null) {
ConsoleInfo.display(consoleMessages.dialogError(), consoleMessages.usernameFieldRequired());
ConsoleInfo.display(CONSOLE_MESSAGES.dialogError(), CONSOLE_MESSAGES.usernameFieldRequired());
} else if (password.getValue() == null) {
ConsoleInfo.display(consoleMessages.dialogError(), consoleMessages.passwordFieldRequired());
ConsoleInfo.display(CONSOLE_MESSAGES.dialogError(), CONSOLE_MESSAGES.passwordFieldRequired());
password.markInvalid(password.getErrorMessage());
} else {

Expand Down Expand Up @@ -299,7 +299,7 @@ public void performLogin(String trustKey) {
GwtLoginCredential credentials = new GwtLoginCredential(username.getValue(), password.getValue());
credentials.setTrustKey(trustKey);

gwtAuthorizationService.login(credentials, false, new AsyncCallback<GwtSession>() {
GWT_AUTHORIZATION_SERVICE.login(credentials, false, new AsyncCallback<GwtSession>() {

@Override
public void onFailure(Throwable caught) {
Expand All @@ -309,7 +309,7 @@ public void onFailure(Throwable caught) {
mfaLoginDialog.show();
return;
} else {
ConsoleInfo.display(consoleCoreMessages.loginError(), caught.getLocalizedMessage());
ConsoleInfo.display(CONSOLE_CORE_MESSAGES.loginError(), caught.getLocalizedMessage());
}
CookieUtils.removeCookie(CookieUtils.KAPUA_COOKIE_TRUST + username.getValue());
} else {
Expand All @@ -328,7 +328,7 @@ public void onSuccess(GwtSession gwtSession) {
}

public void performLogout() {
gwtAuthorizationService.logout(new AsyncCallback<Void>() {
GWT_AUTHORIZATION_SERVICE.logout(new AsyncCallback<Void>() {

@Override
public void onFailure(Throwable caught) {
Expand All @@ -337,7 +337,7 @@ public void onFailure(Throwable caught) {

@Override
public void onSuccess(Void arg0) {
ConsoleInfo.display(consoleMessages.popupInfo(), consoleMessages.loggedOut());
ConsoleInfo.display(CONSOLE_MESSAGES.popupInfo(), CONSOLE_MESSAGES.loggedOut());
resetDialog();
show();
}
Expand Down
Loading

0 comments on commit 0828ec9

Please sign in to comment.