use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class IndexActionRegisterServiceImpl method storeIndexActions.
@Override
@RunAsSystem
public void storeIndexActions(String transactionId) {
Set<Impact> changes = getChangesForCurrentTransaction();
if (changes.isEmpty()) {
return;
}
if (changes.stream().allMatch(impact -> excludedEntities.contains(impact.getEntityTypeId()))) {
return;
}
IndexActionGroup indexActionGroup = indexActionGroupFactory.create(transactionId);
IndexDependencyModel dependencyModel = createIndexDependencyModel(changes);
Stream<Impact> impactStream = indexingStrategy.determineImpact(changes, dependencyModel).stream().filter(key -> !excludedEntities.contains(key.getEntityTypeId()));
List<IndexAction> indexActions = mapWithIndex(impactStream, (key, actionOrder) -> createIndexAction(indexActionGroup, key, (int) actionOrder)).collect(toList());
if (indexActions.isEmpty()) {
return;
}
LOG.debug("Store index actions for transaction {}", transactionId);
dataService.add(INDEX_ACTION_GROUP, indexActionGroupFactory.create(transactionId).setCount(indexActions.size()));
dataService.add(INDEX_ACTION, indexActions.stream());
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class AlgorithmServiceImpl method autoGenerateAlgorithm.
@Override
@RunAsSystem
public void autoGenerateAlgorithm(EntityType sourceEntityType, EntityType targetEntityType, EntityMapping mapping, Attribute targetAttribute) {
LOG.debug("createAttributeMappingIfOnlyOneMatch: target= " + targetAttribute.getName());
Multimap<Relation, OntologyTerm> tagsForAttribute = ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute);
Map<Attribute, ExplainedAttribute> relevantAttributes = semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, tagsForAttribute.values(), null);
GeneratedAlgorithm generatedAlgorithm = algorithmGeneratorService.generate(targetAttribute, relevantAttributes, targetEntityType, sourceEntityType);
if (StringUtils.isNotBlank(generatedAlgorithm.getAlgorithm())) {
AttributeMapping attributeMapping = mapping.addAttributeMapping(targetAttribute.getName());
attributeMapping.setAlgorithm(generatedAlgorithm.getAlgorithm());
attributeMapping.getSourceAttributes().addAll(generatedAlgorithm.getSourceAttributes());
attributeMapping.setAlgorithmState(generatedAlgorithm.getAlgorithmState());
LOG.debug("Creating attribute mapping: " + targetAttribute.getName() + " = " + generatedAlgorithm.getAlgorithm());
}
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class UserDetailsService method loadUserByUsername.
@Override
@RunAsSystem
public UserDetails loadUserByUsername(String username) {
User user = dataService.query(UserMetaData.USER, User.class).eq(UserMetaData.USERNAME, username).findOne();
if (user == null) {
throw new UsernameNotFoundException("unknown user '" + username + "'");
}
Collection<? extends GrantedAuthority> authorities = getAuthorities(user);
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), user.isActive(), true, true, true, authorities);
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class TokenAuthenticationProvider method authenticate.
@Override
@RunAsSystem
public Authentication authenticate(Authentication authentication) {
if (!supports(authentication.getClass()))
throw new IllegalArgumentException("Only RestAuthenticationToken is supported");
RestAuthenticationToken authToken = (RestAuthenticationToken) authentication;
if (authToken.getToken() != null) {
// Throws UnknownTokenException
UserDetails userDetails = tokenService.findUserByToken(authToken.getToken());
// if token is invalid
authToken = new RestAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities(), authToken.getToken());
}
return authToken;
}
use of org.molgenis.security.core.runas.RunAsSystem in project molgenis by molgenis.
the class AccountServiceImpl method createUser.
@Override
@RunAsSystem
@Transactional
public void createUser(User user, String baseActivationUri) throws UsernameAlreadyExistsException, EmailAlreadyExistsException {
// Check if username already exists
if (userService.getUser(user.getUsername()) != null) {
throw new UsernameAlreadyExistsException("Username '" + user.getUsername() + "' already exists.");
}
// Check if email already exists
if (userService.getUserByEmail(user.getEmail()) != null) {
throw new EmailAlreadyExistsException("Email '" + user.getEmail() + "' is already registered.");
}
// collect activation info
String activationCode = idGenerator.generateId(SECURE_RANDOM);
List<String> activationEmailAddresses;
if (authenticationSettings.getSignUpModeration()) {
activationEmailAddresses = userService.getSuEmailAddresses();
if (activationEmailAddresses == null || activationEmailAddresses.isEmpty())
throw new MolgenisDataException("Administrator account is missing required email address");
} else {
String activationEmailAddress = user.getEmail();
if (activationEmailAddress == null || activationEmailAddress.isEmpty())
throw new MolgenisDataException("User '" + user.getUsername() + "' is missing required email address");
activationEmailAddresses = asList(activationEmailAddress);
}
// create user
user.setActivationCode(activationCode);
user.setActive(false);
dataService.add(USER, user);
LOG.debug("created user " + user.getUsername());
// add user to group
Group group = dataService.query(GROUP, Group.class).eq(NAME, ALL_USER_GROUP).findOne();
GroupMember groupMember = null;
if (group != null) {
groupMember = groupMemberFactory.create();
groupMember.setGroup(group);
groupMember.setUser(user);
dataService.add(GROUP_MEMBER, groupMember);
}
// send activation email
URI activationUri = URI.create(baseActivationUri + '/' + activationCode);
try {
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(activationEmailAddresses.toArray(new String[] {}));
mailMessage.setSubject("User registration for " + appSettings.getTitle());
mailMessage.setText(createActivationEmailText(user, activationUri));
mailSender.send(mailMessage);
} catch (MailException mce) {
LOG.error("Could not send signup mail", mce);
if (groupMember != null) {
dataService.delete(GROUP_MEMBER, groupMember);
}
dataService.delete(USER, user);
throw new MolgenisUserException("An error occurred. Please contact the administrator. You are not signed up!");
}
LOG.debug("send activation email for user " + user.getUsername() + " to " + StringUtils.join(activationEmailAddresses, ','));
}
Aggregations