added formatter plugin
This commit is contained in:
parent
ced84a05a6
commit
af4181185c
1
.gitignore
vendored
1
.gitignore
vendored
@ -29,6 +29,7 @@ build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
.cache/
|
||||
|
||||
node_modules
|
||||
bundle.js
|
||||
|
11
pom.xml
11
pom.xml
@ -223,6 +223,17 @@
|
||||
</excludeProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.revelc.code.formatter</groupId>
|
||||
<artifactId>formatter-maven-plugin</artifactId>
|
||||
<version>2.12.0</version>
|
||||
<configuration>
|
||||
<configFile>${project.basedir}/eclipse-formatter.xml</configFile>
|
||||
<compilerSource>11</compilerSource>
|
||||
<compilerCompliance>11</compilerCompliance>
|
||||
<compilerTargetPlatform>11</compilerTargetPlatform>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -28,8 +28,10 @@ public class V3__add_default_admin extends BaseJavaMigration {
|
||||
/**
|
||||
* Method will generate random string based on the parameters
|
||||
*
|
||||
* @param len the length of the random string
|
||||
* @param dic the dictionary used to generate the password
|
||||
* @param len
|
||||
* the length of the random string
|
||||
* @param dic
|
||||
* the dictionary used to generate the password
|
||||
* @return the random password
|
||||
*/
|
||||
public String generatePassword(int len, String dic) {
|
||||
@ -44,8 +46,10 @@ public class V3__add_default_admin extends BaseJavaMigration {
|
||||
@Override
|
||||
public void migrate(final Context context) throws Exception {
|
||||
try (final PreparedStatement ps = context.getConnection()
|
||||
.prepareStatement("insert into users (user_id, name, password) values (0,?,?)")) {
|
||||
final String generatedPassword = generatePassword(60, ALPHA_CAPS + ALPHA + SPECIAL_CHARS);
|
||||
.prepareStatement(
|
||||
"insert into users (user_id, name, password) values (0,?,?)")) {
|
||||
final String generatedPassword = generatePassword(60,
|
||||
ALPHA_CAPS + ALPHA + SPECIAL_CHARS);
|
||||
final BufferedWriter bw = new BufferedWriter(
|
||||
new FileWriter("gen-password.txt"));
|
||||
|
||||
@ -53,9 +57,8 @@ public class V3__add_default_admin extends BaseJavaMigration {
|
||||
bw.write("\nPlease delete this file");
|
||||
bw.close();
|
||||
|
||||
final var perms = Files.getPosixFilePermissions(Paths.get(
|
||||
"gen-password.txt"));
|
||||
|
||||
final var perms = Files
|
||||
.getPosixFilePermissions(Paths.get("gen-password.txt"));
|
||||
|
||||
// add owners permission
|
||||
perms.add(PosixFilePermission.OWNER_READ);
|
||||
@ -71,14 +74,14 @@ public class V3__add_default_admin extends BaseJavaMigration {
|
||||
perms.remove(PosixFilePermission.OTHERS_EXECUTE);
|
||||
Files.setPosixFilePermissions(Paths.get("gen-password.txt"), perms);
|
||||
|
||||
|
||||
ps.setString(1, "admin");
|
||||
ps.setString(2, passwordEncoder.encode(generatedPassword));
|
||||
ps.execute();
|
||||
}
|
||||
|
||||
try (final PreparedStatement ps = context.getConnection()
|
||||
.prepareStatement("insert into users_roles (user_id, role_id) values (1,0)")) {
|
||||
.prepareStatement(
|
||||
"insert into users_roles (user_id, role_id) values (1,0)")) {
|
||||
ps.execute();
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,12 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationEn
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public final class RESTAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
|
||||
public final class RESTAuthenticationEntryPoint
|
||||
extends BasicAuthenticationEntryPoint {
|
||||
|
||||
@Override
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
|
||||
public void commence(HttpServletRequest request,
|
||||
HttpServletResponse response, AuthenticationException authEx)
|
||||
throws IOException, ServletException {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
PrintWriter writer = response.getWriter();
|
||||
|
@ -6,7 +6,8 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
protected SpringApplicationBuilder configure(
|
||||
SpringApplicationBuilder application) {
|
||||
return application.sources(ChattoApplication.class);
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,8 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/api/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("POST","GET","OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
registry.addMapping("/api/**").allowedOrigins("*")
|
||||
.allowedMethods("POST", "GET", "OPTIONS").allowedHeaders("*")
|
||||
.allowCredentials(false).maxAge(3600);
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ import java.awt.image.BufferedImage;
|
||||
|
||||
interface CaptchaBehaviour {
|
||||
public BufferedImage generateCaptcha();
|
||||
|
||||
public BufferedImage generateCaptcha(String captchaText);
|
||||
|
||||
public String getRandomChars(int size);
|
||||
|
||||
public String getRandomChars();
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import lombok.Builder;
|
||||
public class ManualCaptchaBehaviour implements CaptchaBehaviour {
|
||||
private final int length;
|
||||
private final String style;
|
||||
|
||||
@Override
|
||||
public BufferedImage generateCaptcha() {
|
||||
// TODO Auto-generated method stub
|
||||
@ -33,5 +34,4 @@ public class ManualCaptchaBehaviour implements CaptchaBehaviour{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -10,10 +10,8 @@ import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This class represents a simple captcha consisting
|
||||
* of an image {@code png} and its text value.
|
||||
* Comic Neue Bold Font.
|
||||
* Capital english letters {@code ONLY}.
|
||||
* This class represents a simple captcha consisting of an image {@code png} and
|
||||
* its text value. Comic Neue Bold Font. Capital english letters {@code ONLY}.
|
||||
*
|
||||
* @since 1.3
|
||||
* @author Gennadiy Golovin
|
||||
@ -24,8 +22,8 @@ public final class SimpleCaptcha {
|
||||
private char[] text;
|
||||
|
||||
/**
|
||||
* Initializes a newly created default object
|
||||
* consisting of 8 capital english letters.
|
||||
* Initializes a newly created default object consisting of 8 capital
|
||||
* english letters.
|
||||
*/
|
||||
public SimpleCaptcha() {
|
||||
this.text = getRandomChars();
|
||||
@ -38,14 +36,14 @@ public final class SimpleCaptcha {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a newly created object, which length
|
||||
* depends on the passed {@code int} parameter,
|
||||
* which {@code MUST} be greater than 0.
|
||||
* If the condition is not met, initializes a newly
|
||||
* created default object consisting of 8 symbols.
|
||||
* Initializes a newly created object, which length depends on the passed
|
||||
* {@code int} parameter, which {@code MUST} be greater than 0. If the
|
||||
* condition is not met, initializes a newly created default object
|
||||
* consisting of 8 symbols.
|
||||
*
|
||||
* @param length the quantity of symbols, that the
|
||||
* captcha consists of, greater than 0.
|
||||
* @param length
|
||||
* the quantity of symbols, that the captcha consists of, greater
|
||||
* than 0.
|
||||
*/
|
||||
public SimpleCaptcha(int length) {
|
||||
if (length < 1) {
|
||||
@ -62,13 +60,14 @@ public final class SimpleCaptcha {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a newly created object based on the passed
|
||||
* {@link String} parameter, consisting of capital english
|
||||
* letters. If the condition is not met, initializes a newly
|
||||
* created default object consisting of 8 capital english letters.
|
||||
* Initializes a newly created object based on the passed {@link String}
|
||||
* parameter, consisting of capital english letters. If the condition is not
|
||||
* met, initializes a newly created default object consisting of 8 capital
|
||||
* english letters.
|
||||
*
|
||||
* @param text the text string with the value of the captcha,
|
||||
* length greater than 0.
|
||||
* @param text
|
||||
* the text string with the value of the captcha, length greater
|
||||
* than 0.
|
||||
*/
|
||||
public SimpleCaptcha(String text) {
|
||||
if (text == null || text.equals("")) {
|
||||
@ -134,7 +133,8 @@ public final class SimpleCaptcha {
|
||||
BufferedImage[] images = new BufferedImage[charsQuantity];
|
||||
|
||||
for (int i = 0; i < charsQuantity; i++) {
|
||||
images[i] = ImageIO.read(SimpleCaptcha.class.getResourceAsStream("/pictures/" + this.text[i] + ".png"));
|
||||
images[i] = ImageIO.read(SimpleCaptcha.class
|
||||
.getResourceAsStream("/pictures/" + this.text[i] + ".png"));
|
||||
if (i % 2 == 0) {
|
||||
images[i] = rotateImage(images[i], 25);
|
||||
} else {
|
||||
@ -145,12 +145,17 @@ public final class SimpleCaptcha {
|
||||
int imageSize = 30;
|
||||
int rotatedImageSize = (int) Math.sqrt(imageSize * imageSize * 2);
|
||||
|
||||
BufferedImage captchaImg = new BufferedImage(rotatedImageSize * (charsQuantity - 1) / 10 * 6 + rotatedImageSize, rotatedImageSize, BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage captchaImg = new BufferedImage(
|
||||
rotatedImageSize * (charsQuantity - 1) / 10 * 6
|
||||
+ rotatedImageSize,
|
||||
rotatedImageSize, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D graphics2d = captchaImg.createGraphics();
|
||||
graphics2d.setBackground(Color.WHITE);
|
||||
graphics2d.clearRect(0, 0, captchaImg.getWidth(), captchaImg.getHeight());
|
||||
graphics2d.clearRect(0, 0, captchaImg.getWidth(),
|
||||
captchaImg.getHeight());
|
||||
for (int i = 0; i < charsQuantity; i++) {
|
||||
captchaImg.getGraphics().drawImage(images[i], rotatedImageSize * i / 10 * 6, 0, null);
|
||||
captchaImg.getGraphics().drawImage(images[i],
|
||||
rotatedImageSize * i / 10 * 6, 0, null);
|
||||
}
|
||||
graphics2d.dispose();
|
||||
this.imagePng = captchaImg;
|
||||
@ -165,14 +170,18 @@ public final class SimpleCaptcha {
|
||||
int width = buffImage.getWidth();
|
||||
int height = buffImage.getHeight();
|
||||
|
||||
int nWidth = (int) Math.floor((double) width * cos + (double) height * sin);
|
||||
int nHeight = (int) Math.floor((double) height * cos + (double) width * sin);
|
||||
int nWidth = (int) Math
|
||||
.floor((double) width * cos + (double) height * sin);
|
||||
int nHeight = (int) Math
|
||||
.floor((double) height * cos + (double) width * sin);
|
||||
|
||||
BufferedImage rotatedImage = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage rotatedImage = new BufferedImage(nWidth, nHeight,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
Graphics2D graphics = rotatedImage.createGraphics();
|
||||
|
||||
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||
graphics.translate((nWidth - width) / 2, (nHeight - height) / 2);
|
||||
graphics.rotate(radian, (double) (width / 2), (double) (height / 2));
|
||||
graphics.drawImage(buffImage, 0, 0, null);
|
||||
|
@ -9,6 +9,7 @@ public class SimpleCaptchaBehavior implements CaptchaBehaviour {
|
||||
SimpleCaptcha simpleCaptcha = new SimpleCaptcha();
|
||||
return simpleCaptcha.getImagePng();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage generateCaptcha(String captchaText) {
|
||||
SimpleCaptcha simpleCaptcha = new SimpleCaptcha(captchaText);
|
||||
@ -19,8 +20,7 @@ public class SimpleCaptchaBehavior implements CaptchaBehaviour {
|
||||
return getRandomChars(8);
|
||||
}
|
||||
|
||||
public String getRandomChars(int quantity)
|
||||
{
|
||||
public String getRandomChars(int quantity) {
|
||||
char[] randomString = new char[quantity];
|
||||
|
||||
Random random = new Random();
|
||||
|
@ -25,7 +25,8 @@ public class WebCaptcha {
|
||||
}
|
||||
}
|
||||
|
||||
// WebCaptcha webCaptcha = WebCaptcha.builder().captchaBehaviour(new SimpleCaptchaBehavior()).build();
|
||||
// WebCaptcha webCaptcha = WebCaptcha.builder().captchaBehaviour(new
|
||||
// SimpleCaptchaBehavior()).build();
|
||||
// webCaptcha.generateCaptcha();
|
||||
//
|
||||
// // @formatter:off
|
||||
|
@ -6,11 +6,14 @@ import org.ehcache.event.CacheEventListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class CustomCacheEventLogger implements CacheEventListener<Object, Object> {
|
||||
public class CustomCacheEventLogger
|
||||
implements CacheEventListener<Object, Object> {
|
||||
|
||||
@Override
|
||||
public void onEvent(CacheEvent<? extends Object, ? extends Object> cacheEvent) {
|
||||
log.debug("custom Caching event {} key = {} old {} new {} ", cacheEvent.getType(), cacheEvent.getKey(),
|
||||
public void onEvent(
|
||||
CacheEvent<? extends Object, ? extends Object> cacheEvent) {
|
||||
log.debug("custom Caching event {} key = {} old {} new {} ",
|
||||
cacheEvent.getType(), cacheEvent.getKey(),
|
||||
cacheEvent.getOldValue(), cacheEvent.getNewValue());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.ros.chatto.config;
|
||||
|
||||
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
@ -89,8 +89,8 @@ public class ChatMessageController {
|
||||
@PathVariable final String userName,
|
||||
@PathVariable final Instant lastMessageTime,
|
||||
final Principal principal) {
|
||||
final List<ChatMessageDTO> chatMessageDTOs = chatService.getNewMessages(
|
||||
principal.getName(), userName, lastMessageTime);
|
||||
final List<ChatMessageDTO> chatMessageDTOs = chatService
|
||||
.getNewMessages(principal.getName(), userName, lastMessageTime);
|
||||
return chatMessageDTOs;
|
||||
}
|
||||
|
||||
|
14
src/main/java/org/ros/chatto/controller/CsrfController.java
Normal file
14
src/main/java/org/ros/chatto/controller/CsrfController.java
Normal file
@ -0,0 +1,14 @@
|
||||
package org.ros.chatto.controller;
|
||||
|
||||
import org.springframework.security.web.csrf.CsrfToken;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class CsrfController {
|
||||
|
||||
@RequestMapping("/csrf")
|
||||
public CsrfToken csrf(CsrfToken token) {
|
||||
return token;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package org.ros.chatto.dto;
|
||||
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
@ -12,7 +12,9 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MessageCipherDTO {
|
||||
@Pattern(regexp = "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$") // regex for base64
|
||||
@Pattern(regexp = "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$") // regex
|
||||
// for
|
||||
// base64
|
||||
@NotBlank
|
||||
private String iv;
|
||||
@Max(1)
|
||||
|
@ -16,7 +16,9 @@ public class UserRegistrationDTO {
|
||||
@Transient
|
||||
@Size(min = 4, max = 75, message = "Password must be between 4 and 75 characters")
|
||||
@NotBlank(message = "Password should not be blank")
|
||||
// @Pattern(regexp = "^.*(?=.{6,})(?=.*d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$", message = "Invalid password format")
|
||||
// @Pattern(regexp =
|
||||
// "^.*(?=.{6,})(?=.*d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$", message
|
||||
// = "Invalid password format")
|
||||
private String password;
|
||||
|
||||
private Long captchaID;
|
||||
|
@ -17,5 +17,4 @@ public class ErrorModel{
|
||||
@JsonProperty("error_message")
|
||||
private String messageError;
|
||||
|
||||
|
||||
}
|
@ -4,5 +4,6 @@ import org.springframework.cache.annotation.CacheEvict;
|
||||
|
||||
public class TokenCacheUtil {
|
||||
@CacheEvict(value = "userTokenCache", key = "#cacheKey")
|
||||
public static void evictSingleTokenValue(String cacheKey) {}
|
||||
public static void evictSingleTokenValue(String cacheKey) {
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ public class UserLoggingSessionListener implements HttpSessionBindingListener {
|
||||
@Override
|
||||
public void valueBound(HttpSessionBindingEvent event) {
|
||||
|
||||
UserLoggingSessionListener user = (UserLoggingSessionListener) event.getValue();
|
||||
UserLoggingSessionListener user = (UserLoggingSessionListener) event
|
||||
.getValue();
|
||||
|
||||
log.debug("Incrementing session count for user {}", user.getUsername());
|
||||
|
||||
@ -38,7 +39,8 @@ public class UserLoggingSessionListener implements HttpSessionBindingListener {
|
||||
|
||||
@Override
|
||||
public void valueUnbound(HttpSessionBindingEvent event) {
|
||||
UserLoggingSessionListener user = (UserLoggingSessionListener) event.getValue();
|
||||
UserLoggingSessionListener user = (UserLoggingSessionListener) event
|
||||
.getValue();
|
||||
|
||||
log.debug("Decrementing session count for user {}", user.getUsername());
|
||||
|
||||
|
@ -11,7 +11,8 @@ import org.springframework.security.web.authentication.AuthenticationSuccessHand
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("myAuthenticationSuccessHandler")
|
||||
public class UserSessionLoggingLoginSuccessHandler implements AuthenticationSuccessHandler {
|
||||
public class UserSessionLoggingLoginSuccessHandler
|
||||
implements AuthenticationSuccessHandler {
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest request,
|
||||
@ -19,7 +20,8 @@ public class UserSessionLoggingLoginSuccessHandler implements AuthenticationSucc
|
||||
throws IOException {
|
||||
HttpSession session = request.getSession(false);
|
||||
if (session != null) {
|
||||
UserLoggingSessionListener user = new UserLoggingSessionListener(authentication.getName());
|
||||
UserLoggingSessionListener user = new UserLoggingSessionListener(
|
||||
authentication.getName());
|
||||
session.setAttribute("user", user);
|
||||
}
|
||||
response.sendRedirect("/chat");
|
||||
|
@ -12,7 +12,8 @@ import org.springframework.security.web.authentication.logout.LogoutSuccessHandl
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("myLogoutSuccessHandler")
|
||||
public class UserSessionLoggingLogoutSuccessHandler implements LogoutSuccessHandler{
|
||||
public class UserSessionLoggingLogoutSuccessHandler
|
||||
implements LogoutSuccessHandler {
|
||||
@Override
|
||||
public void onLogoutSuccess(HttpServletRequest request,
|
||||
HttpServletResponse response, Authentication authentication)
|
||||
|
@ -16,7 +16,6 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(name = "roles")
|
||||
@Data
|
||||
@ -30,8 +29,8 @@ public class Role {
|
||||
|
||||
private String description;
|
||||
|
||||
@OneToMany(mappedBy = "role", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH,
|
||||
CascadeType.REFRESH })
|
||||
@OneToMany(mappedBy = "role", cascade = { CascadeType.PERSIST,
|
||||
CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH })
|
||||
@JsonBackReference
|
||||
@ToString.Exclude
|
||||
@EqualsAndHashCode.Exclude
|
||||
|
@ -4,6 +4,7 @@
|
||||
// import org.springframework.stereotype.Repository;
|
||||
//
|
||||
// @Repository
|
||||
//public interface DBInitializerRepostory extends JpaRepository<Integer, Integer>{
|
||||
// public interface DBInitializerRepostory extends JpaRepository<Integer,
|
||||
// Integer>{
|
||||
//
|
||||
// }
|
||||
|
@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface MessageCipherRepository extends JpaRepository<MessageCipher, Long>{
|
||||
public interface MessageCipherRepository
|
||||
extends JpaRepository<MessageCipher, Long> {
|
||||
|
||||
}
|
||||
|
@ -23,13 +23,17 @@ class UserRepositoryCustomImpl implements UserRepositoryCustom{
|
||||
List<String> userNamesList = null;
|
||||
// Session session = null;
|
||||
try {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<String> criteriaQuery = criteriaBuilder.createQuery(String.class);
|
||||
CriteriaBuilder criteriaBuilder = entityManager
|
||||
.getCriteriaBuilder();
|
||||
CriteriaQuery<String> criteriaQuery = criteriaBuilder
|
||||
.createQuery(String.class);
|
||||
Root<ChatUser> root = criteriaQuery.from(ChatUser.class);
|
||||
criteriaQuery.select(root.get("userName"));
|
||||
criteriaQuery.where(criteriaBuilder.notEqual(root.get("userName"), userName));
|
||||
criteriaQuery.where(
|
||||
criteriaBuilder.notEqual(root.get("userName"), userName));
|
||||
|
||||
userNamesList = entityManager.createQuery(criteriaQuery).getResultList();
|
||||
userNamesList = entityManager.createQuery(criteriaQuery)
|
||||
.getResultList();
|
||||
// for(String un: userNamesList)
|
||||
// {
|
||||
// System.out.println(un);
|
||||
|
@ -16,20 +16,29 @@ import org.springframework.security.web.authentication.AuthenticationSuccessHand
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHandler {
|
||||
public class AuthenticationSuccessHandlerImpl
|
||||
implements AuthenticationSuccessHandler {
|
||||
|
||||
private static final SimpleGrantedAuthority SUPER_USER_AUTHORITY = new SimpleGrantedAuthority("ROLE_SUPER_USER");
|
||||
private static final SimpleGrantedAuthority ADMIN_AUTHORITY = new SimpleGrantedAuthority("ROLE_ADMIN");
|
||||
private static final SimpleGrantedAuthority SUPER_USER_AUTHORITY = new SimpleGrantedAuthority(
|
||||
"ROLE_SUPER_USER");
|
||||
private static final SimpleGrantedAuthority ADMIN_AUTHORITY = new SimpleGrantedAuthority(
|
||||
"ROLE_ADMIN");
|
||||
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
|
||||
Authentication authentication) throws IOException, ServletException {
|
||||
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
|
||||
if (authorities.contains(ADMIN_AUTHORITY) || authorities.contains(SUPER_USER_AUTHORITY)) {
|
||||
redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/admin");
|
||||
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse,
|
||||
Authentication authentication)
|
||||
throws IOException, ServletException {
|
||||
Collection<? extends GrantedAuthority> authorities = authentication
|
||||
.getAuthorities();
|
||||
if (authorities.contains(ADMIN_AUTHORITY)
|
||||
|| authorities.contains(SUPER_USER_AUTHORITY)) {
|
||||
redirectStrategy.sendRedirect(httpServletRequest,
|
||||
httpServletResponse, "/admin");
|
||||
} else {
|
||||
redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/user");
|
||||
redirectStrategy.sendRedirect(httpServletRequest,
|
||||
httpServletResponse, "/user");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,16 +11,15 @@ public class CaptchaService {
|
||||
private final WebCaptcha webCaptcha;
|
||||
|
||||
public CaptchaService() {
|
||||
webCaptcha = WebCaptcha.builder().captchaBehaviour(new SimpleCaptchaBehavior()).build();
|
||||
webCaptcha = WebCaptcha.builder()
|
||||
.captchaBehaviour(new SimpleCaptchaBehavior()).build();
|
||||
}
|
||||
|
||||
public BufferedImage createCaptchaImage(final String captchaText)
|
||||
{
|
||||
public BufferedImage createCaptchaImage(final String captchaText) {
|
||||
return webCaptcha.generateCaptcha(captchaText);
|
||||
}
|
||||
|
||||
public String getRandomText()
|
||||
{
|
||||
public String getRandomText() {
|
||||
return webCaptcha.getRandomChars();
|
||||
}
|
||||
}
|
||||
|
@ -46,13 +46,15 @@ public class DBInitializerService {
|
||||
});
|
||||
}
|
||||
|
||||
private void resetAllUserSessions(final Connection connection) throws SQLException {
|
||||
private void resetAllUserSessions(final Connection connection)
|
||||
throws SQLException {
|
||||
final PreparedStatement preparedStatement = connection
|
||||
.prepareStatement(dbInitializerConfig.getResetSessionsQuery());
|
||||
preparedStatement.executeUpdate();
|
||||
}
|
||||
|
||||
private void clearAllTokens(final Connection connection) throws SQLException {
|
||||
private void clearAllTokens(final Connection connection)
|
||||
throws SQLException {
|
||||
final PreparedStatement preparedStatement = connection
|
||||
.prepareStatement(dbInitializerConfig.getClearTokensQuery());
|
||||
preparedStatement.executeUpdate();
|
||||
|
@ -28,7 +28,8 @@
|
||||
// @Autowired
|
||||
// private UserRoleRepository userRoleRepository;
|
||||
|
||||
// private final Logger logger = LoggerFactory.getLogger(ChattoApplicationTests.class);
|
||||
// private final Logger logger =
|
||||
// LoggerFactory.getLogger(ChattoApplicationTests.class);
|
||||
// //
|
||||
// @Test
|
||||
// public void contextLoads() {
|
||||
@ -47,7 +48,8 @@
|
||||
|
||||
// @Test
|
||||
// public void findAllOtherUsers() {
|
||||
// logger.info("Usernames = {}",userRepository.findAllOtherUserNames("hmm").toString());
|
||||
// logger.info("Usernames =
|
||||
// {}",userRepository.findAllOtherUserNames("hmm").toString());
|
||||
// }
|
||||
|
||||
// // @Test
|
||||
@ -65,7 +67,8 @@
|
||||
// // }
|
||||
|
||||
// /*
|
||||
// * @Test public void testSave() { ChatUser fromUser = new ChatUser(); fromUser =
|
||||
// * @Test public void testSave() { ChatUser fromUser = new ChatUser(); fromUser
|
||||
// =
|
||||
// * userRepository.findByUserName("hmm"); ChatUser toUser = new ChatUser();
|
||||
// * toUser = userRepository.findByUserName("user2"); ChatMessage chatMessage =
|
||||
// * new ChatMessage(); chatMessage.setMessage("Hello!");
|
||||
|
@ -55,7 +55,8 @@
|
||||
// @Mock
|
||||
// private UserRepository userRepository;
|
||||
|
||||
// private UserService userService = new UserServiceImpl(userRepository, userRoleRepository, passwordEncoder, roleRepository,
|
||||
// private UserService userService = new UserServiceImpl(userRepository,
|
||||
// userRoleRepository, passwordEncoder, roleRepository,
|
||||
// userSessionRepository);
|
||||
// // private ChatUser chatUser;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user