Skip to content

Commit 75c003f

Browse files
committed
add ability to get current user profile from CDA
1 parent 1bdaf35 commit 75c003f

4 files changed

Lines changed: 307 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2026 Hydrologic Engineering Center
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package mil.army.usace.hec.cwms.data.api.client.controllers;
26+
27+
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_HEADER_JSON;
28+
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;
29+
30+
import java.io.IOException;
31+
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
32+
import mil.army.usace.hec.cwms.data.api.client.model.User;
33+
import mil.army.usace.hec.cwms.http.client.ApiConnectionInfo;
34+
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilderImpl;
35+
import mil.army.usace.hec.cwms.http.client.HttpRequestResponse;
36+
import mil.army.usace.hec.cwms.http.client.request.HttpRequestExecutor;
37+
38+
public final class UserProfileController {
39+
40+
private static final String USER_PROFILE_ENDPOINT = "user/profile";
41+
42+
public User retrieveCurrentUserProfile(ApiConnectionInfo apiConnectionInfo)
43+
throws IOException {
44+
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, USER_PROFILE_ENDPOINT)
45+
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_JSON)
46+
.get();
47+
try (HttpRequestResponse response = executor.execute()) {
48+
return RadarObjectMapper.mapJsonToObject(response.getBody(), User.class);
49+
}
50+
}
51+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2026 Hydrologic Engineering Center
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package mil.army.usace.hec.cwms.data.api.client.controllers;
26+
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertFalse;
29+
import static org.junit.jupiter.api.Assertions.assertNotNull;
30+
31+
import java.io.IOException;
32+
import mil.army.usace.hec.cwms.data.api.client.model.User;
33+
import org.junit.jupiter.api.Test;
34+
35+
class TestUserProfileController extends TestController {
36+
37+
@Test
38+
void testRetrieveCatalog() throws IOException {
39+
String collect = readJsonFile("radar/v1/json/user_profile.json");
40+
mockHttpServer.enqueue(collect);
41+
mockHttpServer.start();
42+
User user = new UserProfileController().retrieveCurrentUserProfile(buildConnectionInfo());
43+
assertNotNull(user);
44+
assertEquals("M5HECTEST", user.getUserName());
45+
assertFalse(user.isCacAuth());
46+
assertFalse(user.getRoles().get("SWT").isEmpty());
47+
}
48+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"user-name": "M5HECTEST",
3+
"cac-auth": false,
4+
"roles": {
5+
"SWT": [
6+
"All Users",
7+
"CWMS DBA Users",
8+
"CWMS PD Users",
9+
"CWMS Users",
10+
"TS ID Creator"
11+
],
12+
"MVP": [
13+
"All Users",
14+
"CWMS DBA Users",
15+
"CWMS PD Users",
16+
"CWMS Users"
17+
],
18+
"HQ": [
19+
"All Users",
20+
"CWMS DBA Users",
21+
"CWMS PD Users",
22+
"CWMS Users"
23+
],
24+
"SPK": [
25+
"All Users",
26+
"CWMS DBA Users",
27+
"CWMS PD Users",
28+
"CWMS Users"
29+
]
30+
}
31+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2026 Hydrologic Engineering Center
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package mil.army.usace.hec.cwms.data.api.client.model;
26+
27+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
28+
import com.fasterxml.jackson.annotation.JsonProperty;
29+
import jakarta.validation.Valid;
30+
import java.util.HashMap;
31+
import java.util.List;
32+
import java.util.Map;
33+
import java.util.Objects;
34+
35+
/**
36+
* User
37+
*/
38+
@JsonIgnoreProperties(ignoreUnknown = true)
39+
@jakarta.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2025-12-19T13:08:07.460137300-08:00[America/Los_Angeles]")
40+
public class User {
41+
42+
@JsonProperty("user-name")
43+
private String userName = null;
44+
45+
@JsonProperty("principal")
46+
private String principal = null;
47+
48+
@JsonProperty("cac-auth")
49+
private Boolean cacAuth = null;
50+
51+
@JsonProperty("email")
52+
private String email = null;
53+
54+
@JsonProperty("roles")
55+
@Valid
56+
private Map<String, List<String>> roles = new HashMap<>();
57+
58+
public User userName(String userName) {
59+
this.userName = userName;
60+
return this;
61+
}
62+
63+
public String getUserName() {
64+
return userName;
65+
}
66+
67+
public void setUserName(String userName) {
68+
this.userName = userName;
69+
}
70+
71+
public User principal(String principal) {
72+
this.principal = principal;
73+
return this;
74+
}
75+
76+
public String getPrincipal() {
77+
return principal;
78+
}
79+
80+
public void setPrincipal(String principal) {
81+
this.principal = principal;
82+
}
83+
84+
public User cacAuth(Boolean cacAuth) {
85+
this.cacAuth = cacAuth;
86+
return this;
87+
}
88+
89+
public Boolean isCacAuth() {
90+
return cacAuth;
91+
}
92+
93+
public void setCacAuth(Boolean cacAuth) {
94+
this.cacAuth = cacAuth;
95+
}
96+
97+
public User email(String email) {
98+
this.email = email;
99+
return this;
100+
}
101+
102+
public String getEmail() {
103+
return email;
104+
}
105+
106+
public void setEmail(String email) {
107+
this.email = email;
108+
}
109+
110+
public User roles(Map<String, List<String>> roles) {
111+
this.roles = roles;
112+
return this;
113+
}
114+
115+
public User putRolesItem(String key, List<String> rolesItem) {
116+
if (this.roles == null) {
117+
this.roles = new HashMap<>();
118+
}
119+
this.roles.put(key, rolesItem);
120+
return this;
121+
}
122+
123+
public Map<String, List<String>> getRoles() {
124+
return roles;
125+
}
126+
127+
public void setRoles(Map<String, List<String>> roles) {
128+
this.roles = roles;
129+
}
130+
131+
@Override
132+
public boolean equals(Object o) {
133+
if (this == o) {
134+
return true;
135+
}
136+
if (o == null || getClass() != o.getClass()) {
137+
return false;
138+
}
139+
User user = (User) o;
140+
return this.userName == null || user.userName == null?Objects.equals(this.userName, user.userName):this.userName.equalsIgnoreCase(user.userName)
141+
&& this.principal == null || user.principal == null?Objects.equals(this.principal, user.principal):this.principal.equalsIgnoreCase(user.principal)
142+
&& Objects.equals(this.cacAuth, user.cacAuth)
143+
&& this.email == null || user.email == null?Objects.equals(this.email, user.email):this.email.equalsIgnoreCase(user.email)
144+
&& Objects.equals(this.roles, user.roles)
145+
;
146+
}
147+
148+
@Override
149+
public int hashCode() {
150+
return Objects.hash(userName==null?0:userName.toLowerCase(), principal==null?0:principal.toLowerCase(), cacAuth, email==null?0:email.toLowerCase(), roles);
151+
}
152+
153+
@Override
154+
public String toString() {
155+
StringBuilder sb = new StringBuilder();
156+
sb.append("class User {\n");
157+
158+
sb.append(" userName: ").append(toIndentedString(userName)).append("\n");
159+
sb.append(" principal: ").append(toIndentedString(principal)).append("\n");
160+
sb.append(" cacAuth: ").append(toIndentedString(cacAuth)).append("\n");
161+
sb.append(" email: ").append(toIndentedString(email)).append("\n");
162+
sb.append(" roles: ").append(toIndentedString(roles)).append("\n");
163+
sb.append("}");
164+
return sb.toString();
165+
}
166+
167+
/**
168+
* Convert the given object to string with each line indented by 4 spaces
169+
* (except the first line).
170+
*/
171+
private String toIndentedString(Object o) {
172+
if (o == null) {
173+
return "null";
174+
}
175+
return o.toString().replace("\n", "\n ");
176+
}
177+
}

0 commit comments

Comments
 (0)