Skip to content

Commit

Permalink
Use cacheMiss
Browse files Browse the repository at this point in the history
  • Loading branch information
fbelzunc committed May 18, 2016
1 parent bd25c3f commit 704e317
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ private List<SocketInfo> obtainLDAPServers(String domainName) throws Authenticat
public UserDetails retrieveUser(final String username, final String password, final String domainName, final List<SocketInfo> ldapServers) {
UserDetails userDetails;
try {
final ActiveDirectoryUserDetail[] cacheMiss = new ActiveDirectoryUserDetail[1];
userDetails = userCache.get(username, new Callable<UserDetails>() {
public UserDetails call() throws AuthenticationException {
DirContext context;
Expand Down Expand Up @@ -312,11 +313,12 @@ public UserDetails call() throws AuthenticationException {
Set<GrantedAuthority> groups = resolveGroups(domainDN, dnFormatted, context);
groups.add(SecurityRealm.AUTHENTICATED_AUTHORITY);

return new ActiveDirectoryUserDetail(username, password, true, true, true, true, groups.toArray(new GrantedAuthority[groups.size()]),
cacheMiss[0] = new ActiveDirectoryUserDetail(username, password, true, true, true, true, groups.toArray(new GrantedAuthority[groups.size()]),
getStringAttribute(user, "displayName"),
getStringAttribute(user, "mail"),
getStringAttribute(user, "telephoneNumber")
).updateUserInfo();
);
return cacheMiss[0];
} catch (NamingException e) {
if (anonymousBind && e.getMessage().contains("successful bind must be completed") && e.getMessage().contains("000004DC")) {
// sometimes (or always?) anonymous bind itself will succeed but the actual query will fail.
Expand All @@ -331,6 +333,9 @@ public UserDetails call() throws AuthenticationException {
}
}
});
if (cacheMiss[0] != null) {
cacheMiss[0].updateUserInfo();
}
} catch (UncheckedExecutionException e) {
Throwable t = e.getCause();
if (t instanceof AuthenticationException) {
Expand Down

0 comments on commit 704e317

Please sign in to comment.