details: https://code.openbravo.com/erp/devel/pi/rev/10f75897fc09 changeset: 13413:10f75897fc09 user: Iván Perdomo <ivan.perdomo <at> openbravo.com> date: Wed Aug 03 20:03:06 2011 +0200 summary: Issue 18077: Changed dependency enforcement to be consistent with the rest
details: https://code.openbravo.com/erp/devel/pi/rev/bb1404edc6b4 changeset: 13414:bb1404edc6b4 user: Iván Perdomo <ivan.perdomo <at> openbravo.com> date: Wed Aug 03 20:05:52 2011 +0200 summary: Issue 18077: Code improvement based on code review - Some improvements based on code review: * Added a new message when the user try to associate an account already associated * OBContext.setAdmin(false) is not working properly so remove the filter on client/org is required details: https://code.openbravo.com/erp/devel/pi/rev/f8c24d834286 changeset: 13415:f8c24d834286 user: Iván Perdomo <ivan.perdomo <at> openbravo.com> date: Wed Aug 03 20:08:22 2011 +0200 summary: Issue 18077: Code improvements based on code review * Added a unique constraint for OpenID identifier * Changed the module to be translatable * Removed the silent update of the email when associating account. Will be ask the user if he wants to update his email account details: https://code.openbravo.com/erp/devel/pi/rev/69b846d14162 changeset: 13416:69b846d14162 user: Iván Perdomo <ivan.perdomo <at> openbravo.com> date: Wed Aug 03 20:11:50 2011 +0200 summary: Issue 18077: Use message instead of title to report errors in Login page diffstat: modules/org.openbravo.service.integration.google/src-db/database/sourcedata/AD_MESSAGE.xml | 11 ++ modules/org.openbravo.service.integration.google/src/org/openbravo/service/integration/google/GoogleAuthServlet.java | 48 ++++++--- modules/org.openbravo.service.integration.openid/src-db/database/model/tables/OBSOID_USER_IDENTIFIER.xml | 3 + modules/org.openbravo.service.integration.openid/src-db/database/sourcedata/AD_MODULE.xml | 2 +- modules/org.openbravo.service.integration.openid/src/org/openbravo/service/integration/openid/OpenIDManager.java | 43 +++----- modules/org.openbravo.v3/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml | 4 +- 6 files changed, 67 insertions(+), 44 deletions(-) diffs (282 lines): diff -r ba6ad0fef636 -r 69b846d14162 modules/org.openbravo.service.integration.google/src-db/database/sourcedata/AD_MESSAGE.xml --- a/modules/org.openbravo.service.integration.google/src-db/database/sourcedata/AD_MESSAGE.xml Wed Aug 03 17:22:44 2011 +0200 +++ b/modules/org.openbravo.service.integration.google/src-db/database/sourcedata/AD_MESSAGE.xml Wed Aug 03 20:11:50 2011 +0200 @@ -80,4 +80,15 @@ <!--FF808081318644E00131864951C20011--> <AD_MODULE_ID><![CDATA[FF8080813129ADA401312CA1222A0005]]></AD_MODULE_ID> <!--FF808081318644E00131864951C20011--></AD_MESSAGE> +<!--FF8080813190BB58013190C047510009--><AD_MESSAGE> +<!--FF8080813190BB58013190C047510009--> <AD_MESSAGE_ID><![CDATA[FF8080813190BB58013190C047510009]]></AD_MESSAGE_ID> +<!--FF8080813190BB58013190C047510009--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--FF8080813190BB58013190C047510009--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--FF8080813190BB58013190C047510009--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--FF8080813190BB58013190C047510009--> <VALUE><![CDATA[OBSEIG_DuplicatedIdentifier]]></VALUE> +<!--FF8080813190BB58013190C047510009--> <MSGTEXT><![CDATA[This Google Account is already associated with another user. You can only associate one Google Account to one Openbravo user.]]></MSGTEXT> +<!--FF8080813190BB58013190C047510009--> <MSGTYPE><![CDATA[E]]></MSGTYPE> +<!--FF8080813190BB58013190C047510009--> <AD_MODULE_ID><![CDATA[FF8080813129ADA401312CA1222A0005]]></AD_MODULE_ID> +<!--FF8080813190BB58013190C047510009--></AD_MESSAGE> + </data> diff -r ba6ad0fef636 -r 69b846d14162 modules/org.openbravo.service.integration.google/src/org/openbravo/service/integration/google/GoogleAuthServlet.java --- a/modules/org.openbravo.service.integration.google/src/org/openbravo/service/integration/google/GoogleAuthServlet.java Wed Aug 03 17:22:44 2011 +0200 +++ b/modules/org.openbravo.service.integration.google/src/org/openbravo/service/integration/google/GoogleAuthServlet.java Wed Aug 03 20:11:50 2011 +0200 @@ -30,6 +30,7 @@ import org.apache.log4j.Logger; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; +import org.hibernate.exception.ConstraintViolationException; import org.openbravo.base.HttpBaseServlet; import org.openbravo.base.VariablesBase; import org.openbravo.base.exception.OBException; @@ -62,14 +63,14 @@ private static final long serialVersionUID = 1L; - private static Logger log = Logger.getLogger(GoogleAuthServlet.class); + private static final Logger log = Logger.getLogger(GoogleAuthServlet.class); @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { VariablesBase vars = new VariablesBase(req); - OBContext.setAdminMode(); + OBContext.setAdminMode(false); try { @@ -79,7 +80,8 @@ OBError error = new OBError(); // messageDB escapes double-quotes error.setTitle(""); - error.setMessage(Utility.messageBD(this, "OBSEIG_Activate", lang).replaceAll(""", "\"")); + error.setMessage(Utility.messageBD(this, "OBSEIG_Activate", lang) + .replaceAll(""", "\"")); error.setType("Error"); vars.setSessionObject("LoginErrorMsg", error); resp.sendRedirect(strDireccion); @@ -98,7 +100,7 @@ } } catch (Exception e) { - log4j.error(e.getMessage(), e); + log4j.error("Error trying to authenticate using Google Auth service: " + e.getMessage(), e); } finally { OBContext.restorePreviousMode(); } @@ -114,7 +116,7 @@ final VariablesSecureApp vars = new VariablesSecureApp(req); try { - OBContext.setAdminMode(); + OBContext.setAdminMode(false); String lang = OBDal.getInstance().get(Client.class, "0").getLanguage().getLanguage(); @@ -122,11 +124,25 @@ if ("true".equals(vars.getSessionValue("is_association"))) { vars.removeSessionValue("is_association"); - OpenIDManager.getInstance().associateAccount(oid, req, resp); - vars.setSessionValue("startup-message", Utility.messageBD(this, "OBSEIG_LinkedOK", lang) - .replaceAll(""", "\"")); - vars.setSessionValue("startup-message-title", Utility.messageBD(this, "ProcessOK", lang) - .replaceAll(""", "\"")); + try { + OpenIDManager.getInstance().associateAccount(oid, req, resp); + vars.setSessionValue("startup-message", Utility.messageBD(this, "OBSEIG_LinkedOK", lang) + .replaceAll(""", "\"")); + vars.setSessionValue("startup-message-title", Utility.messageBD(this, "ProcessOK", lang) + .replaceAll(""", "\"")); + + } catch (ConstraintViolationException e) { + log.error("Error trying to associate account with OpenID identifier: " + oid.toString(), + e); + // User notification + vars.setSessionValue( + "startup-message", + Utility.messageBD(this, "OBSEIG_DuplicatedIdentifier", lang).replaceAll(""", + "\"")); + vars.setSessionValue("startup-message-title", + Utility.messageBD(this, "ProcessFailed", lang).replaceAll(""", "\"")); + + } resp.sendRedirect(strDireccion); return; } @@ -162,7 +178,7 @@ } @SuppressWarnings("unchecked") - public User createUser(Identifier oid, HttpServletRequest req, HttpServletResponse resp) + private User createUser(Identifier oid, HttpServletRequest req, HttpServletResponse resp) throws OBException, IOException { Map<String, String> attributes = (Map<String, String>) req.getAttribute("attributes"); @@ -179,14 +195,14 @@ OBCriteria<OBSEIGDefaults> defaults = OBDal.getInstance().createCriteria(OBSEIGDefaults.class); defaults.setFilterOnReadableClients(false); - defaults.setFilterOnReadableClients(false); + defaults.setFilterOnReadableOrganization(false); if (defaults.count() == 0) { OBError error = new OBError(); - error.setTitle(Utility.messageBD(this, "OBSEIG_NoDefaultConf", lang) + error.setMessage(Utility.messageBD(this, "OBSEIG_NoDefaultConf", lang) .replaceAll("@@email@@", attributes.get(OpenIDManager.ATTRIBUTE_EMAIL)) .replaceAll(""", "\"")); - error.setMessage(""); + error.setTitle(""); error.setType("Error"); vars.setSessionObject("LoginErrorMsg", error); resp.sendRedirect(strDireccion); @@ -195,10 +211,10 @@ if (defaults.count() > 1) { OBError error = new OBError(); - error.setTitle(Utility.messageBD(this, "OBSEIG_TooMuchConf", lang) + error.setMessage(Utility.messageBD(this, "OBSEIG_TooMuchConf", lang) .replaceAll("@@email@@", attributes.get(OpenIDManager.ATTRIBUTE_EMAIL)) .replaceAll(""", "\"")); - error.setMessage(""); + error.setTitle(""); error.setType("Error"); vars.setSessionObject("LoginErrorMsg", error); resp.sendRedirect(strDireccion); diff -r ba6ad0fef636 -r 69b846d14162 modules/org.openbravo.service.integration.openid/src-db/database/model/tables/OBSOID_USER_IDENTIFIER.xml --- a/modules/org.openbravo.service.integration.openid/src-db/database/model/tables/OBSOID_USER_IDENTIFIER.xml Wed Aug 03 17:22:44 2011 +0200 +++ b/modules/org.openbravo.service.integration.openid/src-db/database/model/tables/OBSOID_USER_IDENTIFIER.xml Wed Aug 03 20:11:50 2011 +0200 @@ -50,6 +50,9 @@ <foreign-key foreignTable="AD_USER" name="OBSOID_USER_OID_AD_USER"> <reference local="AD_USER_ID" foreign="AD_USER_ID"/> </foreign-key> + <unique name="OBSOID_UN_IDENTIFIER"> + <unique-column name="OPENID_IDENTIFIER"/> + </unique> <check name="OBSOID_USER_OID_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 'N')]]></check> </table> </database> diff -r ba6ad0fef636 -r 69b846d14162 modules/org.openbravo.service.integration.openid/src-db/database/sourcedata/AD_MODULE.xml --- a/modules/org.openbravo.service.integration.openid/src-db/database/sourcedata/AD_MODULE.xml Wed Aug 03 17:22:44 2011 +0200 +++ b/modules/org.openbravo.service.integration.openid/src-db/database/sourcedata/AD_MODULE.xml Wed Aug 03 20:11:50 2011 +0200 @@ -14,7 +14,7 @@ <!--FF8080813141B198013141B86DD70003--> <JAVAPACKAGE><![CDATA[org.openbravo.service.integration.openid]]></JAVAPACKAGE> <!--FF8080813141B198013141B86DD70003--> <LICENSETYPE><![CDATA[OBPL]]></LICENSETYPE> <!--FF8080813141B198013141B86DD70003--> <AUTHOR><![CDATA[Openbravo S.L.U.]]></AUTHOR> -<!--FF8080813141B198013141B86DD70003--> <ISTRANSLATIONREQUIRED><![CDATA[N]]></ISTRANSLATIONREQUIRED> +<!--FF8080813141B198013141B86DD70003--> <ISTRANSLATIONREQUIRED><![CDATA[Y]]></ISTRANSLATIONREQUIRED> <!--FF8080813141B198013141B86DD70003--> <AD_LANGUAGE><![CDATA[en_US]]></AD_LANGUAGE> <!--FF8080813141B198013141B86DD70003--> <HASCHARTOFACCOUNTS><![CDATA[N]]></HASCHARTOFACCOUNTS> <!--FF8080813141B198013141B86DD70003--> <ISTRANSLATIONMODULE><![CDATA[N]]></ISTRANSLATIONMODULE> diff -r ba6ad0fef636 -r 69b846d14162 modules/org.openbravo.service.integration.openid/src/org/openbravo/service/integration/openid/OpenIDManager.java --- a/modules/org.openbravo.service.integration.openid/src/org/openbravo/service/integration/openid/OpenIDManager.java Wed Aug 03 17:22:44 2011 +0200 +++ b/modules/org.openbravo.service.integration.openid/src/org/openbravo/service/integration/openid/OpenIDManager.java Wed Aug 03 20:11:50 2011 +0200 @@ -65,9 +65,9 @@ private static ConsumerManager manager; private static OpenIDManager instance; - private static Logger log = Logger.getLogger(OpenIDManager.class); + private static final Logger log = Logger.getLogger(OpenIDManager.class); - private static final Map<String, DiscoveryInformation> discoveryInformationMap; + private static Map<String, DiscoveryInformation> discoveryInformationMap; public static final String ATTRIBUTE_EMAIL = "email"; public static final String ATTRIBUTE_FIRSTNAME = "firstName"; @@ -75,13 +75,10 @@ public static final String GOOGLE_OPENID_DISCOVER_URL = "https://www.google.com/accounts/o8/id"; - static { - discoveryInformationMap = new HashMap<String, DiscoveryInformation>(); - } - - public static OpenIDManager getInstance() { + public static synchronized OpenIDManager getInstance() { if (instance == null) { instance = OBProvider.getInstance().get(OpenIDManager.class); + discoveryInformationMap = new HashMap<String, DiscoveryInformation>(); manager = new ConsumerManager(); manager.setAssociations(new InMemoryConsumerAssociationStore()); manager.setNonceVerifier(new InMemoryNonceVerifier(5000)); @@ -150,34 +147,33 @@ u = userCriteria.list().get(0).getUserContact(); } return u; + } - @SuppressWarnings("unchecked") public void associateAccount(Identifier oid, HttpServletRequest req, HttpServletResponse resp) throws Exception { - Map<String, String> userAttributes = (LinkedHashMap<String, String>) req - .getAttribute("attributes"); + // Map<String, String> userAttributes = (LinkedHashMap<String, String>) req + // .getAttribute("attributes"); User user = OBDal.getInstance().get(User.class, OBContext.getOBContext().getUser().getId()); - - if (!userAttributes.get(ATTRIBUTE_EMAIL).equals(user.getEmail())) { - try { - user.setEmail(userAttributes.get(ATTRIBUTE_EMAIL)); - OBDal.getInstance().save(user); - OBDal.getInstance().flush(); - } catch (Exception e) { - log.error("Error trying to update email for user: " + user.getUsername(), e); - } - } + // TODO: Ask the user if he wants to update the email account and uncomment this code + // if (!userAttributes.get(ATTRIBUTE_EMAIL).equals(user.getEmail())) { + // try { + // user.setEmail(userAttributes.get(ATTRIBUTE_EMAIL)); + // OBDal.getInstance().save(user); + // OBDal.getInstance().flush(); + // } catch (Exception e) { + // log.error("Error trying to update email for user: " + user.getUsername(), e); + // } + // } OBCriteria<OBSOIDUserIdentifier> oidCriteria = OBDal.getInstance().createCriteria( OBSOIDUserIdentifier.class); oidCriteria .add(Restrictions.eq(OBSOIDUserIdentifier.PROPERTY_OPENIDIDENTIFIER, oid.toString())); - oidCriteria.add(Restrictions.eq(OBSOIDUserIdentifier.PROPERTY_USERCONTACT, user)); if (oidCriteria.count() > 0) { - log.warn("Account association already exists"); + log.warn("Account association already exists - OpenID identifier: " + oid.toString()); return; } @@ -236,9 +232,6 @@ if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) { FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX); - // List emails = fetchResp.getAttributeValues("email"); - // String email = (String) emails.get(0); - List aliases = fetchResp.getAttributeAliases(); Map attributes = new LinkedHashMap(); for (Iterator iter = aliases.iterator(); iter.hasNext();) { diff -r ba6ad0fef636 -r 69b846d14162 modules/org.openbravo.v3/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml --- a/modules/org.openbravo.v3/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml Wed Aug 03 17:22:44 2011 +0200 +++ b/modules/org.openbravo.v3/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml Wed Aug 03 20:11:50 2011 +0200 @@ -94,7 +94,7 @@ <!--FF8080813189932B013189B45B59003A--> <STARTVERSION><![CDATA[0.1.0]]></STARTVERSION> <!--FF8080813189932B013189B45B59003A--> <ISINCLUDED><![CDATA[Y]]></ISINCLUDED> <!--FF8080813189932B013189B45B59003A--> <DEPENDANT_MODULE_NAME><![CDATA[OpenID Service Integration]]></DEPENDANT_MODULE_NAME> -<!--FF8080813189932B013189B45B59003A--> <DEPENDENCY_ENFORCEMENT><![CDATA[MINOR]]></DEPENDENCY_ENFORCEMENT> +<!--FF8080813189932B013189B45B59003A--> <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT> <!--FF8080813189932B013189B45B59003A--> <USER_EDITABLE_ENFORCEMENT><![CDATA[N]]></USER_EDITABLE_ENFORCEMENT> <!--FF8080813189932B013189B45B59003A--></AD_MODULE_DEPENDENCY> @@ -108,7 +108,7 @@ <!--FF8080813189932B013189B4C00F003D--> <STARTVERSION><![CDATA[0.1.0]]></STARTVERSION> <!--FF8080813189932B013189B4C00F003D--> <ISINCLUDED><![CDATA[Y]]></ISINCLUDED> <!--FF8080813189932B013189B4C00F003D--> <DEPENDANT_MODULE_NAME><![CDATA[Integration with Google APIs]]></DEPENDANT_MODULE_NAME> -<!--FF8080813189932B013189B4C00F003D--> <DEPENDENCY_ENFORCEMENT><![CDATA[MINOR]]></DEPENDENCY_ENFORCEMENT> +<!--FF8080813189932B013189B4C00F003D--> <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT> <!--FF8080813189932B013189B4C00F003D--> <USER_EDITABLE_ENFORCEMENT><![CDATA[N]]></USER_EDITABLE_ENFORCEMENT> <!--FF8080813189932B013189B4C00F003D--></AD_MODULE_DEPENDENCY> ------------------------------------------------------------------------------ BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1 _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits