]
Jan Kalina moved WFLY-8094 to ELY-965:
--------------------------------------
Project: WildFly Elytron (was: WildFly)
Key: ELY-965 (was: WFLY-8094)
Component/s: Realms
(was: Security)
Coverity static analysis, Resource leak, LdapsecurityRealm (Elytron)
--------------------------------------------------------------------
Key: ELY-965
URL:
https://issues.jboss.org/browse/ELY-965
Project: WildFly Elytron
Issue Type: Bug
Components: Realms
Reporter: Martin Choma
Assignee: Jan Kalina
Coverity static analysis found 8 occurence of Closeable object LdapIdentity not closing
properly.
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
https://scan7.coverity.com/reports.htm#v23632/p11778/fileInstanceId=95643...
{{LdapIdentity}} in {{close()}} method just close provided dirContext. {{LdapIdentity}}
does not create dirContext by itself. So it looks to me it is no necessary to implement
Closeable in {{LdapIdentity}}, as code where dirContext was created should be responsible
for closing it (and according to coverity it is closed properly everywhere).
{code:java|title=LdapSecurityRealm.java}
private class LdapIdentity implements Closeable {
private final String name;
private final DirContext dirContext;
private final String distinguishedName;
private final SearchResult entry;
LdapIdentity(String name, DirContext dirContext, String distinguishedName,
SearchResult entry) {
this.name = name;
this.dirContext = dirContext;
this.distinguishedName = distinguishedName;
this.entry = entry;
}
String getName() {
return this.name;
}
DirContext getDirContext() {
return this.dirContext;
}
String getDistinguishedName() {
return this.distinguishedName;
}
SearchResult getEntry() {
return this.entry;
}
@Override
public void close() throws IOException {
try {
dirContext.close();
} catch (NamingException e) {
log.debug("LdapSecurityRealm failed to close DirContext",
e);
}
}
}
{code}