+ @Override
+ @Transactional(readOnly=false)
+ public void createGroup(String groupName, List<GrantedAuthority> authorities) {
+ Assert.hasText(groupName);
+ Assert.notNull(authorities);
+
+ Group newGroup = Group.NewInstance(groupName);
+ for (GrantedAuthority grantedAuthority: authorities){
+ newGroup.addGrantedAuthority(grantedAuthority);
+ }
+ saveGroup(newGroup);
+ }
+
+ @Override
+ @Transactional(readOnly=false)
+ @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER_MANAGER')")
+ public UUID saveGroup(Group group) {
+ return dao.save(group).getUuid();
+ }
+
+ @Override
+ @Transactional(readOnly=false)
+ public DeleteResult delete(UUID groupUUID ){
+
+ String groupUUIDString = groupUUID.toString();
+ Group group = dao.findByUuid(groupUUID);
+ //org.springframework.security.provisioning.GroupManager#deleteGroup needs a string argument
+ this.deleteGroup(groupUUIDString);
+ DeleteResult result = new DeleteResult();
+ result.addDeletedObject(group);
+ //there is no feedback from the deleteGroup method...
+ return result;
+ }
+
+ @Override
+ @Transactional(readOnly = false)
+ public MergeResult<Group> merge(Group newInstance, boolean returnTransientEntity) {
+
+ Set<GrantedAuthority> newAuthorities = newInstance.getGrantedAuthorities();
+ Map<GrantedAuthority, GrantedAuthority> mapOfAlreadyExistingAuthorities = new HashMap<GrantedAuthority, GrantedAuthority>();
+ GrantedAuthorityImpl alreadyInDB;
+ for (GrantedAuthority authority: newAuthorities){
+ if (authority instanceof GrantedAuthorityImpl){
+ alreadyInDB = grantedAuthorityDao.findAuthorityString(authority.getAuthority());
+ if (alreadyInDB != null){
+ if (alreadyInDB.getId() != ((GrantedAuthorityImpl)authority).getId()){
+ mapOfAlreadyExistingAuthorities.put(authority,alreadyInDB);
+ }
+ }
+ }
+ }
+ for (GrantedAuthority authority : mapOfAlreadyExistingAuthorities.keySet()){
+ newInstance.removeGrantedAuthority(authority);
+ newInstance.addGrantedAuthority(mapOfAlreadyExistingAuthorities.get(authority));
+ }
+
+ return dao.merge(newInstance, returnTransientEntity);
+ }