Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keycloak oidc #15

Merged
merged 5 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Spring MVC:
- favicon handler

Security:
- Account management
- Account management with KeyCloak
- Spring Security
- User/User_Authority entity and repository/services
- login, logout, home pages based on user role
Expand Down Expand Up @@ -108,12 +108,12 @@ It contains following applications:

# Note you will need to create a database named 'seedapp' in your mysql server

Option 1 - run with manually started ActiveMQ and MySQL servers
Option 1 - run with manually started KeyCloak, ActiveMQ and MySQL servers
- Run ```mvn clean install``` at root
- Run ```docker-compose -f config/docker-compose.yml up``` at root to start docker containers
- Go to main-app folder and run ```mvn``` to start the application

Option 2 - automatically start ActiveMQ and MySQL using TestContainer while application is starting
Option 2 - automatically start KeyCloak, ActiveMQ and MySQL using TestContainer while application is starting
- Run ```mvn clean install``` at root
- Go to main-app folder and run ```mvn -Pdev,withTestContainer``` to start the application

Expand Down
19 changes: 19 additions & 0 deletions config/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ services:
- 9411:9411
networks:
- seedappnet
keycloak:
image: 'quay.io/keycloak/keycloak:23.0.3'
container_name: keycloak
command: start-dev --import-realm
environment:
- KEYCLOAK_DB=dev-file
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
- KEYCLOAK_FEATURES=scripts
- KEYCLOAK_HTTP_PORT=8080
- KEYCLOAK_HTTPS_PORT=9443
# entrypoint: /tmp/keycloak/config/docker-compose-entrypoint.sh --hostname host.docker.internal:8080
volumes:
- ../main-app/main-webapp/src/main/resources/keycloak/:/opt/keycloak/data/import
ports:
- 8082:8080
- 9443:9443
networks:
- seedappnet
volumes:
esdata1:
driver: local
Expand Down
8 changes: 0 additions & 8 deletions email/email-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,6 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi-ui.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
<build.profile>dev</build.profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gt.mail.web.rest;

import gt.common.config.BaseException;
//import gt.common.config.BaseException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -21,9 +21,9 @@ public class HelloResource {
@GetMapping("/hello")
public Map<String, String> sayHello() {
log.info("Received hello request");
if (RANDOM.nextBoolean()) {
throw new BaseException("Something");
}
// if (RANDOM.nextBoolean()) {
// throw new BaseException("Something");
// }
return Map.of("hello", "world");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,27 @@
class EmailResourceIT {

@Test
void sayHello2(@Autowired MockMvc mvc) throws Exception {
void canSendEmail(@Autowired MockMvc mvc) throws Exception {

mvc.perform(
post("/sendEmail")
.contentType(MediaType.APPLICATION_JSON)
.content(sampleEmail().getBytes()))
post("/sendEmail")
.contentType(MediaType.APPLICATION_JSON)
.content(sampleEmail().getBytes()))
.andExpect(status().isOk());
}

String sampleEmail() {
return "{\"from\":\"test@email.com\",\"subject\":\"Test\",\"content\":\"Body\",\"isHtml\":false,\"files\":[],\"to\":[\"recep@emai.com\"],\"cc\":[],\"bcc\":[]}";
return """
{
"fromEmail":"test@email.com",
"subject":"Test",
"content":"Body",
"isHtml":false,
"files":[],
"to":["recep@emai.com"]
,"cc":[],
"bcc":[]
}
""";
}
}
6 changes: 5 additions & 1 deletion email/email-service/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ spring:
port: ${MAILHOG_PORT:1025}
username:
password:

security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://localhost:${KEYCLOAK_PORT:8082}/realms/articleapp
logging.level:
ROOT: WARN
gt: INFO
Expand Down
7 changes: 6 additions & 1 deletion main-app/main-orm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@
<propertyFile>src/main/resources/liquibase-jpa-diff.properties</propertyFile>

<!-- liquibase:generateChangeLog-->
<!--<propertyFile>src/main/resources/liquibase-existing-db.properties</propertyFile>-->
<!-- <propertyFile>src/main/resources/liquibase-existing-db.properties</propertyFile>-->

</configuration>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate6</artifactId>
<version>${liquibase.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
Expand Down
Loading
Loading