Revision 3d9a0098
Added by Andreas Kohlbecker over 6 years ago
src/main/java/eu/etaxonomy/cdm/service/CdmUserHelper.java | ||
---|---|---|
216 | 216 |
createAuthorityFor(userName(), cdmType, entitiyId, crud, property); |
217 | 217 |
} |
218 | 218 |
|
219 |
/** |
|
220 |
* {@inheritDoc} |
|
221 |
*/ |
|
222 |
@Override |
|
223 |
public void createAuthorityFor(String username, CdmBase cdmEntity, EnumSet<CRUD> crud, String property) { |
|
224 |
UserDetails userDetails = repo.getUserService().loadUserByUsername(username); |
|
225 |
if(userDetails != null){ |
|
226 |
User user = (User)userDetails; |
|
227 |
CdmAuthority authority = new CdmAuthority(cdmEntity, property, crud); |
|
228 |
try { |
|
229 |
user.getGrantedAuthorities().add(authority.asNewGrantedAuthority()); |
|
230 |
} catch (CdmAuthorityParsingException e) { |
|
231 |
throw new RuntimeException(e); |
|
232 |
} |
|
233 |
repo.getSession().flush(); |
|
234 |
logger.debug("new authority for " + username + ": " + authority.toString()); |
|
235 |
Authentication authentication = new PreAuthenticatedAuthenticationToken(user, user.getPassword(), user.getAuthorities()); |
|
236 |
SecurityContextHolder.getContext().setAuthentication(authentication); |
|
237 |
logger.debug("security context refreshed with user " + username); |
|
238 |
} |
|
239 |
|
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* {@inheritDoc} |
|
244 |
*/ |
|
245 |
@Override |
|
246 |
public void createAuthorityForCurrentUser(CdmBase cdmEntity, EnumSet<CRUD> crud, String property) { |
|
247 |
createAuthorityFor(userName(), cdmEntity, crud, property); |
|
248 |
|
|
249 |
} |
|
250 |
|
|
219 | 251 |
} |
Also available in: Unified diff
ref #6867 RegistrationWorkingsetEditor: granting UPDATE permissions for SpecimenOrObservationBase entities