@Override
public SecurityContext createSecurityContext(WithMockJaasUser withUser) {
String username = StringUtils.hasLength(withUser.username()) ? withUser.username() : withUser.value();
List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
for (String authority : withUser.authorities()) {
grantedAuthorities.add(new JaasGrantedAuthority(authority, new GroupPrincipal(authority)));
}
User principal = new User(username, withUser.password(), true, true, true, true, grantedAuthorities);
Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), principal.getAuthorities());
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication);
return context;
}