diff --git a/chatto/src/main/java/org/ros/chatto/captcha/SimpleCaptchaBehavior.java b/chatto/src/main/java/org/ros/chatto/captcha/SimpleCaptchaBehavior.java index f317421..d9d7eb3 100644 --- a/chatto/src/main/java/org/ros/chatto/captcha/SimpleCaptchaBehavior.java +++ b/chatto/src/main/java/org/ros/chatto/captcha/SimpleCaptchaBehavior.java @@ -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(); } diff --git a/chatto/src/main/java/org/ros/chatto/config/CustomCacheEventLogger.java b/chatto/src/main/java/org/ros/chatto/config/CustomCacheEventLogger.java index 2324078..d03f006 100644 --- a/chatto/src/main/java/org/ros/chatto/config/CustomCacheEventLogger.java +++ b/chatto/src/main/java/org/ros/chatto/config/CustomCacheEventLogger.java @@ -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 { diff --git a/chatto/src/main/java/org/ros/chatto/controller/AdminRESTController.java b/chatto/src/main/java/org/ros/chatto/controller/AdminRESTController.java index 4256471..4951e3a 100644 --- a/chatto/src/main/java/org/ros/chatto/controller/AdminRESTController.java +++ b/chatto/src/main/java/org/ros/chatto/controller/AdminRESTController.java @@ -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; diff --git a/chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java b/chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java index e074730..20110f1 100644 --- a/chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java +++ b/chatto/src/main/java/org/ros/chatto/controller/ChatMessageController.java @@ -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 diff --git a/chatto/src/main/java/org/ros/chatto/controller/DemoRestController.java b/chatto/src/main/java/org/ros/chatto/controller/DemoRestController.java index 8881b8f..5c1486f 100644 --- a/chatto/src/main/java/org/ros/chatto/controller/DemoRestController.java +++ b/chatto/src/main/java/org/ros/chatto/controller/DemoRestController.java @@ -92,17 +92,6 @@ public class DemoRestController { return userRoleRepository.getAllRegularUser(); } -// @RequestMapping(value = "/", method = RequestMethod.POST) -// public ResponseEntity update(@RequestBody Car car) { -// -// if (car != null) { -// car.setMiles(car.getMiles() + 100); -// } -// -// // TODO: call persistence layer to update -// return new ResponseEntity(car, HttpStatus.OK); -// } - @PostMapping(value = "/post-message", consumes = { "application/json" }) public ResponseEntity postMessage(@RequestBody MessageCipher messageCipher) { System.out.println("Message cipher = " + messageCipher); diff --git a/chatto/src/main/java/org/ros/chatto/controller/Home.java b/chatto/src/main/java/org/ros/chatto/controller/Home.java index 2e24671..a092b7d 100644 --- a/chatto/src/main/java/org/ros/chatto/controller/Home.java +++ b/chatto/src/main/java/org/ros/chatto/controller/Home.java @@ -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; diff --git a/chatto/src/main/java/org/ros/chatto/logged/MySimpleUrlAuthenticationSuccessHandler.java b/chatto/src/main/java/org/ros/chatto/logged/MySimpleUrlAuthenticationSuccessHandler.java index 388953b..eb879cf 100644 --- a/chatto/src/main/java/org/ros/chatto/logged/MySimpleUrlAuthenticationSuccessHandler.java +++ b/chatto/src/main/java/org/ros/chatto/logged/MySimpleUrlAuthenticationSuccessHandler.java @@ -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; diff --git a/chatto/src/main/java/org/ros/chatto/model/ChatUser.java b/chatto/src/main/java/org/ros/chatto/model/ChatUser.java index a547fc9..2d9ee31 100644 --- a/chatto/src/main/java/org/ros/chatto/model/ChatUser.java +++ b/chatto/src/main/java/org/ros/chatto/model/ChatUser.java @@ -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; diff --git a/chatto/src/main/java/org/ros/chatto/model/MessageCipher.java b/chatto/src/main/java/org/ros/chatto/model/MessageCipher.java index 9b6b61f..be9a8c8 100644 --- a/chatto/src/main/java/org/ros/chatto/model/MessageCipher.java +++ b/chatto/src/main/java/org/ros/chatto/model/MessageCipher.java @@ -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" } diff --git a/chatto/src/main/java/org/ros/chatto/repository/RoleRepository.java b/chatto/src/main/java/org/ros/chatto/repository/RoleRepository.java index c7424dc..4dec770 100644 --- a/chatto/src/main/java/org/ros/chatto/repository/RoleRepository.java +++ b/chatto/src/main/java/org/ros/chatto/repository/RoleRepository.java @@ -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 diff --git a/chatto/src/main/java/org/ros/chatto/repository/UserRepositoryCustomImpl.java b/chatto/src/main/java/org/ros/chatto/repository/UserRepositoryCustomImpl.java index 73fffdf..ddb8a89 100644 --- a/chatto/src/main/java/org/ros/chatto/repository/UserRepositoryCustomImpl.java +++ b/chatto/src/main/java/org/ros/chatto/repository/UserRepositoryCustomImpl.java @@ -35,7 +35,6 @@ class UserRepositoryCustomImpl implements UserRepositoryCustom{ // System.out.println(un); // } } catch (Exception e) { - // TODO: handle exception e.printStackTrace(); } return userNamesList; diff --git a/chatto/src/main/java/org/ros/chatto/security/AuthenticationSuccessHandlerImpl.java b/chatto/src/main/java/org/ros/chatto/security/AuthenticationSuccessHandlerImpl.java index 8ef29bc..3330c53 100644 --- a/chatto/src/main/java/org/ros/chatto/security/AuthenticationSuccessHandlerImpl.java +++ b/chatto/src/main/java/org/ros/chatto/security/AuthenticationSuccessHandlerImpl.java @@ -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 authorities = authentication.getAuthorities(); if (authorities.contains(ADMIN_AUTHORITY) || authorities.contains(SUPER_USER_AUTHORITY)) { redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/admin"); diff --git a/chatto/src/main/java/org/ros/chatto/security/MyUserDetailsService.java b/chatto/src/main/java/org/ros/chatto/security/MyUserDetailsService.java index 386d782..882d9ef 100644 --- a/chatto/src/main/java/org/ros/chatto/security/MyUserDetailsService.java +++ b/chatto/src/main/java/org/ros/chatto/security/MyUserDetailsService.java @@ -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 userRoles = userRoleRepository.findByUser(username); -// @SuppressWarnings("unchecked") -// List userRoles = (List)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; - } - } } \ No newline at end of file diff --git a/chatto/src/main/java/org/ros/chatto/security/MyUserPrincipal.java b/chatto/src/main/java/org/ros/chatto/security/MyUserPrincipal.java deleted file mode 100644 index aed45cc..0000000 --- a/chatto/src/main/java/org/ros/chatto/security/MyUserPrincipal.java +++ /dev/null @@ -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 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; - } - -} diff --git a/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java b/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java index 3442456..d4771b0 100644 --- a/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java +++ b/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java @@ -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; diff --git a/chatto/src/main/java/org/ros/chatto/service/ChatServiceImpl.java b/chatto/src/main/java/org/ros/chatto/service/ChatServiceImpl.java index 98e8153..90573c1 100644 --- a/chatto/src/main/java/org/ros/chatto/service/ChatServiceImpl.java +++ b/chatto/src/main/java/org/ros/chatto/service/ChatServiceImpl.java @@ -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); diff --git a/chatto/src/main/java/org/ros/chatto/service/DBInitializerService.java b/chatto/src/main/java/org/ros/chatto/service/DBInitializerService.java index a3ebbba..6746d32 100644 --- a/chatto/src/main/java/org/ros/chatto/service/DBInitializerService.java +++ b/chatto/src/main/java/org/ros/chatto/service/DBInitializerService.java @@ -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); } } }); diff --git a/chatto/src/main/java/org/ros/chatto/service/RoleServiceImpl.java b/chatto/src/main/java/org/ros/chatto/service/RoleServiceImpl.java index 806acb6..814b8c7 100644 --- a/chatto/src/main/java/org/ros/chatto/service/RoleServiceImpl.java +++ b/chatto/src/main/java/org/ros/chatto/service/RoleServiceImpl.java @@ -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); } diff --git a/chatto/src/main/java/org/ros/chatto/service/UserService.java b/chatto/src/main/java/org/ros/chatto/service/UserService.java index 6785fc2..56a97bc 100644 --- a/chatto/src/main/java/org/ros/chatto/service/UserService.java +++ b/chatto/src/main/java/org/ros/chatto/service/UserService.java @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service; @Service public interface UserService { - public void saveChatUser(ChatUser user); public List findAllOtherUsers(String userName); public UserRole registerUser(UserRegistrationDTO userRegistrationDTO); public List getAllRegularUsers(); diff --git a/chatto/src/main/java/org/ros/chatto/service/UserServiceImpl.java b/chatto/src/main/java/org/ros/chatto/service/UserServiceImpl.java index afd1898..15733cb 100644 --- a/chatto/src/main/java/org/ros/chatto/service/UserServiceImpl.java +++ b/chatto/src/main/java/org/ros/chatto/service/UserServiceImpl.java @@ -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(); diff --git a/chatto/src/main/javascript/ts/src/main.ts b/chatto/src/main/javascript/ts/src/main.ts index d3f85ab..7dac815 100644 --- a/chatto/src/main/javascript/ts/src/main.ts +++ b/chatto/src/main/javascript/ts/src/main.ts @@ -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'); diff --git a/chatto/src/test/java/org/ros/chatto/UnitTest.java b/chatto/src/test/java/org/ros/chatto/UnitTest.java index fb8d443..95791a0 100644 --- a/chatto/src/test/java/org/ros/chatto/UnitTest.java +++ b/chatto/src/test/java/org/ros/chatto/UnitTest.java @@ -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;