package com.github.sbugat.samplerest.service.security;

import java.util.ArrayList;
import java.util.Collection;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.github.sbugat.samplerest.dao.UserDao;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;

@Named
public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService {

	@Inject
	private UserDao userDao;

	@Override
	public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

		final com.github.sbugat.samplerest.model.User user = userDao.findByUsername(username);
		if (null == user) {
			return null;
		}

		return new User(username, user.getPassword(), true, true, true, true, toAuthorities(user.getRoles()));
	}

	private static Collection<? extends GrantedAuthority> toAuthorities(final String roles) {

		final Collection<GrantedAuthority> authoritiesList = new ArrayList<>();

		for (final String role : Splitter.on(",").omitEmptyStrings().trimResults().split(Strings.nullToEmpty(roles))) {

			authoritiesList.add(new SimpleGrantedAuthority(role));
		}

		return authoritiesList;
	}
}

@@ -167,24 +167,130 @@
 t.Named;%0D%0A%0D%0A
+import org.slf4j.ext.XLogger;%0D%0Aimport org.slf4j.ext.XLogger.Level;%0D%0Aimport org.slf4j.ext.XLoggerFactory;%0D%0A
 import org.s
@@ -329,32 +329,32 @@
 ntedAuthority;%0D%0A
-
 import org.sprin
@@ -673,16 +673,76 @@
 erDao;%0D%0A
+import com.github.sbugat.samplerest.resource.UserResource;%0D%0A
 import c
@@ -937,16 +937,105 @@
 ce %7B%0D%0A%0D%0A
+%09private static final XLogger logger = XLoggerFactory.getXLogger(UserResource.class);%0D%0A%0D%0A
 %09@Inject
@@ -1173,24 +1173,132 @@
 eption %7B%0D%0A%0D%0A
+%09%09logger.entry(username);%0D%0A%09%09logger.info(%22=-------------------------------------------------%22 + username);%0D%0A
 %09%09final com.
@@ -1405,19 +1405,205 @@
 %0A%09%09%09
-return null
+final UsernameNotFoundException usernameNotFoundException = new UsernameNotFoundException(username);%0D%0A%09%09%09logger.throwing(Level.TRACE, usernameNotFoundException);%0D%0A%09%09%09throw usernameNotFoundException
 ;%0D%0A%09

Add logs