Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
Make it work OOTB with PWS (in 'cloud' profile)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Syer committed Mar 30, 2015
1 parent dd56e79 commit 02ebf01
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
@@ -1,3 +1,13 @@
This project is a sample of a client application with OAuth2 single
sign on using Spring Cloud (in Java - there is a Groovy sample in the
"demo" directory at https://github.com/spring-cloud-samples/scripts).

You can run the app locally with the "authserver" app from https://github.com/spring-cloud-samples/ (running on localhost:8080/uaa), or against Github as an auth server by using the "github" profile (run it with `-Dspring.profiles.active=github`).

It should also work out of the box on Cloud Foundry if you create a user provided service called "sso" pointing to the UAA, e.g.

```
$ cf create-user-provided-service sso -p '{"userInfoUri":"https://uaa.run.pivotal.io/userinfo", "tokenUri":"https://login.run.pivotal.io/oauth/token", "authorizationUri":"https://login.run.pivotal.io/oauth/authorize", "clientId":"[acme]", "clientSecret":"[secret]"}'
```

where `[client]` and `[secret]` are the credentials of a registered client that is
5 changes: 5 additions & 0 deletions src/main/java/demo/SsoApplication.java
Expand Up @@ -18,6 +18,7 @@
import org.springframework.cloud.security.oauth2.sso.OAuth2SsoConfigurerAdapter;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfToken;
Expand Down Expand Up @@ -48,6 +49,10 @@ public Principal user(Principal user) {
}

public static void main(String[] args) {
StandardEnvironment environment = new StandardEnvironment();
if (!environment.acceptsProfiles("cloud", "github")) {
environment.addActiveProfile("local");
}
SpringApplication.run(SsoApplication.class, args);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/application.yml
Expand Up @@ -21,6 +21,11 @@ spring:
sso:
loginPath: /dashboard/login
logoutPath: /dashboard/logout

---
spring:
profiles: local
oauth2:
client:
accessTokenUri: http://localhost:8080/uaa/oauth/token
userAuthorizationUri: http://localhost:8080/uaa/oauth/authorize
Expand All @@ -35,11 +40,6 @@ spring:
id: openid
serviceId: ${PREFIX:}resource

---
spring:
profiles: local
oauth2:

---
spring:
profiles: github
Expand Down

0 comments on commit 02ebf01

Please sign in to comment.