Search in sources :

Example 6 with RunAsSystem

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;
}
Also used : MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with RunAsSystem

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;
}
Also used : User(org.molgenis.data.security.auth.User) Token(org.molgenis.data.security.auth.Token) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with RunAsSystem

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);
}
Also used : Token(org.molgenis.data.security.auth.Token) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with RunAsSystem

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);
}
Also used : User(org.molgenis.data.security.auth.User) MolgenisUserException(org.molgenis.security.user.MolgenisUserException) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 10 with RunAsSystem

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.");
    }
}
Also used : User(org.molgenis.data.security.auth.User) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MolgenisUserException(org.molgenis.security.user.MolgenisUserException) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Aggregations

RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)29 Entity (org.molgenis.data.Entity)12 Transactional (org.springframework.transaction.annotation.Transactional)7 User (org.molgenis.data.security.auth.User)5 QueryImpl (org.molgenis.data.support.QueryImpl)4 UnknownEntityException (org.molgenis.data.UnknownEntityException)3 MolgenisUserException (org.molgenis.security.user.MolgenisUserException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Stream (java.util.stream.Stream)2 DataService (org.molgenis.data.DataService)2 Fetch (org.molgenis.data.Fetch)2 IndexActionGroup (org.molgenis.data.index.meta.IndexActionGroup)2 INDEX_ACTION_GROUP (org.molgenis.data.index.meta.IndexActionGroupMetaData.INDEX_ACTION_GROUP)2 Token (org.molgenis.data.security.auth.Token)2 ProgressImpl (org.molgenis.jobs.ProgressImpl)2 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)2 RunAsUserToken (org.springframework.security.access.intercept.RunAsUserToken)2