Skip to content

Commit

Permalink
Merge pull request Baeldung#203 from sampada07/JAVA-409
Browse files Browse the repository at this point in the history
JAVA-409: Update SSO with OAuth2 article
  • Loading branch information
lor6 authored Jul 1, 2020
2 parents c86845d + c8748f3 commit 51e377c
Show file tree
Hide file tree
Showing 26 changed files with 645 additions and 621 deletions.
14 changes: 10 additions & 4 deletions oauth-sso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
### Relevant information:

1. `sso-authorization-server` is a Keycloak Authorization Server wrapped as a Spring Boot application
2. There is one OAuth Client registered in the Authorization Server:
1. Client Id: ssoClient
2. Client secret: ssoClientSecret
3. Redirect Uri: http://localhost:8089/
2. There are two OIDC-Connect Clients registered in the Authorization Server:
First -
1. Client Id: ssoClient-1
2. Client secret: ssoClientSecret-1
3. Redirect Uri: http://localhost:8082/ui-one/login/oauth2/code/custom
And second -
1. Client Id: ssoClient-2
2. Client secret: ssoClientSecret-2
3. Redirect Uri: http://localhost:8084/ui-two/login/oauth2/code/custom
3. `sso-resource-server` is a Spring Boot based RESTFul API, acting as a backend Application
4. `sso-client-app-1` and `sso-client-app-2` are two identical Spring MVC Thymeleaf App acting our front end. They are available at [http://localhost:8082/ui-one/](http://localhost:8082/ui-one) and [http://localhost:8084/ui-two/](http://localhost:8084/ui-two/) respectively.
5. There are two users registered in the Authorization Server:
1. [email protected] / 123
2. [email protected] / pass
6. The module uses the new OAuth stack with Java 13.

## Relevant Articles:

29 changes: 15 additions & 14 deletions oauth-sso/pom.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<description>New OAuth2 Stack in Spring Security 5</description>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<description>New OAuth2 Stack in Spring Security 5</description>

<groupId>com.baeldung</groupId>
<artifactId>oauth-sso</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<groupId>com.baeldung</groupId>
<artifactId>oauth-sso</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>sso-authorization-server</module>
<module>sso-resource-server</module>
<module>sso-client-app-1</module>
<module>sso-client-app-2</module>
</modules>
<modules>
<module>sso-authorization-server</module>
<module>sso-resource-server</module>
<module>sso-client-app-1</module>
<module>sso-client-app-2</module>
</modules>

</project>
222 changes: 111 additions & 111 deletions oauth-sso/sso-authorization-server/pom.xml
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.baeldung</groupId>
<artifactId>sso-authorization-server</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath />
</parent>

<dependencies>

<!-- web -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- persistence -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Keycloak server -->

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>

<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-dependencies-server-all</artifactId>
<version>${keycloak.version}</version>
<type>pom</type>
</dependency>
<!-- config properties processor -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<!-- test -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<developers>
<developer>
<email>[email protected]</email>
<name>Eugen Paraschiv</name>
<url>https://github.com/eugenp</url>
<id>eugenp</id>
</developer>
</developers>

<properties>
<!-- non-dependencies -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>13</java.version>

<keycloak.version>10.0.1</keycloak.version>
<resteasy.version>3.11.2.Final</resteasy.version>
</properties>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.baeldung</groupId>
<artifactId>sso-authorization-server</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath />
</parent>

<dependencies>

<!-- web -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- persistence -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Keycloak server -->

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>

<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-dependencies-server-all</artifactId>
<version>${keycloak.version}</version>
<type>pom</type>
</dependency>

<!-- config properties processor -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<!-- test -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<developers>
<developer>
<email>[email protected]</email>
<name>Eugen Paraschiv</name>
<url>https://github.com/eugenp</url>
<id>eugenp</id>
</developer>
</developers>

<properties>
<!-- non-dependencies -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>13</java.version>

<keycloak.version>10.0.1</keycloak.version>
<resteasy.version>3.11.2.Final</resteasy.version>
</properties>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@
@EnableConfigurationProperties({ KeycloakServerProperties.class })
public class AuthorizationServerApp {

private static final Logger LOG = LoggerFactory.getLogger(AuthorizationServerApp.class);
private static final Logger LOG = LoggerFactory.getLogger(AuthorizationServerApp.class);

public static void main(String[] args) throws Exception {
SpringApplication.run(AuthorizationServerApp.class, args);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(AuthorizationServerApp.class, args);
}

@Bean
ApplicationListener<ApplicationReadyEvent> onApplicationReadyEventListener(ServerProperties serverProperties,
KeycloakServerProperties keycloakServerProperties) {
@Bean
ApplicationListener<ApplicationReadyEvent> onApplicationReadyEventListener(ServerProperties serverProperties, KeycloakServerProperties keycloakServerProperties) {

return (evt) -> {
return (evt) -> {

Integer port = serverProperties.getPort();
String keycloakContextPath = keycloakServerProperties.getContextPath();
Integer port = serverProperties.getPort();
String keycloakContextPath = keycloakServerProperties.getContextPath();

LOG.info("Embedded Keycloak started: http://localhost:{}{} to use keycloak", port, keycloakContextPath);
};
}
LOG.info("Embedded Keycloak started: http://localhost:{}{} to use keycloak", port, keycloakContextPath);
};
}

}
Loading

0 comments on commit 51e377c

Please sign in to comment.