@Test public void test_authenticateLdap_failure_500() { UserLogin userLogin = new UserLogin("safeadmin", "safeadmin"); Response response = getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, true, "{\"errors\": [\"User Authentication failed\", \"This may be due to vault services are down or vault services are not reachable\"]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\": [\"User Authentication failed\", \"This may be due to vault services are down or vault services are not reachable\"]}"); String jsonStr = "{ \"username\": \"safeadmin\", \"password\": \"safeadmin\"}"; when(JSONUtil.getJSON(userLogin)).thenReturn(jsonStr); when(reqProcessor.process("/auth/ldap/login",jsonStr,"")).thenReturn(response); ResponseEntity<String> responseEntity = ldapAuthService.authenticateLdap(userLogin); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
public ResponseEntity<String> authenticateLdap(UserLogin userLogin){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Trying to authenticate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); String jsonStr = JSONUtil.getJSON(userLogin); Response response = reqProcessor.process("/auth/ldap/login",jsonStr,""); if(HttpStatus.OK.equals(response.getHttpstatus())){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Authentication Successful"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ if (HttpStatus.BAD_REQUEST.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Invalid username or password."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"Invalid username or password. Please retry again after correcting username or password.\"]}"); } else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Vault Services could be down."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"This may be due to vault services are down or vault services are not reachable\"]}"); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Username Authentication Failed.\"]}"); } }
LDAPAuthService { public ResponseEntity<String> authenticateLdap(UserLogin userLogin){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Trying to authenticate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); String jsonStr = JSONUtil.getJSON(userLogin); Response response = reqProcessor.process("/auth/ldap/login",jsonStr,""); if(HttpStatus.OK.equals(response.getHttpstatus())){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Authentication Successful"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ if (HttpStatus.BAD_REQUEST.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Invalid username or password."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"Invalid username or password. Please retry again after correcting username or password.\"]}"); } else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Vault Services could be down."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"This may be due to vault services are down or vault services are not reachable\"]}"); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Username Authentication Failed.\"]}"); } } }
LDAPAuthService { public ResponseEntity<String> authenticateLdap(UserLogin userLogin){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Trying to authenticate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); String jsonStr = JSONUtil.getJSON(userLogin); Response response = reqProcessor.process("/auth/ldap/login",jsonStr,""); if(HttpStatus.OK.equals(response.getHttpstatus())){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Authentication Successful"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ if (HttpStatus.BAD_REQUEST.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Invalid username or password."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"Invalid username or password. Please retry again after correcting username or password.\"]}"); } else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Vault Services could be down."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"This may be due to vault services are down or vault services are not reachable\"]}"); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Username Authentication Failed.\"]}"); } }  }
LDAPAuthService { public ResponseEntity<String> authenticateLdap(UserLogin userLogin){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Trying to authenticate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); String jsonStr = JSONUtil.getJSON(userLogin); Response response = reqProcessor.process("/auth/ldap/login",jsonStr,""); if(HttpStatus.OK.equals(response.getHttpstatus())){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Authentication Successful"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ if (HttpStatus.BAD_REQUEST.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Invalid username or password."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"Invalid username or password. Please retry again after correcting username or password.\"]}"); } else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Vault Services could be down."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"This may be due to vault services are down or vault services are not reachable\"]}"); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Username Authentication Failed.\"]}"); } }  ResponseEntity<String> authenticateLdap(UserLogin userLogin); ResponseEntity<String> configureLdapGroup(String token, LDAPGroup ldapGroup); ResponseEntity<String> listLdapGroups(String token); ResponseEntity<String> fetchLdapGroup(String token, String groupname); ResponseEntity<String> deleteLdapGroup(String token, String groupname); ResponseEntity<String> configureLdapUser(String token, LDAPUser ldapUser); ResponseEntity<String> listLdapUsers(String token); ResponseEntity<String> fetchLdapUser(String token, String username); ResponseEntity<String> deleteLdapUser(String token, String username); }
LDAPAuthService { public ResponseEntity<String> authenticateLdap(UserLogin userLogin){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Trying to authenticate"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); String jsonStr = JSONUtil.getJSON(userLogin); Response response = reqProcessor.process("/auth/ldap/login",jsonStr,""); if(HttpStatus.OK.equals(response.getHttpstatus())){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "Authentication Successful"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ if (HttpStatus.BAD_REQUEST.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Invalid username or password."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"Invalid username or password. Please retry again after correcting username or password.\"]}"); } else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed. Vault Services could be down."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\": [\"User Authentication failed\", \"This may be due to vault services are down or vault services are not reachable\"]}"); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, userLogin.getUsername()). put(LogMessage.ACTION, "LDAP Login"). put(LogMessage.MESSAGE, "User Authentication failed."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"errors\":[\"Username Authentication Failed.\"]}"); } }  ResponseEntity<String> authenticateLdap(UserLogin userLogin); ResponseEntity<String> configureLdapGroup(String token, LDAPGroup ldapGroup); ResponseEntity<String> listLdapGroups(String token); ResponseEntity<String> fetchLdapGroup(String token, String groupname); ResponseEntity<String> deleteLdapGroup(String token, String groupname); ResponseEntity<String> configureLdapUser(String token, LDAPUser ldapUser); ResponseEntity<String> listLdapUsers(String token); ResponseEntity<String> fetchLdapUser(String token, String username); ResponseEntity<String> deleteLdapUser(String token, String username);  }