Koblížkáč
Koblížkáč
Explore posts from servers
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 11/17/2024 in #java-help
Spring sessions with Redis
Hi, I have these 2 endpoints:
@GetMapping("/signin")
public ResponseEntity<String> signIn(@RequestParam String username, @RequestParam String password) {
var auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
SecurityContextHolder.getContext().setAuthentication(auth);
return ResponseEntity.ok("Done");
}

@GetMapping("/signup")
public ResponseEntity<Boolean> check() {
var authentication = SecurityContextHolder.getContext().getAuthentication();
return ResponseEntity.ok(authentication != null && authentication.isAuthenticated());
}
@GetMapping("/signin")
public ResponseEntity<String> signIn(@RequestParam String username, @RequestParam String password) {
var auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
SecurityContextHolder.getContext().setAuthentication(auth);
return ResponseEntity.ok("Done");
}

@GetMapping("/signup")
public ResponseEntity<Boolean> check() {
var authentication = SecurityContextHolder.getContext().getAuthentication();
return ResponseEntity.ok(authentication != null && authentication.isAuthenticated());
}
but when i try the second one after the first one, it always returns false. why? auth.isAuthenticated() is true when debugged
4 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 8/15/2024 in #java-help
Adding post and then fetching doesn't work in spring
No description
62 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 8/8/2024 in #java-help
JavaParser help
Does anyone know how to return the index of character starting a token?
7 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 8/4/2024 in #java-help
Funny thing happening in JavaFX
No description
4 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 7/30/2024 in #java-help
How to make spring boot @Value fields inject the values from properties?
No description
31 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 7/30/2024 in #java-help
Drawing SVG paths in javafx css
No description
4 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 7/18/2024 in #java-help
Mocking fails for some reason
@SpringBootTest
@TestPropertySource(locations = "classpath:application-test.properties")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
class UserServiceTests {

User testUser = new User(
1L,
"xxxJohnxxx",
"John Doe",
"Password123"
);

@Mock
UserRepository userRepository;

@Autowired
@InjectMocks
UserService userService;

@BeforeEach
void setUp() {
when(userRepository.findById(1L)).thenReturn(Optional.of(testUser));
when(userRepository.findById(2L)).thenReturn(Optional.empty());
}

@Test
void testFindUserById() {
assertThat(userService.findUserById(1L)).isNotEmpty().hasValueSatisfying(usr -> {
assertThat(usr.getUsername()).isEqualTo("xxxJohnxxx");
});
assertThat(userService.findUserById(2L)).isEmpty();
}
}
@SpringBootTest
@TestPropertySource(locations = "classpath:application-test.properties")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
class UserServiceTests {

User testUser = new User(
1L,
"xxxJohnxxx",
"John Doe",
"Password123"
);

@Mock
UserRepository userRepository;

@Autowired
@InjectMocks
UserService userService;

@BeforeEach
void setUp() {
when(userRepository.findById(1L)).thenReturn(Optional.of(testUser));
when(userRepository.findById(2L)).thenReturn(Optional.empty());
}

@Test
void testFindUserById() {
assertThat(userService.findUserById(1L)).isNotEmpty().hasValueSatisfying(usr -> {
assertThat(usr.getUsername()).isEqualTo("xxxJohnxxx");
});
assertThat(userService.findUserById(2L)).isEmpty();
}
}
userService.findUserById(1L) fails and returns empty optional, any idea why?
142 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 7/17/2024 in #java-help
Failing test under misterious circumstances
https://github.com/KoblizekXD/notecz-backend/blob/4a70434b5c139b2d6bf5c6953fbf49a92cebded5/src/test/java/lol/koblizek/notecz/api/user/UserServiceTests.java#L49 this test seems to be failing, altough when i try to run UserRepositoryTests and test the validation, it correctly throws an exception, but here the saveAndFlush just returns null...
5 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 7/3/2024 in #java-help
What do y'all use for frontend with spring?
Which framework/stuff do you use? i wanted to use nextjs but people told me its overkill because its already a fullstack framework
12 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 7/1/2024 in #java-help
Styling tabpane in javafx
No description
6 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 6/25/2024 in #java-help
Jackson ignores private fields
class POJO {
private int i;

@JsonIgnore
public int getI() {
return i + 1;
}
}
class POJO {
private int i;

@JsonIgnore
public int getI() {
return i + 1;
}
}
this way the field i is completely ignored, can i somehow include it? tried mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); but that did not work
15 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 6/23/2024 in #java-help
Implementing async file watching
using this doc page: https://docs.oracle.com/javase/tutorial/essential/io/notification.html what would be recommended way of doing it asynchronously? do i just setup some sort of exeuctor or thread?? im not very skilled in parallel stuff
4 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 6/21/2024 in #java-help
Jackson Json overwrites json values when reading from it
No description
4 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 6/18/2024 in #java-help
jackson json question
No description
22 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 6/16/2024 in #java-help
onMouseClicked event doesnt do anything
<Pane onMouseClicked="#selectPath" style="-fx-border-color: red" AnchorPane.topAnchor="4" AnchorPane.rightAnchor="4" AnchorPane.bottomAnchor="4">
<JetBrainsImage pickOnBounds="true" icon="AllIcons.Expui.General.Open" />
</Pane>
<Pane onMouseClicked="#selectPath" style="-fx-border-color: red" AnchorPane.topAnchor="4" AnchorPane.rightAnchor="4" AnchorPane.bottomAnchor="4">
<JetBrainsImage pickOnBounds="true" icon="AllIcons.Expui.General.Open" />
</Pane>
for some strange reason it doesnt do anything when i click on it
7 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 5/30/2024 in #java-help
Injecting objects into custom controls FXML
How can that be done? i cant pass it through ctor as it doesnt allow ctors with any params in fxml
7 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 5/20/2024 in #java-help
JFX component from other components
How can I have custom component designed in fxml but still usable like <TestComponent />
15 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 5/19/2024 in #java-help
JavaFX menubar/contextmenu weird borders
No description
5 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 4/27/2024 in #java-help
IntelliJ source code question
Where can I find source code for the code editor in community src?
8 replies
JCHJava Community | Help. Code. Learn.
Created by Koblížkáč on 4/26/2024 in #java-help
RSTA & FlatLaf together
How can i make RSTA use same styling like FlatLaf does
4 replies