Alexander Wels has uploaded a new change for review.

Change subject: userportal,webadmin: multiple login messages
......................................................................

userportal,webadmin: multiple login messages

- When the backend would return multiple login failure
  messages (for instance with the password expired). All
  messages after the first would be discarded. This would
  lead to configured messages to not be displayed.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1157773

Change-Id: Idd3bc6b716797583d3fc69fc69746bc3362eb58d
Signed-off-by: Alexander Wels <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/aaa/LoginBaseCommand.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractLoginPresenterWidget.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/LoginModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/Model.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.ui.xml
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/login/view/LoginFormView.ui.xml
8 files changed, 90 insertions(+), 62 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/14/38214/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/aaa/LoginBaseCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/aaa/LoginBaseCommand.java
index 8a9af99..eec20a8 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/aaa/LoginBaseCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/aaa/LoginBaseCommand.java
@@ -414,13 +414,15 @@
 
             if (authResult == Authn.AuthResult.CREDENTIALS_EXPIRED) {
                 boolean addedUserPasswordExpiredCDA = false;
-                if (outputMap.<String> 
get(Authn.InvokeKeys.CREDENTIALS_CHANGE_URL) != null) {
+                if (outputMap.<String> 
get(Authn.InvokeKeys.CREDENTIALS_CHANGE_URL) != null
+                        && !outputMap.<String> 
get(Authn.InvokeKeys.CREDENTIALS_CHANGE_URL).trim().isEmpty()) {
                     
addCanDoActionMessage(VdcBllMessages.USER_PASSWORD_EXPIRED_CHANGE_URL_PROVIDED);
                     addCanDoActionMessageVariable("URL",
                             
outputMap.<String>get(Authn.InvokeKeys.CREDENTIALS_CHANGE_URL));
                     addedUserPasswordExpiredCDA = true;
                 }
-                if (outputMap.<String> get(Authn.InvokeKeys.USER_MESSAGE) != 
null) {
+                if (outputMap.<String> get(Authn.InvokeKeys.USER_MESSAGE) != 
null
+                        && !outputMap.<String> 
get(Authn.InvokeKeys.USER_MESSAGE).trim().isEmpty()) {
                     
addCanDoActionMessage(VdcBllMessages.USER_PASSWORD_EXPIRED_CHANGE_MSG_PROVIDED);
                     addCanDoActionMessageVariable("MSG",
                             
outputMap.<String>get(Authn.InvokeKeys.USER_MESSAGE));
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractLoginPresenterWidget.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractLoginPresenterWidget.java
index 646aec0..0cd4753 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractLoginPresenterWidget.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractLoginPresenterWidget.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.ui.common.presenter;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.logging.Logger;
 
 import org.ovirt.engine.ui.common.system.ClientStorage;
@@ -42,9 +44,9 @@
 
         void resetAndFocus();
 
-        void setErrorMessageHtml(SafeHtml text);
+        void setErrorMessages(List<SafeHtml> text);
 
-        void clearErrorMessage();
+        void clearErrorMessages();
 
         HasUiCommandClickHandlers getLoginButton();
 
@@ -100,7 +102,7 @@
             @Override
             public void eventRaised(Event<? extends EventArgs> ev, Object 
sender, EventArgs args) {
                 lockInteractionManager.hideLoadingIndicator();
-                formatAndSetErrorMessage(loginModel.getMessage());
+                formatAndSetErrorMessage(loginModel.getMessages());
                 logger.warning("Login failed for user [" + 
loginModel.getUserName().getEntity() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
             }
 
@@ -167,7 +169,7 @@
     protected abstract String getSelectedDomainKey();
 
     protected void onLoggedInEvent(T loginModel) {
-        getView().clearErrorMessage();
+        getView().clearErrorMessages();
         saveSelectedDomain(loginModel);
     }
 
@@ -180,29 +182,31 @@
         clientStorage.setLocalItem(getSelectedDomainKey(), selectedItem);
     }
 
-    private void formatAndSetErrorMessage(String message) {
-        SafeHtml safeMessage = null;
-        if (message != null) {
-            SafeHtmlBuilder builder = new SafeHtmlBuilder();
-            int urlIndex = message.indexOf("http"); //$NON-NLS-1$
-            if (urlIndex != -1) {
-                String beforeURL = message.substring(0, urlIndex);
-                int afterUrlMessageIndex = message.indexOf(" ", urlIndex); 
//$NON-NLS-1$
-                int endIndex = afterUrlMessageIndex > -1 ? 
afterUrlMessageIndex : message.length();
-                //Sanitize the URL, returns # if it is not safe.
-                String url = UriUtils.sanitizeUri(message.substring(urlIndex, 
endIndex));
-                String motdAnchor = getView().getMotdAnchorHtml(url);
-                
builder.appendEscaped(beforeURL).append(SafeHtmlUtils.fromTrustedString(motdAnchor));
-                if (endIndex < message.length()) {
-                    //There was a string after the URL append it as well.
-                    builder.appendEscaped(message.substring(endIndex));
+    private void formatAndSetErrorMessage(List<String> messages) {
+        List<SafeHtml> safeMessages = new ArrayList<SafeHtml>();
+        if (messages != null) {
+            for (String message: messages) {
+                SafeHtmlBuilder builder = new SafeHtmlBuilder();
+                int urlIndex = message.indexOf("http"); //$NON-NLS-1$
+                if (urlIndex != -1) {
+                    String beforeURL = message.substring(0, urlIndex);
+                    int afterUrlMessageIndex = message.indexOf(" ", urlIndex); 
//$NON-NLS-1$
+                    int endIndex = afterUrlMessageIndex > -1 ? 
afterUrlMessageIndex : message.length();
+                    //Sanitize the URL, returns # if it is not safe.
+                    String url = 
UriUtils.sanitizeUri(message.substring(urlIndex, endIndex));
+                    String motdAnchor = getView().getMotdAnchorHtml(url);
+                    
builder.appendEscaped(beforeURL).append(SafeHtmlUtils.fromTrustedString(motdAnchor));
+                    if (endIndex < message.length()) {
+                        //There was a string after the URL append it as well.
+                        builder.appendEscaped(message.substring(endIndex));
+                    }
+                } else {
+                    builder.appendEscaped(message);
                 }
-            } else {
-                builder.appendEscaped(message);
+                safeMessages.add(builder.toSafeHtml());
             }
-            safeMessage = builder.toSafeHtml();
         }
-        getView().setErrorMessageHtml(safeMessage);
+        getView().setErrorMessages(safeMessages);
     }
 
     @Override
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java
index 8e1c63d..31b5cc6 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.ui.common.view;
 
 import java.util.Arrays;
+import java.util.List;
 
 import org.gwtbootstrap3.client.ui.Label;
 import org.gwtbootstrap3.client.ui.ListBox;
@@ -25,6 +26,7 @@
 import com.google.gwt.event.dom.client.HasKeyPressHandlers;
 import com.google.gwt.event.shared.EventBus;
 import com.google.gwt.i18n.client.LocaleInfo;
+import com.google.gwt.resources.client.CssResource;
 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
 import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.uibinder.client.UiField;
@@ -42,9 +44,16 @@
         SafeHtml anchor(String url, String text);
     }
 
+    public interface Style extends CssResource {
+        String loginMessageError();
+    }
+
     private static final String DEFAULT_LOCALE = "default"; //$NON-NLS-1$
 
     private static MotdAnchorTemplate template;
+
+    @UiField
+    public Style style;
 
     @UiField(provided = true)
     @Ignore
@@ -72,10 +81,6 @@
     @UiField
     @WithElementId
     public PatternflyUiCommandButton loginButton;
-
-    @UiField
-    @Ignore
-    public Label errorMessage;
 
     @UiField
     @Ignore
@@ -175,27 +180,22 @@
         return template;
     }
 
-    protected void setErrorMessageLabel(Label errorMessage, SafeHtml text) {
-        if (text != null) {
-            errorMessage.getElement().setInnerSafeHtml(text);
-        } else {
-            errorMessage.getElement().setInnerHTML(null);
-        }
-    }
-
     public String getMotdAnchorHtml(String url) {
         return getTemplate().anchor(url, url).asString();
     }
 
-    public void clearErrorMessage() {
-        setErrorMessageHtml(null);
+    public void clearErrorMessages() {
+        errorMessagePanel.clear();
         errorMessagePanel.setVisible(false);
     }
 
-    public void setErrorMessageHtml(SafeHtml text) {
-        setErrorMessageLabel(errorMessage, text);
-        errorMessage.setVisible(text != null);
-        if (errorMessage.isVisible()) {
+    public void setErrorMessages(List<SafeHtml> messages) {
+        clearErrorMessages();
+        for (SafeHtml message: messages) {
+            Label messageLabel = new Label();
+            messageLabel.setHTML(message.asString());
+            messageLabel.addStyleName(style.loginMessageError());
+            errorMessagePanel.add(messageLabel);
             errorMessagePanel.setVisible(true);
         }
     }
@@ -203,7 +203,7 @@
     public void resetAndFocus() {
         userNameEditor.asValueBox().selectAll();
         userNameEditor.asValueBox().setFocus(true);
-        clearErrorMessage();
+        clearErrorMessages();
     }
 
     public HasUiCommandClickHandlers getLoginButton() {
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/LoginModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/LoginModel.java
index 071566f..e51a92b 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/LoginModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/LoginModel.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.ui.uicommonweb.models;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -8,7 +9,6 @@
 import org.ovirt.engine.ui.frontend.AsyncQuery;
 import org.ovirt.engine.ui.frontend.Frontend;
 import org.ovirt.engine.ui.frontend.INewAsyncCallback;
-import org.ovirt.engine.ui.uicommonweb.Linq;
 import org.ovirt.engine.ui.uicommonweb.UICommand;
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
 import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
@@ -182,9 +182,9 @@
                 LoginModel loginModel = (LoginModel) model;
                 if (ReturnValue == null)
                 {
-                    loginModel.setMessage(ConstantsManager.getInstance()
+                    
loginModel.setMessages(Arrays.asList(ConstantsManager.getInstance()
                             .getConstants()
-                            .couldNotConnectToOvirtEngineServiceMsg());
+                            .couldNotConnectToOvirtEngineServiceMsg()));
                     return;
                 }
 
@@ -237,7 +237,7 @@
                     if (user == null)
                     {
                         loginModel.getPassword().setEntity(""); //$NON-NLS-1$
-                        
loginModel.setMessage(Linq.firstOrDefault(returnValue.getCanDoActionMessages()));
+                        
loginModel.setMessages(returnValue.getCanDoActionMessages());
                         loginModel.getUserName().setIsChangable(true);
                         loginModel.getPassword().setIsChangable(true);
                         loginModel.getProfile().setIsChangable(true);
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/Model.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/Model.java
index 9edf863..efd2dff 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/Model.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/Model.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.ui.uicommonweb.models;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -451,18 +452,32 @@
         privateOpenDocumentationCommand = value;
     }
 
-    private String message;
+    private List<String> messages;
 
-    public String getMessage()
-    {
-        return message;
+    public List<String> getMessages() {
+        return messages;
     }
 
-    public void setMessage(String value)
+    public String getMessage() {
+        String result = null;
+        if (messages != null && !messages.isEmpty()) {
+            result = messages.get(0);
+        }
+        return result;
+    }
+
+    public void setMessage(String value) {
+        if (!ObjectUtils.objectsEqual(getMessage(), value) || messages.size() 
> 1) {
+            messages.clear();
+            setMessages(Arrays.asList(value));
+        }
+    }
+
+    public void setMessages(List<String> value)
     {
-        if (!ObjectUtils.objectsEqual(message, value))
+        if (!ObjectUtils.objectsEqual(messages, value))
         {
-            message = value;
+            messages = value;
             onPropertyChanged(new PropertyChangedEventArgs("Message")); 
//$NON-NLS-1$
         }
     }
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.java
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.java
index bf8b027..fc1b669 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.java
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.java
@@ -68,6 +68,7 @@
             ApplicationTemplates templates) {
         super(eventBus, resources);
 
+//        style = GWT.create(Style.class);
         connectAutomaticallyEditor = new 
EntityModelCheckBoxEditor(Align.RIGHT);
 
         initWidget(ViewUiBinder.uiBinder.createAndBindUi(this));
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.ui.xml
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.ui.xml
index 5aaab3f7..cc6c9b5 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.ui.xml
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/section/login/view/LoginFormView.ui.xml
@@ -7,7 +7,7 @@
 
     <ui:with field='resources' 
type='org.ovirt.engine.ui.userportal.ApplicationResources' />
 
-    <ui:style>
+    <ui:style 
type="org.ovirt.engine.ui.common.view.AbstractLoginFormView.Style">
         .loginForm:focus {
             outline: 0;
         }
@@ -35,11 +35,13 @@
             border-color: #b94a48;
         }
 
-        .login-message-error {
+        .loginMessageError {
             color: #b94a48;
             background-color: inherit;
             word-break: break-word;
             white-space: normal;
+            display: block;
+            text-align: left;
         }
 
         .information-triangle {
@@ -77,7 +79,6 @@
                 </b:Column>
 
                 <b:Well size="SMALL" addStyleNames="col-sm-11 
{style.login-error}" ui:field="errorMessagePanel">
-                    <b:Label ui:field="errorMessage" 
addStyleNames="{style.login-message-error} temp-link-color"/>
                 </b:Well>
 
                 <b:Column size="SM_7 MD_6 LG_5" addStyleNames="login">
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/login/view/LoginFormView.ui.xml
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/login/view/LoginFormView.ui.xml
index c979776..6c46d84 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/login/view/LoginFormView.ui.xml
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/login/view/LoginFormView.ui.xml
@@ -7,7 +7,7 @@
 
     <ui:with field='resources' 
type='org.ovirt.engine.ui.webadmin.ApplicationResources' />
 
-    <ui:style>
+    <ui:style 
type="org.ovirt.engine.ui.common.view.AbstractLoginFormView.Style">
         .loginForm:focus {
             outline: 0;
         }
@@ -35,11 +35,17 @@
             border-color: #b94a48;
         }
 
-        .login-message-error {
+        .loginMessageError a {
+            color: #cc0000;
+        }
+
+        .loginMessageError {
             color: #b94a48;
             background-color: inherit;
             word-break: break-word;
             white-space: normal;
+            display: block;
+            text-align: left;
         }
 
         .information-triangle {
@@ -66,7 +72,6 @@
                 </b:Column>
 
                 <b:Well size="SMALL" addStyleNames="col-sm-11 
{style.login-error}" ui:field="errorMessagePanel">
-                    <b:Label ui:field="errorMessage" 
addStyleNames="{style.login-message-error} temp-link-color"/>
                 </b:Well>
 
                 <b:Column size="SM_7 MD_6 LG_5" addStyleNames="login">


-- 
To view, visit https://gerrit.ovirt.org/38214
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd3bc6b716797583d3fc69fc69746bc3362eb58d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alexander Wels <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to