I’m trying to implement an example of Spring Cloud running on Docker.
I have a problem in Keycloak.
I got 401 error.
I couldn’t fix it.
I found some links shown below but they didn’t help me fix my issue.
https://stackoverflow.com/questions/65891716/keycloak-http-401-unauthorized-while-creating-new-user-using-spring-boot-service
https://stackoverflow.com/questions/69335630/still-getting-401-unauthorized-with-a-spring-boot-and-keycloak-in-dockerized-e
https://stackoverflow.com/questions/71432651/getting-401-unauthorized-when-calling-quarkus-app-inside-a-docker-container-with
https://stackoverflow.com/questions/62838369/keycloak-always-returns-401-zuul-api-gateway-for-microservices
Here are some errors when I changed serverUrl
keycloak:8080 -> 401 Unauthorized issue
keycloak:8080/auth -> 404 Not Found
keycloak:8181 -> Connection refused
Here is my github repository : GitHub - Rapter1990/SpringBootMicroservices: Spring Boot Microservice Example(Eureka Server, Config Server, API Gateway, Services , RabbitMq, Keycloak)
Can you look through my new screenshots if you don’t mind ?
Here is the link : spring_cloud_new_screenshots - Google Drive
When I changed the serverUrl shown below,
public final static String serverUrl = "http://keycloak:8080/auth";
I got this issue.
2022-08-28 20:53:17.899 INFO 1 --- [nio-9000-exec-4] c.s.u.controller.UserController : UserController | signUpUser is started
2022-08-28 20:53:17.899 INFO 1 --- [nio-9000-exec-4] c.s.u.controller.UserController : UserController | signUpUser | SignUpRequest role : ROLE_USER
2022-08-28 20:53:17.899 INFO 1 --- [nio-9000-exec-4] c.s.u.controller.UserController : UserController | signUpUser | SignUpRequest email : springbootmicroserviceuser@user.com
2022-08-28 20:53:17.899 INFO 1 --- [nio-9000-exec-4] c.s.u.controller.UserController : UserController | signUpUser | SignUpRequest name : Micro User
2022-08-28 20:53:17.900 INFO 1 --- [nio-9000-exec-4] c.s.u.service.impl.UserServiceImpl : UserServiceImpl | signUpUser is started
2022-08-28 20:53:17.900 INFO 1 --- [nio-9000-exec-4] c.s.u.service.impl.KeycloakServiceImpl : KeycloakServiceImpl | createUserWithKeycloak is started
2022-08-28 20:53:17.900 INFO 1 --- [nio-9000-exec-4] c.s.u.service.impl.KeycloakServiceImpl : KeycloakServiceImpl | createUserWithKeycloak | userRepresentation is completed
2022-08-28 20:53:17.900 INFO 1 --- [nio-9000-exec-4] c.s.u.service.impl.KeycloakServiceImpl : KeycloakServiceImpl | createUserWithKeycloak | credentialRepresentation is completed
2022-08-28 20:53:17.909 INFO 1 --- [nio-9000-exec-4] c.s.u.service.impl.KeycloakServiceImpl : KeycloakServiceImpl | createUserWithKeycloak | usersResource : RESTEASY004635: Resteasy
Client Proxy for : org.keycloak.admin.client.resource.UsersResource
2022-08-28 20:53:17.921 ERROR 1 --- [nio-9000-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw excepti
on [Request processing failed; nested exception is javax.ws.rs.ProcessingException: javax.ws.rs.NotFoundException: HTTP 404 Not Found] with root cause
javax.ws.rs.NotFoundException: HTTP 404 Not Found
Here is my Keycloak Config file
@Configuration
public class KeycloakConfig {
public final static String serverUrl = "http://keycloak:8080/auth";
public final static String realm = "spring_cloud_microservices";
public final static String clientId = "spring-boot-microservice-keycloak";
public final static String clientSecret = "X4kQIiWgCsLXRrL3xy5aQ03eCmmT7Ib1";
final static String userName = "admin";
final static String password = "admin";
@Bean
public KeycloakConfigResolver keycloakConfigResolver(){
return new KeycloakSpringBootConfigResolver();
}
@Bean
public Keycloak keycloak(){
return Keycloak.getInstance(serverUrl,
realm,
userName,
password,
clientId,
clientSecret);
}
}