Skip to content

Commit

Permalink
Regular version updates of artifacts, fixed some error prone issues, …
Browse files Browse the repository at this point in the history
…cleaned up some parts of the security config to avoid warnings
  • Loading branch information
surajcm committed Dec 31, 2023
1 parent 27cfd1e commit d4fddb6
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 20
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '20'
java-version: '21'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ buildscript {
plugins {
id 'java'
id 'idea'
id 'org.springframework.boot' version '3.1.2'
id 'io.spring.dependency-management' version '1.1.2'
id 'org.springframework.boot' version '3.2.1'
id 'io.spring.dependency-management' version '1.1.3'
id 'net.ltgt.errorprone' version '3.1.0'
id 'com.github.spotbugs' version '5.0.14' apply false
id 'com.github.spotbugs' version '5.2.3' apply false
id 'de.aaschmid.cpd' version '3.3'
id "org.sonarqube" version "4.3.0.3225"
id "org.sonarqube" version "4.4.1.3373"
}

group = 'com.quiz.darkhold'
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home"
export JAVA_OPTS="-Xms512m -Xmx512m"
exec ./gradlew "$@"
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
errorprone("com.google.errorprone:error_prone_core:2.20.0")
errorprone("com.google.errorprone:error_prone_core:2.23.0")
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")

implementation("org.springframework.boot:spring-boot-starter-web")
Expand Down
4 changes: 2 additions & 2 deletions gradle/staticCodeAnalysis.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'jacoco'
//apply plugin: 'com.github.spotbugs'

checkstyle {
toolVersion = '10.12.1'
toolVersion = '10.12.4'
ignoreFailures = false
maxWarnings = 0
checkstyleMain {
Expand All @@ -31,7 +31,7 @@ pmd {
}

jacoco {
toolVersion = "0.8.10"
toolVersion = "0.8.11"
reportsDirectory = file("build/reports/jacoco/")
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -56,7 +55,7 @@ public Long readProcessAndSaveChallenge(final MultipartFile upload,
var challenge = new Challenge();
challenge.setTitle(title);
challenge.setDescription(description);
challenge.setQuestionSets(questionSets);
challenge.setQuestionSets(questionSets.stream().toList());
challenge.setChallengeOwner(currentUserId());
final var savedChallenge = challengeRepository.save(challenge);
questionSets.forEach(q -> q.setChallenge(savedChallenge));
Expand Down Expand Up @@ -84,8 +83,9 @@ private Long currentUserId() {
return user.getId();
}

private List<QuestionSet> readAndProcessChallenge(final MultipartFile upload) throws ChallengeException {
List<QuestionSet> questionSets = new LinkedList<>();
//replace LinkedList with ArrayDeque as the return type
private ArrayDeque<QuestionSet> readAndProcessChallenge(final MultipartFile upload) throws ChallengeException {
ArrayDeque<QuestionSet> questionSets = new ArrayDeque<>();
try (var workbook = new XSSFWorkbook(upload.getInputStream());) {
var datatypeSheet = workbook.getSheetAt(0);
for (Row currentRow : datatypeSheet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String startGame(final Model model, final Principal principal) {
challenge.setQuestionSet(questionPointer.getCurrentQuestion());
challenge.setQuestionNumber(challenge.getQuestionNumber() + 1);
model.addAttribute("challenge", challenge);
model.addAttribute("game_timer", "25");
model.addAttribute("game_timer", "5");
return "game";
}

Expand All @@ -99,6 +99,7 @@ Boolean enterGame(@ModelAttribute("selectedOptions") final String selectedOption
var scoreOnStatus = findScoreOnStatus(status, timeTook);
logger.info("score is {}", scoreOnStatus);
var moderator = gameService.findModerator();
logger.info("is user moderator : {}", user.equalsIgnoreCase(moderator));
if (user.equalsIgnoreCase(moderator)) {
gameService.incrementQuestionNo();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<String> getAllParticipants(final String pin) {
public QuestionPointer getCurrentQuestionPointer() {
var publishInfo = previewService.getActiveChallenge();
var pin = publishInfo.getPin();
logger.info("Current pin is ");
logger.info("Current pin is {}", pin);
return currentGame.getCurrentQuestionPointer(pin);
}

Expand All @@ -68,6 +68,7 @@ public String findModerator() {

public Map<String, Integer> getCurrentScore() {
var pin = currentPin();
logger.info("current pin is {}", pin);
return currentGame.getCurrentScore(pin);
}

Expand Down
38 changes: 17 additions & 21 deletions src/main/java/com/quiz/darkhold/init/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,37 @@ public static BCryptPasswordEncoder passwordEncoder() {

@Bean
public SecurityFilterChain filterChain(final HttpSecurity http,
final HandlerMappingIntrospector introspector) throws Exception {
final HandlerMappingIntrospector introspect) throws Exception {
//todo : we need to enable CSRF
http.csrf(AbstractHttpConfigurer::disable);
MvcRequestMatcher.Builder mvcMatcherBuilder = new MvcRequestMatcher.Builder(introspector);
for (var paths: matchingPaths()) {
MvcRequestMatcher.Builder mvcMatcherBuilder = new MvcRequestMatcher.Builder(introspect);
for (var paths : matchingPaths()) {
http.authorizeHttpRequests(auth -> auth
.requestMatchers(mvcMatcherBuilder.pattern(paths)).permitAll()
);
}
http.authorizeHttpRequests(auth -> auth.anyRequest().authenticated());
http.formLogin(
(formLogin) -> {
try {
formLogin
//.loginPage("/authenticate")
.defaultSuccessUrl("/", true)
.permitAll()
.and()
.logout((logout) -> logout.logoutSuccessUrl("/")
.invalidateHttpSession(true)
.clearAuthentication(true)
.deleteCookies("JSESSIONID"));
} catch (Exception ex) {
//todo : clean up
throw new RuntimeException(ex);
}
});
http.formLogin((formLogin) -> {
try {
formLogin.defaultSuccessUrl("/", true).permitAll();
} catch (Exception ex) {
//todo : clean up
throw new RuntimeException(ex);
}
});
http.logout((logout) -> logout.logoutSuccessUrl("/")
.invalidateHttpSession(true)
.clearAuthentication(true)
.deleteCookies("JSESSIONID"));

http.headers(
(header) -> header.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin)
);
return http.build();
}

private String[] matchingPaths() {
return new String[] {"/", "/logmein" ,
return new String[]{"/", "/logmein",
"/home", "/resources/**",
"/registration", "/images/**",
"/scripts/**", "/styles/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.quiz.darkhold.challenge.entity.QuestionSet;

import java.util.List;
import java.util.ArrayDeque;

public class PreviewInfo {
private String challengeId;
private String challengeName;
private List<QuestionSet> questionSets;
private ArrayDeque<QuestionSet> questionSets;

public String getChallengeId() {
return challengeId;
Expand All @@ -25,11 +25,11 @@ public void setChallengeName(final String challengeName) {
this.challengeName = challengeName;
}

public List<QuestionSet> getQuestionSets() {
public ArrayDeque<QuestionSet> getQuestionSets() {
return questionSets;
}

public void setQuestionSets(final List<QuestionSet> questionSets) {
public void setQuestionSets(final ArrayDeque<QuestionSet> questionSets) {
this.questionSets = questionSets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -37,7 +38,7 @@ public class CurrentGame {
*
* @param publishInfo publish info
*/
public void saveCurrentStatus(final PublishInfo publishInfo, final List<QuestionSet> questionSets) {
public void saveCurrentStatus(final PublishInfo publishInfo, final ArrayDeque<QuestionSet> questionSets) {
List<String> users = new ArrayList<>();
users.add(publishInfo.getModerator());
// table contents
Expand Down Expand Up @@ -177,7 +178,7 @@ public QuestionPointer getCurrentQuestionPointer(final String pin) {
var doc = cursor.toList().get(0);
var questionNo = (Integer) doc.get(CURRENT_QUESTION_NO);
logger.info("questionNo : {}", questionNo);
var questions = (List<QuestionSet>) doc.get(QUESTIONS);
var questions = ((ArrayDeque<QuestionSet>) doc.get(QUESTIONS)).stream().toList();
logger.info("questions size : {}}", questions.size());
var questionPointer = new QuestionPointer();
questionPointer.setCurrentQuestionNumber(questionNo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayDeque;

@Service
public class PreviewService {

Expand Down Expand Up @@ -37,7 +39,9 @@ public PreviewInfo fetchQuestions(final String challengeId) {
var previewInfo = new PreviewInfo();
var challengeOne = Long.valueOf(challengeId);
var challenge = challengeRepository.getById(challengeOne);
previewInfo.setQuestionSets(challenge.getQuestionSets());
// convert challenge to type ArrayDeque<QuestionSet>
var dequeChallenge = new ArrayDeque<>(challenge.getQuestionSets());;
previewInfo.setQuestionSets(dequeChallenge);
previewInfo.setChallengeName(challenge.getTitle());
previewInfo.setChallengeId(challengeId);
return previewInfo;
Expand All @@ -55,7 +59,7 @@ public PreviewInfo fetchQuestionsFromPin(final String pin) {
var previewInfo = new PreviewInfo();
var challengeOne = Long.valueOf(challengeId);
var challenge = challengeRepository.findById(challengeOne);
challenge.ifPresent(value -> previewInfo.setQuestionSets(value.getQuestionSets()));
challenge.ifPresent(value -> previewInfo.setQuestionSets(new ArrayDeque<>(value.getQuestionSets())));
challenge.ifPresent(value -> previewInfo.setChallengeName(value.getTitle()));
previewInfo.setChallengeId(challengeId);
return previewInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public String scoreCheck(final Model model) {
logger.info("On to the scoreboard screen");
var score = new CurrentScore();
var scores = gameService.getCurrentScore();
logger.info("Total uses are {}", scores.size());
scores.forEach((key, value) ->
logger.info(new StringBuilder()
.append("key is:").append(key)
.append(", and value is :").append(value).toString()));
logger.info("key is:" + key +
", and value is :" + value));
score.setScore(scores);
model.addAttribute("score", score);
return "scoreboard";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.powermock.reflect.Whitebox;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -33,7 +34,7 @@ void saveCurrentStatus() {
var publishInfo = new PublishInfo();
publishInfo.setPin("1234");
publishInfo.setModerator("admin");
Assertions.assertAll(() -> currentGame.saveCurrentStatus(publishInfo, new ArrayList<>()));
Assertions.assertAll(() -> currentGame.saveCurrentStatus(publishInfo, new ArrayDeque<>()));
}

@Test
Expand Down

0 comments on commit d4fddb6

Please sign in to comment.