Skip to content

Commit 409831a

Browse files
zlamalpHejdaJakub
authored andcommitted
fix(core): Do not cache LDAP ExtSource
- Do not use same instance of LDAP ExtSource since they share their DirContext and can close it when others are in the middle of synchronization process. - Removed empty class for already deleted ExtSourceVOOT. (cherry picked from commit 7da88e8)
1 parent e76786e commit 409831a

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

perun-core/src/main/java/cz/metacentrum/perun/core/blImpl/ExtSourcesManagerBlImpl.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import cz.metacentrum.perun.core.bl.ExtSourcesManagerBl;
3333
import cz.metacentrum.perun.core.bl.PerunBl;
34+
import cz.metacentrum.perun.core.impl.ExtSourceLdap;
3435
import cz.metacentrum.perun.core.impl.Utils;
3536
import cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi;
3637
import cz.metacentrum.perun.core.implApi.ExtSourcesManagerImplApi;
@@ -73,7 +74,7 @@ public void initialize(PerunSession sess) {
7374

7475
private Map<Integer,ExtSource> extSourcesByIdMap = new HashMap<>();
7576
private Map<String,ExtSource> extSourcesByNameMap = new HashMap<>();
76-
77+
7778
private void cacheExtSourcesInMemory(PerunSession sess) {
7879
Map<Integer,ExtSource> extSourcesByIdMap = new HashMap<>();
7980
Map<String,ExtSource> extSourcesByNameMap = new HashMap<>();
@@ -112,34 +113,65 @@ public void deleteExtSource(PerunSession sess, ExtSource extSource) throws ExtSo
112113
@Override
113114
public ExtSource getExtSourceById(PerunSession sess, int id) throws InternalErrorException, ExtSourceNotExistsException {
114115
ExtSource extSource = extSourcesByIdMap.get(id);
116+
if (extSource instanceof ExtSourceLdap) {
117+
// FIXME - retrieve new instance for LDAP ExtSources !!
118+
return getExtSourcesManagerImpl().getExtSourceById(sess, id);
119+
}
115120
if (extSource == null) throw new ExtSourceNotExistsException("ExtSource with ID=" + id + " not exists");
116121
return extSource;
117122
}
118123

119124
@Override
120125
public ExtSource getExtSourceByName(PerunSession sess, String name) throws InternalErrorException, ExtSourceNotExistsException {
121126
ExtSource extSource = extSourcesByNameMap.get(name);
127+
if (extSource instanceof ExtSourceLdap) {
128+
// FIXME - retrieve new instance for LDAP ExtSources !!
129+
return getExtSourcesManagerImpl().getExtSourceByName(sess, name);
130+
}
122131
if (extSource == null) throw new ExtSourceNotExistsException("ExtSource with name =" + name + " not exists");
123132
return extSource;
124133
}
125134

126135
@Override
127136
public List<ExtSource> getVoExtSources(PerunSession sess, Vo vo) throws InternalErrorException {
128137
List<Integer> ids = getExtSourcesManagerImpl().getVoExtSourcesIds(sess, vo);
129-
return ids.stream().map(id -> extSourcesByIdMap.get(id)).collect(Collectors.toList());
138+
return ids.stream().map(id -> { ExtSource extSource = extSourcesByIdMap.get(id);
139+
if (extSource instanceof ExtSourceLdap) {
140+
// FIXME - retrieve new instance for LDAP ExtSources !!
141+
try {
142+
return getExtSourcesManagerImpl().getExtSourceById(sess, id);
143+
} catch (ExtSourceNotExistsException e) {
144+
log.error("VO ExtSource by its ID doesn't exists!");
145+
throw new ConsistencyErrorException("VO ExtSource by its ID doesn't exists!", e);
146+
}
147+
}
148+
return extSource;
149+
}).collect(Collectors.toList());
130150
}
131151

132152
@Override
133153
public List<ExtSource> getGroupExtSources(PerunSession sess, Group group) throws InternalErrorException {
134154
List<Integer> ids = getExtSourcesManagerImpl().getGroupExtSourcesIds(sess, group);
135-
return ids.stream().map(id -> extSourcesByIdMap.get(id)).collect(Collectors.toList());
155+
return ids.stream().map(id -> { ExtSource extSource = extSourcesByIdMap.get(id);
156+
if (extSource instanceof ExtSourceLdap) {
157+
// FIXME - retrieve new instance for LDAP ExtSources !!
158+
try {
159+
return getExtSourcesManagerImpl().getExtSourceById(sess, id);
160+
} catch (ExtSourceNotExistsException e) {
161+
log.error("Group ExtSource by its ID doesn't exists!");
162+
throw new ConsistencyErrorException("VO ExtSource by its ID doesn't exists!", e);
163+
}
164+
}
165+
return extSource;
166+
}).collect(Collectors.toList());
136167
}
137168

138169
@Override
139170
public List<ExtSource> getExtSources(PerunSession sess) throws InternalErrorException {
171+
// FIXME - no need to retrieve new instance for LDAP ExtSources since its used only by outer API and tests.
140172
return new ArrayList<>(extSourcesByIdMap.values());
141173
}
142-
174+
143175
@Override
144176
public void addExtSource(PerunSession sess, Vo vo, ExtSource source) throws ExtSourceAlreadyAssignedException {
145177
getExtSourcesManagerImpl().addExtSource(sess, vo, source);

perun-core/src/main/java/cz/metacentrum/perun/core/impl/ExtSourceVOOT.java

Whitespace-only changes.

0 commit comments

Comments
 (0)