details:   https://code.openbravo.com/erp/devel/pi/rev/c109b6a0ee8a
changeset: 35748:c109b6a0ee8a
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Wed May 08 17:04:23 2019 +0200
summary:   fixes issue 40813: prevent NPE in web service authentication

details:   https://code.openbravo.com/erp/devel/pi/rev/41266f223ad5
changeset: 35749:41266f223ad5
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Wed May 08 17:08:32 2019 +0200
summary:   related to issue 40813: add test case

diffstat:

 src-test/src/org/openbravo/test/AllAntTaskTests.java                          
|   4 +
 src-test/src/org/openbravo/test/authentication/AuthenticationManagerTest.java 
|  47 ++++++++++
 src-test/src/org/openbravo/test/base/TestConstants.java                       
|   4 +
 src/org/openbravo/authentication/AuthenticationManager.java                   
|   2 +-
 4 files changed, 56 insertions(+), 1 deletions(-)

diffs (98 lines):

diff -r 7a1c0c6a1456 -r 41266f223ad5 
src-test/src/org/openbravo/test/AllAntTaskTests.java
--- a/src-test/src/org/openbravo/test/AllAntTaskTests.java      Wed May 08 
12:25:18 2019 +0000
+++ b/src-test/src/org/openbravo/test/AllAntTaskTests.java      Wed May 08 
17:08:32 2019 +0200
@@ -41,6 +41,7 @@
 import org.openbravo.erpCommon.info.ClassicSelectorTest;
 import org.openbravo.test.accounting.PostDocumentTest;
 import org.openbravo.test.accounting.RecordID2Test;
+import org.openbravo.test.authentication.AuthenticationManagerTest;
 import org.openbravo.test.cancelandreplace.CancelAndReplaceTest;
 import org.openbravo.test.centralbroker.CentralBrokerTest;
 import org.openbravo.test.copyLinesFromOrders.CopyLinesFromOrdersTest;
@@ -150,6 +151,9 @@
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
 
+    // authentication
+    AuthenticationManagerTest.class, //
+
     // dal
     DalComplexQueryRequisitionTest.class, //
     DalComplexQueryTestOrderLine.class, //
diff -r 7a1c0c6a1456 -r 41266f223ad5 
src-test/src/org/openbravo/test/authentication/AuthenticationManagerTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/src-test/src/org/openbravo/test/authentication/AuthenticationManagerTest.java 
    Wed May 08 17:08:32 2019 +0200
@@ -0,0 +1,47 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2019 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.test.authentication;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.openbravo.test.base.TestConstants.Users.OPENBRAVO;
+
+import org.junit.Test;
+import org.openbravo.authentication.basic.DefaultAuthenticationManager;
+import org.openbravo.test.base.OBBaseTest;
+
+/**
+ * Test cases to cover the authentication manager mechanism.
+ */
+public class AuthenticationManagerTest extends OBBaseTest {
+
+  private static final String USER_NAME = "Openbravo";
+  private static final String PASSWORD = "Openbravo";
+
+  /**
+   * Test the authentication intended for non standard REST web services (such 
as SOAP).
+   */
+  @Test
+  public void webServiceAuthenticate() {
+    DefaultAuthenticationManager authManager = new 
DefaultAuthenticationManager();
+    String userId = authManager.webServiceAuthenticate(USER_NAME, PASSWORD);
+    assertThat(userId, equalTo(OPENBRAVO));
+  }
+
+}
diff -r 7a1c0c6a1456 -r 41266f223ad5 
src-test/src/org/openbravo/test/base/TestConstants.java
--- a/src-test/src/org/openbravo/test/base/TestConstants.java   Wed May 08 
12:25:18 2019 +0000
+++ b/src-test/src/org/openbravo/test/base/TestConstants.java   Wed May 08 
17:08:32 2019 +0200
@@ -56,6 +56,10 @@
     public static final String COUNTRY = "Country";
   }
 
+  public static class Users {
+    public static final String OPENBRAVO = "100";
+  }
+
   private TestConstants() {
   }
 }
diff -r 7a1c0c6a1456 -r 41266f223ad5 
src/org/openbravo/authentication/AuthenticationManager.java
--- a/src/org/openbravo/authentication/AuthenticationManager.java       Wed May 
08 12:25:18 2019 +0000
+++ b/src/org/openbravo/authentication/AuthenticationManager.java       Wed May 
08 17:08:32 2019 +0200
@@ -263,7 +263,7 @@
     // If the current license has unlimited number of WS calls no limit will 
be checked, so there is
     // no need to create a new register in the AD_Session table
     if (activationKey.hasUnlimitedWsAccess()) {
-      if (!AuthenticationManager.isStatelessRequest(request)) {
+      if (request != null && 
!AuthenticationManager.isStatelessRequest(request)) {
         // force creation of the http session in stateful WS requests
         request.getSession(true);
       }


_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to