|
1 | 1 | package com.stormpath.sdk.impl.okta; |
2 | 2 |
|
3 | 3 | import com.stormpath.sdk.account.AccountStatus; |
| 4 | +import com.stormpath.sdk.group.Group; |
4 | 5 | import com.stormpath.sdk.lang.Collections; |
5 | 6 | import com.stormpath.sdk.lang.Objects; |
6 | 7 | import com.stormpath.sdk.lang.Strings; |
@@ -139,13 +140,11 @@ public static Map<String, Object> toAccount(Map<String, Object> userMap, String |
139 | 140 | } |
140 | 141 |
|
141 | 142 | // _links.self.href -> href |
142 | | - Map<String, Object> linksMap = getPropertyMap(userMap,OKTA_LINKS); |
143 | | - if (!Collections.isEmpty(linksMap)) { |
144 | | - Map<String, Object> self = getPropertyMap(linksMap, OKTA_SELF); |
145 | | - if (!Collections.isEmpty(self)) { |
146 | | - nullSafePut(accountMap, STORMPATH_HREF, self.get(OKTA_HREF)); |
147 | | - } |
148 | | - } |
| 143 | + nullSafePut(accountMap, STORMPATH_HREF, getOktaHref(userMap)); |
| 144 | + |
| 145 | + Map<String, Object> groupsMap = new LinkedHashMap<>(); |
| 146 | + groupsMap.put(STORMPATH_HREF, accountMap.get(STORMPATH_HREF) + "/groups"); |
| 147 | + accountMap.put("groups", groupsMap); |
149 | 148 |
|
150 | 149 | return accountMap; |
151 | 150 | } |
@@ -189,6 +188,19 @@ public static Map<String, Object> toUser(Map<String, Object> accountMap) { |
189 | 188 | return userMap; |
190 | 189 | } |
191 | 190 |
|
| 191 | + private static String getOktaHref(Map<String, Object> properties) { |
| 192 | + |
| 193 | + // _links.self.href -> href |
| 194 | + Map<String, Object> linksMap = getPropertyMap(properties,OKTA_LINKS); |
| 195 | + if (!Collections.isEmpty(linksMap)) { |
| 196 | + Map<String, Object> self = getPropertyMap(linksMap, OKTA_SELF); |
| 197 | + if (!Collections.isEmpty(self)) { |
| 198 | + return (String) self.get(OKTA_HREF); |
| 199 | + } |
| 200 | + } |
| 201 | + return null; |
| 202 | + } |
| 203 | + |
192 | 204 | private static String buildFullName(Object firstName, Object lastName) { |
193 | 205 | return (Objects.getDisplayString(firstName) + " " + Objects.getDisplayString(lastName)).trim(); |
194 | 206 | } |
@@ -258,4 +270,32 @@ private static Map<String, Object> trimMap(Map<String, Object> map, String... ke |
258 | 270 |
|
259 | 271 | return result; |
260 | 272 | } |
| 273 | + |
| 274 | + public static Map<String, Object> toStormpathGroup(Map<String, Object> oktaGroup) { |
| 275 | + |
| 276 | + if (Collections.isEmpty(oktaGroup) || !oktaGroup.containsKey(OKTA_PROFILE)) { |
| 277 | + return oktaGroup; |
| 278 | + } |
| 279 | + |
| 280 | + Map<String, Object> stormpathGroup = new LinkedHashMap<>(); |
| 281 | + |
| 282 | + nullSafePut(stormpathGroup, STORMPATH_CREATED_AT, oktaGroup.get(OKTA_CREATED)); |
| 283 | + nullSafePut(stormpathGroup, STORMPATH_MODIFIED_AT, oktaGroup.get(OKTA_LAST_UPDATED)); |
| 284 | + |
| 285 | + stormpathGroup.put(STORMPATH_STATUS, "ENABLED"); |
| 286 | + |
| 287 | + Map<String, Object> profile = getPropertyMap(oktaGroup, OKTA_PROFILE); |
| 288 | + if (!Collections.isEmpty(profile)) { |
| 289 | + nullSafePut(stormpathGroup, "name", profile.get("name")); |
| 290 | + nullSafePut(stormpathGroup, "description", profile.get("description")); |
| 291 | + } |
| 292 | + |
| 293 | + // _links.self.href -> href |
| 294 | + nullSafePut(stormpathGroup, STORMPATH_HREF, "/api/v1/groups/" + oktaGroup.get("id")); |
| 295 | + |
| 296 | + stormpathGroup.put(STORMPATH_CUSTOM_DATA, new LinkedHashMap<String, Object>()); |
| 297 | + |
| 298 | + return stormpathGroup; |
| 299 | + } |
| 300 | + |
261 | 301 | } |
0 commit comments