Skip to content

Commit ac69ac2

Browse files
committed
Merge branch 'releases/1.8.2'
2 parents c4ff395 + 3cc99c4 commit ac69ac2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1382
-294
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ coverage.ec
2727
.gradle
2828
build/
2929
/classes/
30+
uaa/src/main/resources/build.properties
31+
uaa/src/main/resources/git.properties

README.md

Lines changed: 34 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ clients, as well as various other management functions.
1717
* Tokens: [A note on tokens, scopes and authorities](https://github.com/cloudfoundry/uaa/tree/master/docs/UAA-Tokens.md)
1818
* Technical forum: [vcap-dev google group](https://groups.google.com/a/cloudfoundry.org/forum/?fromgroups#!forum/vcap-dev)
1919
* Docs: [docs/](https://github.com/cloudfoundry/uaa/tree/master/docs)
20-
* API Documentation: [UAA-API.rst](https://github.com/cloudfoundry/uaa/tree/master/doc/UAA-API.rst)
20+
* API Documentation: [UAA-APIs.rst](https://github.com/cloudfoundry/uaa/tree/master/docs/UAA-APIs.rst)
2121
* Specification: [The Oauth 2 Authorization Framework](http://tools.ietf.org/html/rfc6749)
22-
* LDAP: [UAA LDAP Integration](https://github.com/cloudfoundry/uaa/tree/master/doc/UAA-LDAP.md)
22+
* LDAP: [UAA LDAP Integration](https://github.com/cloudfoundry/uaa/tree/master/docs/UAA-LDAP.md)
2323

2424
## Quick Start
2525

@@ -128,26 +128,14 @@ grant, the same as used by a client like CF.
128128
You can run the integration tests with
129129

130130
$ ./gradlew integrationTest
131-
132-
To make the tests work in various environments you can modify the
133-
configuration of the server and the tests (e.g. the admin client)
134-
using a variety of mechanisms. The simplest is to provide additional
135-
Maven profiles on the command line, e.g.
136-
137-
$ (cd uaa; mvn test -P vcap)
138-
131+
139132
will run the integration tests against a uaa server running in a local
140-
vcap, so for example the service URL is set to `uaa.vcap.me` (by
141-
default). There are several Maven profiles to play with, and they can
142-
be used to run the server, or the tests or both:
143-
144-
* `local`: runs the server on the ROOT context `http://localhost:8080/`
145-
146-
* `vcap`: also runs the server on the ROOT context and points the
147-
tests at `uaa.vcap.me`.
133+
Apache Tomcat instance, so for example the service URL is set to `http://localhost:8080/uaa` (by
134+
default).
148135

149-
These profiles set the `CLOUD_FOUNDRY_CONFIG_PATH` to pick up a
150-
`uaa.yml` and (if appropriate) set the context root for running the
136+
You can point the `CLOUD_FOUNDRY_CONFIG_PATH` to pick up a
137+
`uaa.yml` where URLs can be changed
138+
and (if appropriate) set the context root for running the
151139
server (see below for more detail on that).
152140

153141
### Custom YAML Configuration
@@ -164,7 +152,7 @@ To modify the runtime parameters you can provide a `uaa.yml`, e.g.
164152

165153
then from `uaa/uaa`
166154

167-
$ CLOUD_FOUNDRY_CONFIG_PATH=/tmp mvn test
155+
$ CLOUD_FOUNDRY_CONFIG_PATH=/tmp ./gradlew test
168156

169157
The webapp looks for a Yaml file in the following locations
170158
(later entries override earlier ones) when it starts up.
@@ -174,69 +162,23 @@ The webapp looks for a Yaml file in the following locations
174162
file:${UAA_CONFIG_FILE}
175163
${UAA_CONFIG_URL}
176164

177-
### Using Maven with Cloud Foundry
178-
179-
To test against a Cloud Foundry instance use the Maven profile `vcap` (it
180-
switches off some of the tests that create random client and user
181-
accounts):
165+
### Using Gradle to test with postgresql or mysql
182166

183-
$ (cd uaa; mvn test -P vcap)
184-
185-
To change the target server it should suffice to set
186-
`VCAP_BVT_TARGET` (the tests prefix it with `uaa.` to form the
187-
server url), e.g.
188-
189-
$ VCAP_BVT_TARGET=appcloud21.dev.mozycloud mvn test -P vcap
190-
191-
You can also override some of the other most important default
192-
settings using environment variables. The defaults as usual come from
193-
`uaa.yml` but tests will search first in an environment variable:
194-
195-
* `UAA_ADMIN_CLIENT_ID` the client id for bootstrapping client
196-
registrations needed for the rest of the tests.
197-
198-
* `UAA_ADMIN_CLIENT_SECRET` the client secret for bootstrapping client
199-
registrations
200-
201-
All other settings from `uaa.yml` can be overridden individually as
202-
system properties. Running in an IDE this is easy just using whatever
203-
features allow you to modify the JVM in test runs, but using Maven you
204-
have to use the `argLine` property to get settings passed onto the
205-
test JVM, e.g.
206-
207-
$ mvn -DargLine=-Duaa.test.username=foo test
208-
209-
will create an account with `userName=foo` for testing (instead using
210-
the default setting from `uaa.yml`).
211-
212-
If you prefer environment variables to system properties you can use a
213-
custom `uaa.yml` with placeholders for your environment variables,
214-
e.g.
215-
216-
uaa:
217-
test:
218-
username: ${UAA_TEST_USERNAME:marissa}
219-
220-
will look for an environment variable (or system property)
221-
`UAA_TEST_USERNAME` before defaulting to `marissa`. This is the trick
222-
used to expose `UAA_ADMIN_CLIENT_SECRET` etc. in the standard
223-
configuration.
224-
225-
### Using Maven to test with postgresql or mysql
226-
227-
The default uaa unit tests (mvn test) use hsqldb.
167+
The default uaa unit tests (./gradlew test) use hsqldb.
228168

229169
To run the unit tests using postgresql:
230170

231-
$ SPRING_PROFILES_ACTIVE=test,postgresql CLOUD_FOUNDRY_CONFIG_PATH=src/test/resources/test/profiles/postgresql mvn test
171+
$ echo "spring_profiles: default,postgresql" > src/main/resources/uaa.yml
172+
$ ./gradlew test integrationTest
232173

233174
To run the unit tests using mysql:
234175

235-
$ SPRING_PROFILES_ACTIVE=test,mysql CLOUD_FOUNDRY_CONFIG_PATH=src/test/resources/test/profiles/mysql mvn test
176+
$ echo "spring_profiles: default,mysql" > src/main/resources/uaa.yml
177+
$ ./gradlew test integrationTest
178+
236179

237-
The database configuration for the common and scim modules is located at:
238-
common/src/test/resources/(mysql|postgresql).properties
239-
scim/src/test/resources/(mysql|postgresql).properties
180+
The database configuration for the common and scim modules is defaulted in
181+
the Spring XML configuration files. You can change them by configuring them in `uaa.yml`
240182

241183
## Inventory
242184

@@ -268,10 +210,9 @@ In CloudFoundry terms
268210

269211
The authentication service is `uaa`. It's a plain Spring MVC webapp.
270212
Deploy as normal in Tomcat or your container of choice, or execute
271-
`mvn tomcat7:run` to run it directly from `uaa` directory in the source
272-
tree (make sure the common jar is installed first using `mvn install`
273-
from the common subdirectory or from the top level directory). When
274-
running with maven it listens on port 8080.
213+
`./gradlew run` to run it directly from `uaa` directory in the source
214+
tree. When running with gradle it listens on port 8080 and the URL is
215+
`http://localhost:8080/uaa`
275216

276217
The UAA Server supports the APIs defined in the UAA-APIs document. To summarise:
277218

@@ -339,63 +280,36 @@ To use Postgresql for user data, activate one of the Spring profiles
339280

340281
The active profiles can be configured in `uaa.yml` using
341282

342-
spring_profiles: postgresql
283+
spring_profiles: postgresql,default
343284

344-
or by passing the `spring.profiles.active` parameter to the JVM. For,
345-
example to run with an embedded HSQL database:
346-
347-
mvn -Dspring.profiles.active=hsqldb tomcat7:run
348-
349-
Or to use PostgreSQL instead of HSQL:
350-
351-
mvn -Dspring.profiles.active=postgresql tomcat7:run
352-
353-
To bootstrap a microcloud type environment you need an admin client.
354-
For this there is a database initializer component that inserts an
355-
admin client. If the default profile is active (i.e. not
356-
`postgresql`) there is also a `cf` client so that the gem login works
357-
out of the box. You can override the default settings and add
358-
additional clients in `uaa.yml`:
285+
To use PostgreSQL instead of HSQL:
359286

360-
oauth:
361-
clients:
362-
admin:
363-
authorized-grant-types: client_credentials
364-
scope: read,write,password
365-
authorities: ROLE_CLIENT,ROLE_ADIN
366-
id: admin
367-
secret: adminclientsecret
368-
resource-ids: clients
287+
$ echo "spring_profiles: default,postgresql" > src/main/resources/uaa.yml
288+
$ ./gradlew run
369289

370-
The admin client can be used to create additional clients (but not to
371-
do anything much else). A client with read/write access to the `scim`
372-
resource will be needed to create user accounts. The integration
373-
tests take care of this automatically, inserting client and user
374-
accounts as necessary to make the tests work.
375290

376-
## The API Application
291+
## The API Sample Application
377292

378-
An example resource server. It hosts a service which returns
379-
a list of mock applications under `/apps`.
293+
Two sample applications are included with the UAA. The `/api` and `/app`
380294

381-
Run it using `mvn tomcat7:run` from the `api` directory (once all other
382-
tomcat processes have been shutdown). This will deploy the app to a
383-
Tomcat manager on port 8080.
295+
Run it using `./gradlew run` from the `uaa` root directory
296+
All three apps, `/uaa`, `/api` and `/app` get deployed
297+
simultaneously.
384298

385-
## The App Application
299+
## The App Sample Application
386300

387301
This is a user interface app (primarily aimed at browsers) that uses
388302
OpenId Connect for authentication (i.e. SSO) and OAuth2 for access
389303
grants. It authenticates with the Auth service, and then accesses
390-
resources in the API service. Run it with `mvn tomcat7:run` from the
391-
`app` directory (once all other tomcat processes have been shutdown).
304+
resources in the API service. Run it with `./gradlew run` from the
305+
`uaa` root directory.
392306

393307
The application can operate in multiple different profiles according
394308
to the location (and presence) of the UAA server and the Login
395309
application. By default it will look for a UAA on
396310
`localhost:8080/uaa`, but you can change this by setting an
397311
environment variable (or System property) called `UAA_PROFILE`. In
398-
the application source code (`src/main/resources`) you will find
312+
the application source code (`samples/app/src/main/resources`) you will find
399313
multiple properties files pre-configured with different likely
400314
locations for those servers. They are all in the form
401315
`application-<UAA_PROFILE>.properties` and the naming convention

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ cargo {
193193
}
194194

195195
installer {
196-
installUrl = 'http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.52/bin/apache-tomcat-7.0.52.tar.gz'
196+
installUrl = 'http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz'
197197
downloadDir = file("$buildDir/download")
198198
extractDir = file("$buildDir/extract")
199199
}

common/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
description = 'CloudFoundry Identity Common Jar'
22

3+
configurations { providedCompile }
4+
35
dependencies {
46
compile group: 'org.springframework.security', name: 'spring-security-ldap', version:parent.springSecurityVersion
57
compile group: 'org.springframework.ldap', name: 'spring-ldap-core', version:parent.springSecurityLdapVersion
@@ -26,7 +28,6 @@ dependencies {
2628
compile group: 'org.springframework', name: 'spring-tx', version:parent.springVersion
2729
compile group: 'org.springframework.security', name: 'spring-security-core', version:parent.springSecurityVersion
2830
compile group: 'org.springframework.security', name: 'spring-security-web', version:parent.springSecurityVersion
29-
compile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.0.1'
3031
compile group: 'log4j', name: 'log4j', version:'1.2.14'
3132
compile(group: 'org.apache.httpcomponents', name: 'httpclient', version:'4.3.3') {
3233
exclude(module: 'commons-logging')
@@ -46,6 +47,9 @@ dependencies {
4647
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version:'1.1.7'
4748
compile group: 'com.googlecode.flyway', name: 'flyway-core', version:'2.3.1'
4849
compile group: 'org.hsqldb', name: 'hsqldb', version:'2.3.1'
50+
51+
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.0.1'
52+
4953
testCompile group: 'org.springframework', name: 'spring-test', version:parent.springVersion
5054
testCompile group: 'junit', name: 'junit', version:'4.11'
5155
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
@@ -56,6 +60,10 @@ dependencies {
5660
testCompile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version:parent.tomcatVersion
5761
}
5862

63+
sourceSets.main.compileClasspath += configurations.providedCompile
64+
sourceSets.test.compileClasspath += configurations.providedCompile
65+
sourceSets.test.runtimeClasspath += configurations.providedCompile
66+
5967
processResources {
6068
//maven replaces project.artifactId in the log4j.properties file
6169
//https://www.pivotaltracker.com/story/show/74344574

common/src/main/java/org/cloudfoundry/identity/uaa/UaaConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public static class OAuth {
106106
public Authorize authorize;
107107
@Valid
108108
public Map<String, OAuthClient> clients;
109+
@Valid
110+
public User user;
109111

110112
public static class Client {
111113
public String override;
@@ -116,6 +118,11 @@ public static class Authorize {
116118
@NotNull
117119
public boolean ssl;
118120
}
121+
122+
public static class User {
123+
@Valid
124+
public Set<String> authorities;
125+
}
119126
}
120127

121128
public static class OAuthClient {

common/src/main/java/org/cloudfoundry/identity/uaa/authentication/manager/LdapLoginAuthenticationManager.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@ public class LdapLoginAuthenticationManager extends ExternalLoginAuthenticationM
3131
protected UaaUser getUser(UserDetails details, Map<String, String> info) {
3232
UaaUser user = super.getUser(details, info);
3333
if (details instanceof LdapUserDetails) {
34-
String mail = user.getEmail();
34+
String mail = getEmail(user, (LdapUserDetails)details);
3535
String origin = getOrigin();
3636
String externalId = ((LdapUserDetails)details).getDn();
37-
if (details instanceof ExtendedLdapUserDetails) {
38-
String[] addrs = ((ExtendedLdapUserDetails)details).getMail();
39-
if (addrs!=null && addrs.length>0) {
40-
mail = addrs[0];
41-
}
42-
}
4337
return new UaaUser(
4438
user.getId(),
4539
user.getUsername(),
@@ -58,8 +52,27 @@ protected UaaUser getUser(UserDetails details, Map<String, String> info) {
5852
}
5953
}
6054

55+
protected String getEmail(UaaUser user, LdapUserDetails details) {
56+
String mail = user.getEmail();
57+
if (details instanceof ExtendedLdapUserDetails) {
58+
String[] emails = ((ExtendedLdapUserDetails)details).getMail();
59+
if (emails!=null && emails.length>0) {
60+
mail = emails[0];
61+
}
62+
}
63+
return mail;
64+
}
65+
6166
@Override
6267
protected UaaUser userAuthenticated(Authentication request, UaaUser user) {
68+
//we must check and see if the email address has changed between authentications
69+
if (request.getPrincipal() !=null && request.getPrincipal() instanceof ExtendedLdapUserDetails) {
70+
ExtendedLdapUserDetails details = (ExtendedLdapUserDetails)request.getPrincipal();
71+
UaaUser fromRequest = getUser(details, getExtendedAuthorizationInfo(request));
72+
if (fromRequest.getEmail()!=null && !fromRequest.getEmail().equals(user.getEmail())) {
73+
user = user.modifyEmail(fromRequest.getEmail());
74+
}
75+
}
6376
ExternalGroupAuthorizationEvent event = new ExternalGroupAuthorizationEvent(user, request.getAuthorities(), isAutoAddAuthorities());
6477
publish(event);
6578
return getUserDatabase().retrieveUserById(user.getId());

0 commit comments

Comments
 (0)