<commit_before>package ch.difty.sipamato.web.security;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import ch.difty.sipamato.entity.User;
import ch.difty.sipamato.service.UserService;

/**
 * The implementation of {@link UserDetailsService} loads the user from the {@link UserService} and
 * wraps it into a a sipamato specific implementation of {@link UserDetails}.
 *
 * @author u.joss
 */
@Service("sipamatoUserDetailService")
public class SipamatoUserDetailService implements UserDetailsService {

    private final UserService userService;

    @Autowired
    public SipamatoUserDetailService(final UserService userService) {
        this.userService = userService;
    }

    @Override
    public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
        final Optional<User> userOption = userService.findByUserName(username);
        if (!userOption.isPresent()) {
            throw new UsernameNotFoundException("No user found with name " + username);
        } else {
            return new SipamatoUserDetails(userOption.get());
        }
    }

}
<commit_msg>Don't explicitly declare a runtime exception<commit_after>package ch.difty.sipamato.web.security;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import ch.difty.sipamato.entity.User;
import ch.difty.sipamato.service.UserService;

/**
 * The implementation of {@link UserDetailsService} loads the user from the {@link UserService} and
 * wraps it into a a sipamato specific implementation of {@link UserDetails}.
 *
 * @author u.joss
 */
@Service("sipamatoUserDetailService")
public class SipamatoUserDetailService implements UserDetailsService {

    private final UserService userService;

    @Autowired
    public SipamatoUserDetailService(final UserService userService) {
        this.userService = userService;
    }

    @Override
    public UserDetails loadUserByUsername(final String username) {
        final Optional<User> userOption = userService.findByUserName(username);
        if (!userOption.isPresent()) {
            throw new UsernameNotFoundException("No user found with name " + username);
        } else {
            return new SipamatoUserDetails(userOption.get());
        }
    }

}

{'fraction_non_alphanumeric': 0.08473980309423347, 'fraction_numerical': 0.0, 'mean_word_length': 4.492277992277992, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2021332', 'n_tokens_mistral': 763, 'n_tokens_neox': 761, 'n_words': 177}