[backend] Removed obsolete user service method
This commit is contained in:
parent
bf8d282629
commit
b725458a8a
@ -1,6 +1,6 @@
|
|||||||
package org.ros.chatto.model;
|
package org.ros.chatto.model;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.time.Instant;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
@ -12,8 +12,6 @@ import javax.persistence.GenerationType;
|
|||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
@ -43,9 +41,9 @@ public class ChatUser {
|
|||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
String password;
|
private String password;
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
|
||||||
private Date joinDate;
|
private Instant joinDate;
|
||||||
|
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
@EqualsAndHashCode.Exclude
|
@EqualsAndHashCode.Exclude
|
||||||
@ -53,11 +51,4 @@ public class ChatUser {
|
|||||||
CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH })
|
CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH })
|
||||||
@JsonBackReference
|
@JsonBackReference
|
||||||
private Set<UserRole> userRoles;
|
private Set<UserRole> userRoles;
|
||||||
|
|
||||||
// @ToString.Exclude
|
|
||||||
// @EqualsAndHashCode.Exclude
|
|
||||||
// @OneToMany(mappedBy = "fromUser", cascade = { CascadeType.PERSIST,
|
|
||||||
// CascadeType.MERGE, CascadeType.DETACH,
|
|
||||||
// CascadeType.REFRESH })
|
|
||||||
// private List<ChatMessage> chatMessages;
|
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,8 @@ import org.springframework.stereotype.Repository;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserRepository extends JpaRepository<ChatUser, Long> {
|
public interface UserRepository extends JpaRepository<ChatUser, Long> {
|
||||||
@Query("select cu from ChatUser cu where cu.userName = ?1")
|
|
||||||
public Optional<ChatUser> findByUserName(String userName);
|
|
||||||
|
|
||||||
@Query("select cu from ChatUser cu join fetch cu.userRoles where cu.userName = ?1")
|
@Query("select cu from ChatUser cu join fetch cu.userRoles where cu.userName = ?1")
|
||||||
public ChatUser findByUserNameWithRole(String userName);
|
public Optional<ChatUser> findByUserName(String userName);
|
||||||
|
|
||||||
@Query("select cu.userName from ChatUser cu where cu.userName != ?1")
|
@Query("select cu.userName from ChatUser cu where cu.userName != ?1")
|
||||||
public List<String> findAllOtherUserNames(String userName);
|
public List<String> findAllOtherUserNames(String userName);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.ros.chatto.security;
|
package org.ros.chatto.security;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.ros.chatto.model.ChatUser;
|
import org.ros.chatto.model.ChatUser;
|
||||||
@ -26,17 +27,19 @@ public class MyUserDetailsService implements UserDetailsService {
|
|||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(final String username) {
|
public UserDetails loadUserByUsername(final String username) {
|
||||||
log.trace("User Details - loading with username: {}", username);
|
log.trace("User Details - loading with username: {}", username);
|
||||||
ChatUser user = userService.getUserWithRole(username);
|
Optional<ChatUser> user = userService.getUser(username);
|
||||||
|
|
||||||
if (user == null) {
|
if (!user.isPresent()) {
|
||||||
log.warn("Request for unknown user {}", username);
|
log.warn("Request for unknown user {}", username);
|
||||||
throw new UsernameNotFoundException(username);
|
throw new UsernameNotFoundException(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<UserRole> userRoles = user.getUserRoles();
|
ChatUser user2 = user.get();
|
||||||
|
|
||||||
return User.withUsername(user.getUserName())
|
Set<UserRole> userRoles = user2.getUserRoles();
|
||||||
.password(user.getPassword())
|
|
||||||
|
return User.withUsername(user2.getUserName())
|
||||||
|
.password(user2.getPassword())
|
||||||
.roles(userRoles.stream().map(ur -> ur.getRole().getName())
|
.roles(userRoles.stream().map(ur -> ur.getRole().getName())
|
||||||
.toArray(size -> new String[size]))
|
.toArray(size -> new String[size]))
|
||||||
.build();
|
.build();
|
||||||
|
@ -25,8 +25,6 @@ public interface UserService {
|
|||||||
|
|
||||||
public List<ActiveUserDTO> getOtherActiveUsers(String userName);
|
public List<ActiveUserDTO> getOtherActiveUsers(String userName);
|
||||||
|
|
||||||
public ChatUser getUserWithRole(String userName);
|
|
||||||
|
|
||||||
public void incrementUserSession(String userName);
|
public void incrementUserSession(String userName);
|
||||||
|
|
||||||
public UserSession decrementUserSession(String userName);
|
public UserSession decrementUserSession(String userName);
|
||||||
|
@ -139,12 +139,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public ChatUser getUserWithRole(final String userName) {
|
|
||||||
return userRepository.findByUserNameWithRole(userName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incrementUserSession(final String userName) {
|
public void incrementUserSession(final String userName) {
|
||||||
final Optional<ChatUser> chatUser = getUser(userName);
|
final Optional<ChatUser> chatUser = getUser(userName);
|
||||||
|
Loading…
Reference in New Issue
Block a user