Hi,

I created a custom authentication backend that makes an api request to my 
python app to authorize and authenticate users. Everything seems to be 
working well, but if I enter an incorrect password in a short period of 
time, I get this python error: "ConnectionResetError: [Errno 54] Connection 
reset by peer". Does anyone have any ideas why? Here is a quick look at my 
Java code: 
    @Override
   public AuthInfo authenticateAndAuthorize( AuthToken authToken ) throws 
AuthenticationException
   {
       String username = authToken.principal();
       char[] password = authToken.credentials();
       String url = "my api url"
       
       Map<String, String> arguments = new HashMap<>();
       arguments.put("username", username);
       arguments.put("password", new String(password));
       StringJoiner sj = new StringJoiner("&");
       for (Map.Entry<String, String> entry : arguments.entrySet())
           try {
               sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "=" + 
URLEncoder.encode(entry.getValue(), "UTF-8"));
           } catch (UnsupportedEncodingException e) {
               e.printStackTrace();
           }
       byte[] out = sj.toString().getBytes(StandardCharsets.UTF_8);
       int length = out.length;
       HttpURLConnection conn = null;
       try {
           conn = startConnection(url);
           // Send post request
           conn.setDoOutput(true);
           conn.setRequestMethod("POST");
           conn.setFixedLengthStreamingMode(length);
           conn.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded; 
charset=UTF-8");
           conn.connect();
           OutputStream os = conn.getOutputStream();
           os.write(out);
           int responseCode = conn.getResponseCode();
           os.close();

            if (responseCode == 200) {
               return AuthInfo.of("neo4j", Collections.singleton(
PredefinedRoles.READER));
           }
       } catch (IOException e) {
           e.printStackTrace();
       } finally {
           if (conn != null) {
               conn.disconnect();
           }
       }
       return null;
   }
Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to neo4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to