/
RemoteScimUserProvisioning.java
143 lines (122 loc) · 5.3 KB
/
RemoteScimUserProvisioning.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
* Cloud Foundry
* Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product includes a number of subcomponents with
* separate copyright notices and license terms. Your use of these
* subcomponents is subject to the terms and conditions of the
* subcomponent's license, as noted in the LICENSE file.
*******************************************************************************/
package org.cloudfoundry.identity.uaa.scim.remote;
import org.cloudfoundry.identity.uaa.account.PasswordChangeRequest;
import org.cloudfoundry.identity.uaa.scim.ScimUser;
import org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning;
import org.cloudfoundry.identity.uaa.scim.exception.InvalidPasswordException;
import org.cloudfoundry.identity.uaa.scim.exception.InvalidScimResourceException;
import org.cloudfoundry.identity.uaa.scim.exception.ScimResourceNotFoundException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
import java.util.Date;
import java.util.List;
/**
* Remote implementation of
* {@link org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning} using the
* Scim endpoints on a remote server.
*
* @author Dave Syer
*
*/
@Deprecated
public class RemoteScimUserProvisioning implements ScimUserProvisioning {
private RestOperations restTemplate = new RestTemplate();
private String baseUrl = "https://uaa.cloudfoundry.com";
/**
* @param restTemplate the rest template to set
*/
public void setRestTemplate(RestOperations restTemplate) {
this.restTemplate = restTemplate;
}
/**
* @param baseUrl the base url to set to the SCIM server
*/
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
@Override
public ScimUser retrieve(String id) throws ScimResourceNotFoundException {
return restTemplate.getForObject(baseUrl + "/User/{id}", ScimUser.class, id);
}
@Override
@SuppressWarnings("unchecked")
public List<ScimUser> retrieveAll() {
return restTemplate.getForObject(baseUrl + "/Users", List.class);
}
@Override
@SuppressWarnings("unchecked")
public List<ScimUser> query(String filter) {
return restTemplate.getForObject(baseUrl + "/Users?filter={filter}", List.class, filter);
}
@Override
@SuppressWarnings("unchecked")
public List<ScimUser> query(String filter, String sortBy, boolean ascending) {
String order = ascending ? "" : "&sortOrder=descending";
return restTemplate.getForObject(baseUrl + "/Users?filter={filter}&sortBy={sortBy}" + order, List.class,
filter, sortBy);
}
@Override
public ScimUser create(ScimUser user) {
return restTemplate.postForObject(baseUrl + "/User", user, ScimUser.class);
}
@Override
public ScimUser createUser(ScimUser user, String password) throws InvalidPasswordException,
InvalidScimResourceException {
user.setPassword(password);
return create(user);
}
@Override
public ScimUser update(String id, ScimUser user) throws InvalidScimResourceException, ScimResourceNotFoundException {
restTemplate.put(baseUrl + "/User/{id}", user, id);
return user;
}
@Override
public void changePassword(String id, String oldPassword, String newPassword)
throws ScimResourceNotFoundException {
PasswordChangeRequest request = new PasswordChangeRequest();
request.setOldPassword(oldPassword);
request.setPassword(newPassword);
restTemplate.put(baseUrl + "/User/{id}/password", request, id);
}
@Override
public void updatePasswordLastModified(String id, long passwordLastModified) throws ScimResourceNotFoundException {
throw new UnsupportedOperationException();
}
@Override
public ScimUser verifyUser(String id, int version) throws ScimResourceNotFoundException,
InvalidScimResourceException {
HttpHeaders headers = new HttpHeaders();
headers.set("If-Match", String.format("%d", version));
return restTemplate.exchange(baseUrl + "/User/{id}/verify", HttpMethod.GET, new HttpEntity<Void>(headers),
ScimUser.class, id).getBody();
}
@Override
public boolean checkPasswordMatches(String id, String password) throws ScimResourceNotFoundException {
throw new UnsupportedOperationException();
}
@Override
public ScimUser delete(String id, int version) throws ScimResourceNotFoundException {
HttpHeaders headers = new HttpHeaders();
headers.set("If-Match", String.format("%d", version));
return restTemplate.exchange(baseUrl + "/User/{id}", HttpMethod.DELETE, new HttpEntity<Void>(headers),
ScimUser.class, id).getBody();
}
@Override
public int delete(String filter) {
throw new UnsupportedOperationException();
}
}