By: Guillaume Smaha user 09 Aug 2017 at 2:56 p.m. CDT

4 Responses
Guillaume Smaha gravatar
Hi, I want to customize my error message in a custom script for authentication. So I found LanguageBean class and getMessage method to get the message with a key and the current locale. But at start, an error is throw on the "import". I try with ``` from org.jboss.seam.faces import FacesMessages from org.jboss.seam.international import StatusMessage from org.xdi.oxauth.i18n import LanguageBean ... if not StringHelper.isNotEmptyString(user_name): faces_messages = FacesMessages.instance() faces_messages.clear() faces_messages.add(StatusMessage.Severity.ERROR, "login.empty_email") return False ``` and ``` from org.jboss.seam.faces import FacesMessages from org.jboss.seam.international import StatusMessage import org.xdi.oxauth.i18n.LanguageBean ... if not StringHelper.isNotEmptyString(user_name): faces_messages = FacesMessages.instance() faces_messages.clear() faces_messages.add(StatusMessage.Severity.ERROR, "login.empty_email") return False ``` But neither works. Do you have any idea to import this class ? And is it possible to hide the default error message without using an empty value on the key `login.errorMessage` in the messages_en.properties ?

By Guillaume Smaha user 09 Aug 2017 at 4:05 p.m. CDT

Guillaume Smaha gravatar
I try by another way but it also doesn't work. I found that `Authenticator` class in package `org.xdi.oxauth.auth` has a method `addMessage`. But when I try to get the current instance of the class, nothing happens and there is no error in the log. See my following script: ``` from org.jboss.seam.faces import FacesMessages from javax.faces.context import FacesContext from javax.faces.application import FacesMessage from org.xdi.oxauth.auth import Authenticator ... if not StringHelper.isNotEmptyString(user_name): print "Basic (lock account). Bad email" faces_messages = FacesMessages.instance() print "Basic (lock account). Bad email 2" faces_messages.add(FacesMessage.SEVERITY_ERROR, "login.empty_email 2") print "Basic (lock account). Bad email 3" authenticator_instance = Authenticator.instance() print "Basic (lock account). Bad email 3.5" authenticator_instance.addMessage(FacesMessage.SEVERITY_ERROR, "login.empty_email") ``` My last log is `Basic (lock account). Bad email 3`.

By Guillaume Smaha user 09 Aug 2017 at 4:39 p.m. CDT

Guillaume Smaha gravatar
I found it. I based my research on the branch `3.0.2` of oxAuth instead of `version_3.0.2`. So LanguageBean doesn't exist yet. I suppose this class will be release in the version 3.1.0. So, I solve it :) If anybody search the answer: Before `3.1.0`: ``` from org.jboss.seam.faces import FacesMessages from javax.faces.application import FacesMessage faces_messages = FacesMessages.instance() faces_messages.clear() faces_messages.addFromResourceBundle(FacesMessage.SEVERITY_ERROR, "login.empty_email") ``` I still have one question: Is it possible to hide the default error message without using an empty value on the key login.errorMessage in the messages_en.properties ?

By Aliaksandr Samuseu staff 09 Aug 2017 at 5:24 p.m. CDT

Aliaksandr Samuseu gravatar
Hi, Guillaume. Glad to know you found a solution. Thanks for sharing all the details, it will surely help others too. Regarding lack of error messages in logs in some cases: keep in mind you have an option of adding "catch-all" exception handlers into your code for debugging, this way you shouldn't miss anything (some errors won't be registered otherwise). Please also note we usually don't provide support for custom script development for community users. Your organisation may consider paying for some support plan including it if you think you may need it in the future.

By Guillaume Smaha user 10 Aug 2017 at 8:59 a.m. CDT

Guillaume Smaha gravatar
Hi Aliaksandr, Thanks for your answer. Could you delete this branch 3.0.2 to avoid future confusion when somebody tries to explore the code of this version ? Finally, I success to delete the default error message. I just show the first message: ```xhtml <!--<h:messages />--> <c:if test="#{fn:length(facesContext.messageList) > 0}"> <div class="alert alert-danger"> <h:outputText value="#{facesContext.messageList[0].summary}" escape="false" /> </div> </c:if> ``` The problem is solved, I close the ticket.