Skip to content

Commit

Permalink
fix: correct error display (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morazzer authored Sep 15, 2024
1 parent 5ebebe0 commit 08db1dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SecurityConfig(BearerTokenAuthFilter bearerTokenAuthFilter) {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(request -> {
request.requestMatchers("/login", "/auth").permitAll();
request.requestMatchers("/login", "/auth", "/health", "/error").permitAll();
request.anyRequest().authenticated();
}).csrf(CsrfConfigurer::disable).addFilterBefore(bearerTokenAuthFilter, BasicAuthenticationFilter.class);
return http.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.morazzer.cookies.backend.controllers;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class HealthController {

public record Status(boolean ok) {}

@GetMapping(value = "/health", produces = MediaType.APPLICATION_JSON_VALUE)
public Status health() {
return new Status(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@
import dev.morazzer.cookies.backend.entities.other.MinecraftUser;
import dev.morazzer.cookies.backend.utils.redis.UUIDKey;
import dev.morazzer.cookies.backend.utils.redis.UsernameKey;
import dev.morazzer.cookies.entities.request.AuthRequest;
import java.io.IOException;
import java.net.URI;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.swing.text.html.Option;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class MojangAuthService {
Expand Down Expand Up @@ -44,7 +38,8 @@ public Optional<MinecraftUser> isAuthenticated(String sharedSecret, String usern
MinecraftRedisService.INSTANCE.write(new UUIDKey(username), user.uuid());
return Optional.of(user);
}
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ spring:
username: ${RABBIT_MQ_USERNAME}
password: ${RABBIT_MQ_PASSWORD}
host: ${RABBIT_MQ_HOST}
mvc:
servlet:
path: ${API_PATH}
backend:
auth:
sign: ${BACKEND_SIGN_KEY}
Expand Down

0 comments on commit 08db1dc

Please sign in to comment.