Skip to content

Commit

Permalink
Rename local profile to oauth2login
Browse files Browse the repository at this point in the history
  • Loading branch information
alek-sys committed Feb 28, 2020
1 parent 029c72b commit fc498a7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ Use the following commands to manage the local lifecycle of animal-rescue
```

#### Local security configuration
Backend uses Form login for local development with two test accounts - `mysterious_adopter / test` and `test / test`. You can optionally run the app with OAuth2 login flow using `LOGIN_MODE` param: `LOGIN_MODE="oauth2" ./scripts/local.sh start`. This command will build and start Docker container with CloudFoundry User Account and Authentication (UAA) to act as a authorization server.
Backend uses Form login for local development with two test accounts - `mysterious_adopter / test` and `test / test`. You can optionally run the app with OAuth2 login flow using `LOGIN_MODE` param: `LOGIN_MODE="oauth2" ./scripts/local.sh start`. This command will build and start Docker container with CloudFoundry User Account and Authentication (UAA) to act as a authorization server. Test account is `test / test`.

> You have to have Docker installed locally if you want to run the app with OAuth2 login using UAA. For more details, please refer to the official Docker [documentation](https://www.docker.com/products/docker-desktop).
Note that in a real deployment with Gateway, OAuth2 login will be managed by the gateway itself, and your app should use `TokenRelay` filter to receive OpenID ID Token in `Authorization` header. See `CloudFoundrySecurityConfiguration` class for an example of Spring Security 5 configuration to handle token relay correctly.

When `LOGIN_MODE` is set to `oauth2`, Gradle `local` profile will be activated. It adds `spring-security-oauth2-client` to the dependencies list, and configure `oauth2Login` in it's security configuration. After a successful login, the redirect uri is set to `${frontendUrl/rescue/login}` to mimic the user flow with gateway redirect. `auth` module contains a `uaa` Dockerfile which acts as an authorization server the oauth2 login flow.
When `LOGIN_MODE` is set to `oauth2`, Gradle `oauth2login` profile will be activated. It adds `spring-security-oauth2-client` to the dependencies list, and configure `oauth2Login` in it's security configuration. After a successful login, the redirect uri is set to `${frontendUrl/rescue/login}` to mimic the user flow with gateway redirect. `auth` module contains a `uaa` Dockerfile which acts as an authorization server the oauth2 login flow.

#### Tests
Execute the following script to run all tests:
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ repositories {
}

def propertyDrivenProfiles;
if (project.hasProperty('local')) {
propertyDrivenProfiles = 'local'
apply from: rootProject.file('build-local.gradle');
if (project.hasProperty('oauth2login')) {
propertyDrivenProfiles = 'oauth2login'
apply from: rootProject.file('build-oauth2login.gradle');
}

bootRun {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler;

@Configuration
@Profile("local")
public class LocalRunSecurityConfiguration {
@Profile("oauth2login")
public class LocalOAuth2LoginSecurityConfiguration {

@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity httpSecurity) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ startBackend() {
local gradle_opts=''

if [[ $LOGIN_MODE == 'oauth2' ]]; then
gradle_opts='-Plocal'
gradle_opts='-Poauth2login'
fi

if [[ $1 == '--quiet' ]]; then
Expand Down

0 comments on commit fc498a7

Please sign in to comment.