{"action":"created","issue":{"url":"https://api.github.com/repos/pac4j/pac4j/issues/247","labels_url":"https://api.github.com/repos/pac4j/pac4j/issues/247/labels{/name}","comments_url":"https://api.github.com/repos/pac4j/pac4j/issues/247/comments","events_url":"https://api.github.com/repos/pac4j/pac4j/issues/247/events","html_url":"https://github.com/pac4j/pac4j/issues/247","id":104216302,"number":247,"title":"Create a LocalCachingAuthenticator","user":{"login":"leleuj","id":1038508,"avatar_url":"https://avatars.githubusercontent.com/u/1038508?v=3","gravatar_id":"","url":"https://api.github.com/users/leleuj","html_url":"https://github.com/leleuj","followers_url":"https://api.github.com/users/leleuj/followers","following_url":"https://api.github.com/users/leleuj/following{/other_user}","gists_url":"https://api.github.com/users/leleuj/gists{/gist_id}","starred_url":"https://api.github.com/users/leleuj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leleuj/subscriptions","organizations_url":"https://api.github.com/users/leleuj/orgs","repos_url":"https://api.github.com/users/leleuj/repos","events_url":"https://api.github.com/users/leleuj/events{/privacy}","received_events_url":"https://api.github.com/users/leleuj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/pac4j/pac4j/milestones/2","html_url":"https://github.com/pac4j/pac4j/milestones/1.8","labels_url":"https://api.github.com/repos/pac4j/pac4j/milestones/2/labels","id":1159821,"number":2,"title":"1.8","description":null,"creator":{"login":"leleuj","id":1038508,"avatar_url":"https://avatars.githubusercontent.com/u/1038508?v=3","gravatar_id":"","url":"https://api.github.com/users/leleuj","html_url":"https://github.com/leleuj","followers_url":"https://api.github.com/users/leleuj/followers","following_url":"https://api.github.com/users/leleuj/following{/other_user}","gists_url":"https://api.github.com/users/leleuj/gists{/gist_id}","starred_url":"https://api.github.com/users/leleuj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leleuj/subscriptions","organizations_url":"https://api.github.com/users/leleuj/orgs","repos_url":"https://api.github.com/users/leleuj/repos","events_url":"https://api.github.com/users/leleuj/events{/privacy}","received_events_url":"https://api.github.com/users/leleuj/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":39,"state":"open","created_at":"2015-06-11T07:51:25Z","updated_at":"2015-09-17T07:42:27Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2015-09-01T08:40:42Z","updated_at":"2015-09-17T08:01:01Z","closed_at":null,"body":"For stateless use cases, the `Authenticator` may be called at each request. So it might be necessary to cache locally the result for the given credentials, to avoid any performance issue."},"comment":{"url":"https://api.github.com/repos/pac4j/pac4j/issues/comments/140997233","html_url":"https://github.com/pac4j/pac4j/issues/247#issuecomment-140997233","issue_url":"https://api.github.com/repos/pac4j/pac4j/issues/247","id":140997233,"user":{"login":"leleuj","id":1038508,"avatar_url":"https://avatars.githubusercontent.com/u/1038508?v=3","gravatar_id":"","url":"https://api.github.com/users/leleuj","html_url":"https://github.com/leleuj","followers_url":"https://api.github.com/users/leleuj/followers","following_url":"https://api.github.com/users/leleuj/following{/other_user}","gists_url":"https://api.github.com/users/leleuj/gists{/gist_id}","starred_url":"https://api.github.com/users/leleuj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leleuj/subscriptions","organizations_url":"https://api.github.com/users/leleuj/orgs","repos_url":"https://api.github.com/users/leleuj/repos","events_url":"https://api.github.com/users/leleuj/events{/privacy}","received_events_url":"https://api.github.com/users/leleuj/received_events","type":"User","site_admin":false},"created_at":"2015-09-17T08:01:01Z","updated_at":"2015-09-17T08:01:01Z","body":"@mmoayyed : in fact, there is an issue.\r\n\r\nHere is my test:\r\n\r\n```\r\nprivate class OnlyOneCallAuthenticator implements UsernamePasswordAuthenticator {\r\n  private int n = 0;\r\n  public void validate(final UsernamePasswordCredentials credentials) {\r\n    if (n > 0) {\r\n      throw new IllegalArgumentException(\"Cannot call validate twice\");\r\n    }\r\n    credentials.setUserProfile(new UserProfile());\r\n    n++;\r\n  }\r\n}\r\n\r\n@Test\r\npublic void testDoubleCalls() {\r\n  final OnlyOneCallAuthenticator authenticator = new OnlyOneCallAuthenticator();\r\n  final LocalCachingAuthenticator localCachingAuthenticator = new LocalCachingAuthenticator(authenticator, 10, 10, TimeUnit.SECONDS);\r\n  final HttpCredentials credentials1 = new UsernamePasswordCredentials(\"a\", \"a\", this.getClass().getName());\r\n  localCachingAuthenticator.validate(credentials1);\r\n  final HttpCredentials credentials2 = new UsernamePasswordCredentials(\"a\", \"a\", this.getClass().getName());\r\n  localCachingAuthenticator.validate(credentials2);\r\n}\r\n```\r\n\r\nIt throws an exception on the second call but it shouldn't, it should be taken from the cache, but the default `equals` should apply on references, not on the properties. Generating the `equals` and `hashCode` methods based on the `username` and `password` parameter makes the test pass.\r\n\r\nHere is a PR to fix that: https://github.com/pac4j/pac4j/pull/275\r\n\r\nWhat do you think?\r\n\r\n"}}