From c61ba1deb4cf58bc44e1dfb272052dd64150eb49 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Sat, 26 Nov 2016 13:19:17 +0700 Subject: working spring security config --- .../main/java/com/juick/service/UserService.java | 4 +++ .../java/com/juick/service/UserServiceImpl.java | 33 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'juick-server/src/main/java/com/juick/service') diff --git a/juick-server/src/main/java/com/juick/service/UserService.java b/juick-server/src/main/java/com/juick/service/UserService.java index cfd5092a..4d7d09c9 100644 --- a/juick-server/src/main/java/com/juick/service/UserService.java +++ b/juick-server/src/main/java/com/juick/service/UserService.java @@ -28,6 +28,10 @@ public interface UserService { User getUserByName(String username); + User getFullyUserByName(String username); + + List getFullyUsersByNames(Collection usernames); + User getUserByJID(String jid); List getUsersByName(Collection unames); diff --git a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java index 2bdc4d41..d1e4eff5 100644 --- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java @@ -129,6 +129,39 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { return result; } + @Override + // No need marks with @Transactional annotation + public User getFullyUserByName(final String username) { + if (StringUtils.isNotBlank(username)) { + List list = getFullyUsersByNames(Collections.singletonList(username)); + if (!list.isEmpty()) + return list.get(0); + } + return null; + } + + @Transactional(readOnly = true) + @Override + public List getFullyUsersByNames(final Collection usernames) { + if (CollectionUtils.isEmpty(usernames)) + return Collections.emptyList(); + + return getNamedParameterJdbcTemplate().query( + "SELECT id, nick, passw, lang, banned FROM users WHERE nick in (:names)", + new MapSqlParameterSource("names", usernames), + (rs, rowNum) -> { + User user = new User(); + + user.setUid(rs.getInt(1)); + user.setName(rs.getString(2)); + user.setCredentials(rs.getString(3)); + user.setLang(rs.getString(4)); + user.setBanned(rs.getBoolean(5)); + + return user; + }); + } + @Transactional(readOnly = true) @Override public User getUserByJID(final String jid) { -- cgit v1.2.3