Skip to content

Commit c681b3d

Browse files
authored
Merge pull request #450 from ministryofjustice/bugfix/common-pool-ldap-context
2 parents 33429ac + 304bd32 commit c681b3d

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

src/main/java/uk/co/bconline/ndelius/config/cache/CacheConfig.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,42 @@
1111
import uk.co.bconline.ndelius.service.RoleGroupService;
1212
import uk.co.bconline.ndelius.service.RoleService;
1313

14+
import java.util.Objects;
15+
import java.util.stream.Stream;
16+
1417
@Slf4j
1518
@Configuration
1619
@EnableCaching
17-
public class CacheConfig
18-
{
20+
public class CacheConfig {
1921
private final RoleService roleService;
2022
private final RoleGroupService roleGroupService;
2123

2224
@Autowired
23-
public CacheConfig(RoleService roleService, RoleGroupService roleGroupService)
24-
{
25+
public CacheConfig(RoleService roleService, RoleGroupService roleGroupService) {
2526
this.roleService = roleService;
2627
this.roleGroupService = roleGroupService;
2728
}
2829

2930
@Bean
30-
public CacheManager cacheManager()
31-
{
31+
public CacheManager cacheManager() {
3232
return new ConcurrentMapCacheManager();
3333
}
3434

35-
public void evictCache()
36-
{
37-
cacheManager().getCacheNames().parallelStream()
38-
.map(cacheManager()::getCache)
39-
.peek(cache -> log.debug("Cache {} = {}", cache.getName(), cache.getNativeCache()))
40-
.forEach(Cache::clear);
35+
public void evictCache() {
36+
getCaches().forEach(Cache::clear);
4137
log.info("Flushed all caches");
4238

4339
// Populate role + rolegroup cache
4440
roleService.getAllRoles();
4541
roleGroupService.getRoleGroups().forEach(group -> roleGroupService.getRoleGroup(group.getName()));
4642
log.info("Re-populated role and group caches");
47-
cacheManager().getCacheNames().parallelStream()
43+
getCaches();
44+
}
45+
46+
private Stream<Cache> getCaches() {
47+
return cacheManager().getCacheNames().parallelStream()
4848
.map(cacheManager()::getCache)
49-
.forEach(cache -> log.info("Cache {} = {}", cache.getName(), cache.getNativeCache()));
49+
.filter(Objects::nonNull)
50+
.peek(cache -> log.debug("Cache {} = {}", cache.getName(), cache.getNativeCache()));
5051
}
5152
}

src/main/java/uk/co/bconline/ndelius/service/impl/UserEntryServiceImpl.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,13 @@ private void updateUserGroups(String username, Set<Name> groups)
198198
val newGroups = ofNullable(groups).orElse(emptySet());
199199
val groupsToAdd = Sets.difference(newGroups, existingGroups);
200200
val groupsToRemove = Sets.difference(existingGroups, newGroups);
201-
groupService.getGroups(groupsToAdd).parallelStream()
201+
// Note: We must use serial streams here, due to a bug in Spring LDAP meaning the commonPool loads the
202+
// incorrect DirContext class.
203+
// See https://github.com/spring-projects/spring-ldap/issues/501
204+
groupService.getGroups(groupsToAdd).stream()
202205
.peek(group -> group.getMembers().add(userDn))
203206
.forEach(groupService::save);
204-
groupService.getGroups(groupsToRemove).parallelStream()
207+
groupService.getGroups(groupsToRemove).stream()
205208
.peek(group -> group.getMembers().remove(userDn))
206209
.forEach(groupService::save);
207210
}
@@ -227,10 +230,10 @@ public void save(UserEntry user)
227230

228231
// Preferences
229232
log.debug("Checking if user preferences exist");
230-
if (!preferencesRepository.findOne(query()
233+
if (preferencesRepository.findOne(query()
231234
.searchScope(ONELEVEL)
232235
.base(getDn(user.getUsername()))
233-
.where(OBJECTCLASS).isPresent()).isPresent())
236+
.where(OBJECTCLASS).isPresent()).isEmpty())
234237
{
235238
log.debug("Creating user preferences");
236239
preferencesRepository.save(new UserPreferencesEntry(user.getUsername()));

src/main/resources/application.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ spring.application.name: ndelius-um
22

33
server:
44
servlet.context-path: /umt
5-
compression:
6-
enabled: true # Enable GZIP compression
7-
mime-types: application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css
5+
compression.enabled: true # Enable GZIP compression
86

97
spring.resources:
10-
static-locations: classpath:/ui
8+
chain.strategy.content.enabled: true
119
cache.cachecontrol:
1210
cache-public: true # Enable resource caching by browser or intermediaries
1311
no-cache: true # Enable revalidation on each request

ui/angular.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"builder": "@angular-devkit/build-angular:browser",
1919
"options": {
2020
"aot": true,
21-
"outputPath": "dist/ui",
21+
"outputPath": "dist/static",
2222
"index": "src/index.html",
2323
"main": "src/main.ts",
2424
"polyfills": "src/polyfills.ts",

0 commit comments

Comments
 (0)