Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit a02e48d

Browse files
author
Madhura Bhave
committed
Merge branch 'releases/1.10'
2 parents 55a5ba4 + d65437c commit a02e48d

File tree

58 files changed

+2708
-451
lines changed

Some content is hidden

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

58 files changed

+2708
-451
lines changed

build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ buildscript {
1212
classpath group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.2.4'
1313
classpath group: 'net.saliman', name: 'gradle-cobertura-plugin', version: '2.2.2'
1414
classpath group: 'org.kt3k.gradle.plugin', name: 'coveralls-gradle-plugin', version: '0.4.1'
15+
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7'
1516
}
1617
}
1718

@@ -22,6 +23,12 @@ ext {
2223
allprojects {
2324
/* http://issues.gradle.org/browse/GRADLE-2470 */
2425
apply plugin: 'java'
26+
apply plugin: 'eclipse-wtp'
27+
apply plugin: 'propdeps'
28+
apply plugin: 'propdeps-maven'
29+
apply plugin: 'propdeps-idea'
30+
apply plugin: 'propdeps-eclipse'
31+
configurations.provided.transitive = false
2532
sourceCompatibility = 1.7
2633
targetCompatibility = 1.7
2734
}
@@ -35,6 +42,13 @@ group = 'org.cloudfoundry.identity'
3542
apply plugin: 'war'
3643
description = 'Cloud Foundry Login Server'
3744

45+
eclipse {
46+
wtp {
47+
component {
48+
contextPath = 'login'
49+
}
50+
}
51+
}
3852
task packageSources(type: Jar) {
3953
classifier = 'sources'
4054
from sourceSets.main.allSource
@@ -54,10 +68,14 @@ repositories {
5468

5569
dependencies {
5670
Project identityCommon = project(':cloudfoundry-identity-parent:cloudfoundry-identity-common')
71+
compile (project(':cloudfoundry-identity-parent:cloudfoundry-identity-scim')) {
72+
exclude(module: 'jna')
73+
}
5774

5875
compile(identityCommon) {
5976
exclude(module: 'jna')
6077
}
78+
6179
compile group: 'org.springframework', name: 'spring-context-support', version:springVersion
6280
compile group: 'org.springframework.security', name: 'spring-security-openid', version:springSecurityVersion
6381
compile(group: 'org.springframework.security.extensions', name: 'spring-security-saml2-core', version:'1.0.0.RELEASE') {
@@ -167,6 +185,7 @@ cargo {
167185
port = 8080
168186

169187
local {
188+
// jvmArgs = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
170189
systemProperties {
171190
property 'UAA_PROFILE', 'local'
172191
property 'net.sourceforge.cobertura.datafile', integrationCoverageFile
@@ -212,7 +231,13 @@ project.gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
212231
if (runningWithCoverage()) {
213232
extraClasspath = files(configurations.coberturaJar.files)
214233
}
234+
if (graph.hasTask(integrationTest)) {
235+
systemProperties {
236+
property 'login.invitationsEnabled', 'true'
237+
}
238+
}
215239
}
240+
216241
}
217242

218243
project.tasks.withType(Test).each {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.9.1
1+
version=1.10

src/main/java/org/cloudfoundry/identity/uaa/login/AccountCreationService.java

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,90 @@
11
package org.cloudfoundry.identity.uaa.login;
22

3+
import org.cloudfoundry.identity.uaa.scim.ScimUser;
34
import org.codehaus.jackson.annotate.JsonProperty;
45

6+
import java.io.IOException;
7+
58
public interface AccountCreationService {
6-
void beginActivation(String email, String clientId);
9+
void beginActivation(String email, String password, String clientId);
10+
11+
AccountCreationResponse completeActivation(String code) throws IOException;
12+
13+
void resendVerificationCode(String email, String clientId);
14+
15+
ScimUser createUser(String username, String password);
16+
17+
public static class ExistingUserResponse {
18+
@JsonProperty
19+
private String error;
20+
21+
@JsonProperty
22+
private String message;
23+
24+
@JsonProperty("user_id")
25+
private String userId;
26+
27+
@JsonProperty
28+
private Boolean verified;
29+
30+
@JsonProperty
31+
private Boolean active;
32+
33+
public String getError() {
34+
return error;
35+
}
36+
37+
public void setError(String error) {
38+
this.error = error;
39+
}
40+
41+
public String getMessage() {
42+
return message;
43+
}
44+
45+
public void setMessage(String message) {
46+
this.message = message;
47+
}
48+
49+
public Boolean getVerified() {
50+
return verified;
51+
}
52+
53+
public void setVerified(Boolean verified) {
54+
this.verified = verified;
55+
}
56+
57+
public Boolean getActive() {
58+
return active;
59+
}
60+
61+
public void setActive(Boolean active) {
62+
this.active = active;
63+
}
764

8-
AccountCreation completeActivation(String code, String password);
65+
public String getUserId() {
66+
return userId;
67+
}
968

10-
public static class AccountCreation {
69+
public void setUserId(String userId) {
70+
this.userId = userId;
71+
}
72+
}
73+
74+
public static class AccountCreationResponse {
1175
@JsonProperty("user_id")
1276
private String userId;
1377
private String username;
78+
private String email;
1479
@JsonProperty("redirect_location")
1580
private String redirectLocation;
1681

17-
public AccountCreation() {}
82+
public AccountCreationResponse() {}
1883

19-
public AccountCreation(String userId, String username, String redirectLocation) {
84+
public AccountCreationResponse(String userId, String username, String email, String redirectLocation) {
2085
this.userId = userId;
2186
this.username = username;
87+
this.email = email;
2288
this.redirectLocation = redirectLocation;
2389
}
2490

@@ -42,8 +108,8 @@ public String getRedirectLocation() {
42108
return redirectLocation;
43109
}
44110

45-
public void setRedirectLocation(String redirectLocation) {
46-
this.redirectLocation = redirectLocation;
111+
public String getEmail() {
112+
return email;
47113
}
48114
}
49115
}

src/main/java/org/cloudfoundry/identity/uaa/login/AccountsController.java

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,30 @@
1414

1515
import org.cloudfoundry.identity.uaa.authentication.Origin;
1616
import org.cloudfoundry.identity.uaa.authentication.UaaPrincipal;
17+
import org.cloudfoundry.identity.uaa.error.UaaException;
1718
import org.cloudfoundry.identity.uaa.user.UaaAuthority;
19+
import org.hibernate.validator.constraints.Email;
1820
import org.springframework.http.HttpStatus;
1921
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
2022
import org.springframework.security.core.context.SecurityContextHolder;
2123
import org.springframework.stereotype.Controller;
2224
import org.springframework.ui.Model;
25+
import org.springframework.validation.BindingResult;
26+
import org.springframework.web.bind.annotation.ModelAttribute;
2327
import org.springframework.web.bind.annotation.RequestMapping;
2428
import org.springframework.web.bind.annotation.RequestMethod;
2529
import org.springframework.web.bind.annotation.RequestParam;
2630
import org.springframework.web.client.HttpClientErrorException;
2731

2832
import javax.servlet.http.HttpServletResponse;
33+
import javax.validation.Valid;
34+
35+
import java.io.IOException;
2936

3037
import static org.springframework.web.bind.annotation.RequestMethod.GET;
3138
import static org.springframework.web.bind.annotation.RequestMethod.POST;
3239

3340
@Controller
34-
@RequestMapping("/accounts")
3541
public class AccountsController {
3642

3743
private final AccountCreationService accountCreationService;
@@ -40,58 +46,54 @@ public AccountsController(AccountCreationService accountCreationService) {
4046
this.accountCreationService = accountCreationService;
4147
}
4248

43-
@RequestMapping(value = "/new", method = GET)
49+
@RequestMapping(value = "/create_account", method = GET)
4450
public String activationEmail(Model model,
4551
@RequestParam(value = "client_id", defaultValue = "login") String clientId) {
4652
model.addAttribute("client_id", clientId);
4753
return "accounts/new_activation_email";
4854
}
4955

50-
@RequestMapping(value = "/new", method = GET, params = {"code", "email"})
51-
public String newAccount() {
52-
return "accounts/new";
53-
}
54-
55-
@RequestMapping(method = POST, params = {"email", "client_id"})
56-
public String sendActivationEmail(@RequestParam("email") String email,
57-
@RequestParam("client_id") String clientId) {
58-
accountCreationService.beginActivation(email, clientId);
56+
@RequestMapping(value = "/create_account.do", method = POST)
57+
public String sendActivationEmail(Model model, HttpServletResponse response,
58+
@RequestParam("client_id") String clientId,
59+
@Valid @ModelAttribute("email") ValidEmail email, BindingResult result,
60+
@RequestParam("password") String password,
61+
@RequestParam("password_confirmation") String passwordConfirmation) {
62+
if(result.hasErrors()) {
63+
return handleUnprocessableEntity(model, response, "invalid_email");
64+
}
65+
ChangePasswordValidation validation = new ChangePasswordValidation(password, passwordConfirmation);
66+
if (!validation.valid()) {
67+
return handleUnprocessableEntity(model, response, validation.getMessageCode());
68+
}
69+
try {
70+
accountCreationService.beginActivation(email.getEmail(), password, clientId);
71+
} catch (UaaException e) {
72+
return handleUnprocessableEntity(model, response, "username_exists");
73+
}
5974
return "redirect:accounts/email_sent";
6075
}
6176

62-
@RequestMapping(value = "/email_sent", method = RequestMethod.GET)
77+
@RequestMapping(value = "/accounts/email_sent", method = RequestMethod.GET)
6378
public String emailSent() {
6479
return "accounts/email_sent";
6580
}
6681

67-
@RequestMapping(method = POST, params = {"email", "code", "password", "password_confirmation"})
68-
public String createAccount(Model model,
82+
@RequestMapping(value = "/verify_user", method = GET)
83+
public String verifyUser(Model model,
6984
@RequestParam("code") String code,
70-
@RequestParam("password") String password,
71-
@RequestParam("password_confirmation") String passwordConfirmation,
72-
HttpServletResponse response) {
85+
HttpServletResponse response) throws IOException {
7386

74-
ChangePasswordValidation validation = new ChangePasswordValidation(password, passwordConfirmation);
75-
if (!validation.valid()) {
76-
model.addAttribute("message_code", validation.getMessageCode());
77-
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
78-
return "accounts/new";
79-
}
80-
81-
AccountCreationService.AccountCreation accountCreation;
87+
AccountCreationService.AccountCreationResponse accountCreation;
8288
try {
83-
accountCreation = accountCreationService.completeActivation(code, password);
89+
accountCreation = accountCreationService.completeActivation(code);
8490
} catch (HttpClientErrorException e) {
85-
if (e.getStatusCode().equals(HttpStatus.CONFLICT)) {
86-
model.addAttribute("message_code", "email_already_taken");
87-
} else {
88-
model.addAttribute("message_code", "code_expired");
89-
}
91+
model.addAttribute("error_message_code", "code_expired");
9092
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
91-
return "accounts/new";
93+
return "accounts/new_activation_email";
9294
}
9395

94-
UaaPrincipal uaaPrincipal = new UaaPrincipal(accountCreation.getUserId(), accountCreation.getUsername(), accountCreation.getUsername(), Origin.UAA, null);
96+
UaaPrincipal uaaPrincipal = new UaaPrincipal(accountCreation.getUserId(), accountCreation.getUsername(), accountCreation.getEmail(), Origin.UAA, null);
9597
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(uaaPrincipal, null, UaaAuthority.USER_AUTHORITIES);
9698
SecurityContextHolder.getContext().setAuthentication(token);
9799

@@ -101,4 +103,23 @@ public String createAccount(Model model,
101103
}
102104
return "redirect:" + redirectLocation;
103105
}
106+
107+
private String handleUnprocessableEntity(Model model, HttpServletResponse response, String errorMessage) {
108+
model.addAttribute("error_message_code", errorMessage);
109+
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
110+
return "accounts/new_activation_email";
111+
}
112+
113+
public static class ValidEmail {
114+
@Email
115+
String email;
116+
117+
public String getEmail() {
118+
return email;
119+
}
120+
121+
public void setEmail(String email) {
122+
this.email = email;
123+
}
124+
}
104125
}

src/main/java/org/cloudfoundry/identity/uaa/login/ChangeEmailController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.cloudfoundry.identity.uaa.error.UaaException;
66
import org.cloudfoundry.identity.uaa.user.UaaAuthority;
77
import org.hibernate.validator.constraints.Email;
8+
import org.hibernate.validator.constraints.NotEmpty;
89
import org.springframework.http.HttpStatus;
910
import org.springframework.security.authentication.AnonymousAuthenticationToken;
1011
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -105,6 +106,7 @@ public String verifyEmail(Model model, @RequestParam("code") String code, Redire
105106

106107
public static class ValidEmail {
107108
@Email
109+
@NotEmpty
108110
String newEmail;
109111

110112
public String getNewEmail() {

0 commit comments

Comments
 (0)