use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class MappingServiceImpl method addMappingProject.
@Override
@RunAsSystem
@Transactional
public MappingProject addMappingProject(String projectName, User owner, String target) {
MappingProject mappingProject = new MappingProject(projectName, owner);
mappingProject.addTarget(dataService.getEntityType(target));
mappingProjectRepository.add(mappingProject);
return mappingProject;
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class DataServiceTokenService method generateAndStoreToken.
/**
* Generates a token and associates it with a user.
* <p>
* Token expires in 2 hours
*
* @param username username
* @param description token description
* @return token
*/
@Override
@Transactional
@RunAsSystem
public String generateAndStoreToken(String username, String description) {
User user = dataService.query(USER, User.class).eq(USERNAME, username).findOne();
if (user == null) {
throw new IllegalArgumentException(format("Unknown username [%s]", username));
}
String token = tokenGenerator.generateToken();
Token molgenisToken = tokenFactory.create();
molgenisToken.setUser(user);
molgenisToken.setToken(token);
molgenisToken.setDescription(description);
molgenisToken.setExpirationDate(now().plus(2, HOURS));
dataService.add(TOKEN, molgenisToken);
return token;
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class DataServiceTokenService method removeToken.
@Override
@Transactional
@RunAsSystem
public void removeToken(String token) {
Token molgenisToken = getMolgenisToken(token);
dataService.delete(TOKEN, molgenisToken);
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class AccountServiceImpl method changePassword.
@Override
@RunAsSystem
public void changePassword(String username, String newPassword) {
User user = dataService.query(USER, User.class).eq(USERNAME, username).findOne();
if (user == null) {
throw new MolgenisUserException(format("Unknown user [%s]", username));
}
user.setPassword(newPassword);
user.setChangePassword(false);
dataService.update(USER, user);
LOG.info("Changed password of user [{}]", username);
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class AccountServiceImpl method activateUser.
@Override
@RunAsSystem
public void activateUser(String activationCode) {
User user = dataService.query(USER, User.class).eq(ACTIVE, false).and().eq(ACTIVATIONCODE, activationCode).findOne();
if (user != null) {
user.setActive(true);
dataService.update(USER, user);
// send activated email to user
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(user.getEmail());
mailMessage.setSubject("Your registration request for " + appSettings.getTitle());
mailMessage.setText(createActivatedEmailText(user, appSettings.getTitle()));
mailSender.send(mailMessage);
} else {
throw new MolgenisUserException("Invalid activation code or account already activated.");
}
}
Aggregations