cleanup of java backend (removed todos and obsolete code)
This commit is contained in:
parent
b47206496f
commit
f9e6e3085c
@ -6,13 +6,11 @@ import java.util.Random;
|
||||
public class SimpleCaptchaBehavior implements CaptchaBehaviour {
|
||||
@Override
|
||||
public BufferedImage generateCaptcha() {
|
||||
// TODO Auto-generated method stub
|
||||
SimpleCaptcha simpleCaptcha = new SimpleCaptcha();
|
||||
return simpleCaptcha.getImagePng();
|
||||
}
|
||||
@Override
|
||||
public BufferedImage generateCaptcha(String captchaText) {
|
||||
// TODO Auto-generated method stub
|
||||
SimpleCaptcha simpleCaptcha = new SimpleCaptcha(captchaText);
|
||||
return simpleCaptcha.getImagePng();
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import org.ehcache.event.CacheEvent;
|
||||
import org.ehcache.event.CacheEventListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
//@Component
|
||||
public class CustomCacheEventLogger implements CacheEventListener<Object, Object> {
|
||||
|
@ -11,7 +11,6 @@ import javax.validation.Valid;
|
||||
|
||||
import org.ros.chatto.dto.ChatMessageDTO;
|
||||
import org.ros.chatto.dto.ReencryptionDTO;
|
||||
import org.ros.chatto.model.ChatMessage;
|
||||
import org.ros.chatto.service.ChatService;
|
||||
import org.ros.chatto.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -21,8 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -30,7 +28,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
|
@ -92,17 +92,6 @@ public class DemoRestController {
|
||||
return userRoleRepository.getAllRegularUser();
|
||||
}
|
||||
|
||||
// @RequestMapping(value = "/", method = RequestMethod.POST)
|
||||
// public ResponseEntity<Car> update(@RequestBody Car car) {
|
||||
//
|
||||
// if (car != null) {
|
||||
// car.setMiles(car.getMiles() + 100);
|
||||
// }
|
||||
//
|
||||
// // TODO: call persistence layer to update
|
||||
// return new ResponseEntity<Car>(car, HttpStatus.OK);
|
||||
// }
|
||||
|
||||
@PostMapping(value = "/post-message", consumes = { "application/json" })
|
||||
public ResponseEntity<MessageCipher> postMessage(@RequestBody MessageCipher messageCipher) {
|
||||
System.out.println("Message cipher = " + messageCipher);
|
||||
|
@ -4,7 +4,6 @@ import java.security.Principal;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.ros.chatto.dto.ChatMessageDTO;
|
||||
import org.ros.chatto.service.DBInitializerService;
|
||||
import org.ros.chatto.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
@ -6,7 +6,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.ros.chatto.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
@ -11,20 +10,16 @@ import javax.persistence.EntityListeners;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.JoinColumn;
|
||||
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -7,11 +7,10 @@ import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/*Object { iv: "2rtnuXaJXFuQGO9ncaVkmA==", v: 1, iter: 10000, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes", salt: "H1z7o3f6qlQ=", ct: "lF9Uno7ihjVv01M8" }
|
||||
|
@ -2,7 +2,6 @@ package org.ros.chatto.repository;
|
||||
|
||||
import org.ros.chatto.model.Role;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
|
@ -35,7 +35,6 @@ class UserRepositoryCustomImpl implements UserRepositoryCustom{
|
||||
// System.out.println(un);
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
return userNamesList;
|
||||
|
@ -25,7 +25,6 @@ public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHa
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
|
||||
Authentication authentication) throws IOException, ServletException {
|
||||
// TODO Auto-generated method stub
|
||||
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
|
||||
if (authorities.contains(ADMIN_AUTHORITY) || authorities.contains(SUPER_USER_AUTHORITY)) {
|
||||
redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/admin");
|
||||
|
@ -1,98 +1,33 @@
|
||||
package org.ros.chatto.security;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.ros.chatto.model.ChatUser;
|
||||
import org.ros.chatto.model.UserRole;
|
||||
import org.ros.chatto.repository.RoleRepository;
|
||||
import org.ros.chatto.repository.UserRepository;
|
||||
import org.ros.chatto.repository.UserRoleRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.Cache.ValueWrapper;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserCache;
|
||||
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 org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
@Service
|
||||
public class MyUserDetailsService implements UserDetailsService {
|
||||
|
||||
// @Autowired
|
||||
// private WebApplicationContext applicationContext;
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
// @Autowired
|
||||
// private RoleRepository roleRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRoleRepository userRoleRepository;
|
||||
|
||||
// @Autowired
|
||||
// private UserCache userCache;
|
||||
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
|
||||
// @Autowired
|
||||
// private UserCache userCache;
|
||||
// @PostConstruct
|
||||
// public void completeSetup() {
|
||||
// userRepository = applicationContext.getBean(UserRepository.class);
|
||||
// }
|
||||
|
||||
public MyUserDetailsService() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Cacheable(value="chatUser")
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
// ChatUser user = userRepository.findByUserName(username);
|
||||
|
||||
List<UserRole> userRoles = userRoleRepository.findByUser(username);
|
||||
// @SuppressWarnings("unchecked")
|
||||
// List<UserRole> userRoles = (List<UserRole>)cacheManager.getCache(username);
|
||||
// if((userRoles == null)) {
|
||||
// userRoles = userRoleRepository.findByUser(username);
|
||||
// }
|
||||
// UserDetails userDetails = (UserDetails) cacheManager.getCache(username);
|
||||
// if((userDetails == null)) {
|
||||
// user = userRoleRepository.findByUser(username);
|
||||
// }
|
||||
System.out.println("Test from userdetails");
|
||||
|
||||
if (userRoles.size() == 0) {
|
||||
throw new UsernameNotFoundException(username);
|
||||
}
|
||||
// System.out.println("Found useeeeeeeeeeeeeeeeeeeeeeeeeeeeeeer " + user.getUserName() + user.getPassword());
|
||||
|
||||
// ChatUser user2 = userRoles.get(0).getUser();
|
||||
// System.out.println("User role iddddddddddddddddd = " + userRoles.get(0).getRole().getName());
|
||||
// System.out.println(userRoles.);
|
||||
// return new MyUserPrincipal(user);
|
||||
// return toUserDetails(new UserObject(user.getUserName(), user.getPassword(), userRoles.get(0).getRole().getName()));
|
||||
// return User.withUsername(user.getUserName()).password(user.getPassword())
|
||||
// .roles(
|
||||
// user.getUserRoles()
|
||||
// .stream()
|
||||
// .map(userRole -> {
|
||||
// System.out.println("role = " + userRole.getRole().getName());
|
||||
// return userRole.getRole().getName();
|
||||
// })
|
||||
// .toArray(size -> new String[size])
|
||||
// )
|
||||
// .build();
|
||||
ChatUser user = userRoles.get(0).getUser();
|
||||
return User.withUsername(user.getUserName()).password(user.getPassword())
|
||||
.roles(userRoles.stream().map(userRole -> {
|
||||
@ -100,20 +35,4 @@ public class MyUserDetailsService implements UserDetailsService {
|
||||
return userRole.getRole().getName();
|
||||
}).toArray(size -> new String[size])).build();
|
||||
}
|
||||
|
||||
private UserDetails toUserDetails(UserObject userObject) {
|
||||
return User.withUsername(userObject.name).password(userObject.password).roles(userObject.role).build();
|
||||
}
|
||||
|
||||
private static class UserObject {
|
||||
private String name;
|
||||
private String password;
|
||||
private String role;
|
||||
|
||||
public UserObject(String name, String password, String role) {
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.role = role;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package org.ros.chatto.security;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.ros.chatto.model.ChatUser;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
public class MyUserPrincipal implements UserDetails {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2761445275537412028L;
|
||||
private ChatUser user;
|
||||
|
||||
public MyUserPrincipal(ChatUser user) {
|
||||
super();
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
// TODO Auto-generated method stub
|
||||
return Collections.singleton(new SimpleGrantedAuthority("USER"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
// TODO Auto-generated method stub
|
||||
return user.getPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
// TODO Auto-generated method stub
|
||||
return user.getUserName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
public ChatUser getChatUser()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
@ -19,7 +19,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
|
@ -22,8 +22,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Transactional
|
||||
public class ChatServiceImpl implements ChatService {
|
||||
|
||||
// @Autowired
|
||||
// UserService userService;
|
||||
@Autowired
|
||||
UserRepository userRepository;
|
||||
@Autowired
|
||||
@ -39,11 +37,6 @@ public class ChatServiceImpl implements ChatService {
|
||||
ChatUser fromUser = userRepository.findByUserName(fromUserName);
|
||||
ChatUser toUser = userRepository.findByUserName(toUserName);
|
||||
|
||||
// if(fromUser ==null || toUser == null)
|
||||
// {
|
||||
// System.out.println("User is null");
|
||||
// throw new SQLException();
|
||||
// }
|
||||
ChatMessage chatMessage = new ChatMessage();
|
||||
messageCipher = messageCipherRepository.save(messageCipher);
|
||||
chatMessage.setMessageCipher(messageCipher);
|
||||
|
@ -23,7 +23,10 @@ import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.jdbc.datasource.init.ScriptUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@PropertySource(value = "classpath:queries.properties")
|
||||
|
||||
public class DBInitializerService {
|
||||
@ -65,8 +68,7 @@ public class DBInitializerService {
|
||||
try {
|
||||
populateDB(connection);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
log.error("IO error", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -16,8 +16,6 @@ public class RoleServiceImpl implements RoleService {
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Role getRole(String roleName) {
|
||||
// TODO Auto-generated method stub
|
||||
// Role role = new Role();
|
||||
return roleRepository.findByName(roleName);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface UserService {
|
||||
public void saveChatUser(ChatUser user);
|
||||
public List<String> findAllOtherUsers(String userName);
|
||||
public UserRole registerUser(UserRegistrationDTO userRegistrationDTO);
|
||||
public List<String> getAllRegularUsers();
|
||||
|
@ -13,9 +13,7 @@ import org.ros.chatto.model.ChatUser;
|
||||
import org.ros.chatto.model.Role;
|
||||
import org.ros.chatto.model.UserRole;
|
||||
import org.ros.chatto.model.UserSession;
|
||||
import org.ros.chatto.repository.RoleRepository;
|
||||
import org.ros.chatto.repository.UserRepository;
|
||||
import org.ros.chatto.repository.UserRepositoryCustom;
|
||||
import org.ros.chatto.repository.UserRoleRepository;
|
||||
import org.ros.chatto.repository.UserSessionRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -35,28 +33,13 @@ public class UserServiceImpl implements UserService {
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Autowired
|
||||
private RoleRepository roleRepository;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private UserRepositoryCustom userRepositoryCustom;
|
||||
|
||||
@Autowired
|
||||
private UserSessionRepository userSessionRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public void saveChatUser(ChatUser user) {
|
||||
ChatUser changedUser = userRepository.save(user);
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setRole(roleService.getRole("USER"));
|
||||
userRole.setUser(changedUser);
|
||||
userRoleRepository.save(userRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserRole registerUser(UserRegistrationDTO userRegistrationDTO) {
|
||||
ChatUser user = new ChatUser();
|
||||
|
@ -12,17 +12,13 @@ import { ChatModel } from "./model/ChatModel";
|
||||
import { ChatView } from "./view/ChatView";
|
||||
import { ChatController } from "./controller/ChatController";
|
||||
import { JsonAPI } from "./singleton/JsonAPI";
|
||||
// import log = require('loglevel')
|
||||
import * as log from 'loglevel';
|
||||
// import log from 'loglevel';
|
||||
import { EncryptionService } from "./service/EncryptionService";
|
||||
import { SJCLEncryptionService } from "./service/SJCLEncryptionService";
|
||||
import { MessageCipherDTO } from "./dto/MessageCipherDTO";
|
||||
import { SearchService } from "./service/SearchService";
|
||||
import { FuseSearchService } from "./service/FuseSearchService";
|
||||
import { ChatMessageDTO } from "./dto/ChatMessageDTO";
|
||||
// var markdownit = require('markdown-it');
|
||||
// var md = new markdownit();
|
||||
|
||||
|
||||
const usersListElement = document.getElementById('contacts-box');
|
||||
|
@ -22,7 +22,6 @@ import org.ros.chatto.repository.UserSessionRepository;
|
||||
import org.ros.chatto.service.RoleService;
|
||||
import org.ros.chatto.service.UserService;
|
||||
import org.ros.chatto.service.UserServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
Loading…
Reference in New Issue
Block a user