shopizer-developers
Details
sm-shop/SALESMANAGER.h2.db 0(+0 -0)
diff --git a/sm-shop/SALESMANAGER.h2.db b/sm-shop/SALESMANAGER.h2.db
index 6f1b0b6..86cd45b 100644
Binary files a/sm-shop/SALESMANAGER.h2.db and b/sm-shop/SALESMANAGER.h2.db differ
sm-shop/SALESMANAGER.lock.db 4(+4 -0)
diff --git a/sm-shop/SALESMANAGER.lock.db b/sm-shop/SALESMANAGER.lock.db
new file mode 100644
index 0000000..55f38b5
--- /dev/null
+++ b/sm-shop/SALESMANAGER.lock.db
@@ -0,0 +1,4 @@
+#FileLock
+#Tue Feb 27 11:07:08 EST 2018
+id=161d8047dedc5b6b7e4d39907481f4a86196ccefa53
+method=file
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/user/AuthenticateUserApi.java b/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/user/AuthenticateUserApi.java
new file mode 100644
index 0000000..f40bd11
--- /dev/null
+++ b/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/user/AuthenticateUserApi.java
@@ -0,0 +1,122 @@
+package com.salesmanager.shop.store.api.v1.user;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
+
+import org.apache.http.auth.AuthenticationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.mobile.device.Device;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+import com.salesmanager.core.model.merchant.MerchantStore;
+import com.salesmanager.core.model.reference.language.Language;
+import com.salesmanager.shop.model.customer.PersistableCustomer;
+import com.salesmanager.shop.store.controller.customer.facade.CustomerFacade;
+import com.salesmanager.shop.store.controller.store.facade.StoreFacade;
+import com.salesmanager.shop.store.security.AuthenticationRequest;
+import com.salesmanager.shop.store.security.AuthenticationResponse;
+import com.salesmanager.shop.store.security.JWTTokenUtil;
+import com.salesmanager.shop.store.security.user.JWTUser;
+import com.salesmanager.shop.utils.LanguageUtils;
+
+/**
+ * Authenticates a User (Administration purpose)
+ * @author c.samson
+ *
+ */
+@Controller
+@RequestMapping("/api/v1")
+public class AuthenticateUserApi {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticateUserApi.class);
+
+ @Value("${authToken.header}")
+ private String tokenHeader;
+
+ @Inject
+ private AuthenticationManager jwtCustomerAuthenticationManager;
+
+ @Inject
+ private JWTTokenUtil jwtTokenUtil;
+
+
+
+
+
+ /**
+ * Authenticate a customer using username & password
+ * @param authenticationRequest
+ * @param device
+ * @return
+ * @throws AuthenticationException
+ */
+ @RequestMapping(value = "/private/login", method = RequestMethod.POST)
+ public ResponseEntity<?> authenticate(@RequestBody @Valid AuthenticationRequest authenticationRequest, Device device) throws AuthenticationException {
+
+ // Perform the security
+ Authentication authentication = null;
+ try {
+
+
+ //to be used when username and password are set
+ authentication = jwtCustomerAuthenticationManager.authenticate(
+ new UsernamePasswordAuthenticationToken(
+ authenticationRequest.getUsername(),
+ authenticationRequest.getPassword()
+ )
+ );
+
+
+ } catch(Exception e) {
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ }
+
+ if(authentication == null) {
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ }
+
+ SecurityContextHolder.getContext().setAuthentication(authentication);
+
+ // Reload password post-security so we can generate token
+ // todo create one for social
+ //final JWTUser userDetails = (JWTUser)jwtCustomerDetailsService.loadUserByUsername(authenticationRequest.getUsername());
+
+ //final String token = jwtTokenUtil.generateToken(userDetails, device);
+
+ // Return the token
+ //return ResponseEntity.ok(new AuthenticationResponse(userDetails.getId(),token));
+
+ return null;
+ }
+
+/* @RequestMapping(value = "/auth/refresh", method = RequestMethod.GET)
+ public ResponseEntity<?> refreshAndGetAuthenticationToken(HttpServletRequest request) {
+ String token = request.getHeader(tokenHeader);
+ String username = jwtTokenUtil.getUsernameFromToken(token);
+ JWTUser user = (JWTUser) jwtCustomerDetailsService.loadUserByUsername(username);
+
+ if (jwtTokenUtil.canTokenBeRefreshed(token, user.getLastPasswordResetDate())) {
+ String refreshedToken = jwtTokenUtil.refreshToken(token);
+ return ResponseEntity.ok(new AuthenticationResponse(user.getId(),refreshedToken));
+ } else {
+ return ResponseEntity.badRequest().body(null);
+ }
+ }*/
+
+}