Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit ae4bd06

Browse files
committed
1309: Registration is working
initial pass, Registration form works, creates Okta users * Password not set yet * Login page will render once, then throw a 500 LocalApplication needs work, getDomainName() returns 'hack' this config needs to come from a YAML config file
1 parent 37a0cc4 commit ae4bd06

File tree

5 files changed

+66
-15
lines changed

5 files changed

+66
-15
lines changed

extensions/servlet/src/main/java/com/stormpath/sdk/servlet/mvc/FormController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ protected ViewModel doPost(HttpServletRequest request, HttpServletResponse respo
232232
validate(request, response, form);
233233
return onValidSubmit(request, response, form);
234234
} catch (Exception e) {
235+
log.warn("Failure to post", e);
235236
return onErrorSubmit(request, response, form, e);
236237
}
237238
}

impl/src/main/java/com/stormpath/sdk/impl/application/AbstractAccountStoreMapping.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import com.stormpath.sdk.directory.AccountStore;
2020
import com.stormpath.sdk.directory.Directory;
2121
import com.stormpath.sdk.group.Group;
22+
import com.stormpath.sdk.impl.directory.OktaDirectory;
2223
import com.stormpath.sdk.impl.ds.InternalDataStore;
2324
import com.stormpath.sdk.impl.resource.*;
2425
import com.stormpath.sdk.organization.Organization;
26+
import com.stormpath.sdk.resource.Resource;
2527

2628
import java.util.Map;
2729

@@ -57,17 +59,30 @@ public AccountStore getAccountStore() {
5759
accountStore = getDataStore().getResource(href, Group.class);
5860
} else if (href.contains("/organizations/")){
5961
accountStore = getDataStore().getResource(href, Organization.class);
62+
} else if (href.contains("/api/v1")){
63+
accountStore = new OktaDirectory(getDataStore());
6064
}
6165
return accountStore;
6266
}
6367

6468
private String getAccountStoreHref() {
65-
Map<String, String> map = (Map<String, String>) getProperty(ACCOUNT_STORE.getName());
66-
String href = null;
67-
if (map != null && !map.isEmpty()) {
68-
href = map.get(HREF_PROP_NAME);
69+
Object accountStoreRaw = getProperty(ACCOUNT_STORE.getName());
70+
71+
if (accountStoreRaw instanceof Map) {
72+
Map<String, String> map = (Map<String, String>) accountStoreRaw;
73+
String href = null;
74+
if (map != null && !map.isEmpty()) {
75+
href = map.get(HREF_PROP_NAME);
76+
}
77+
return href;
78+
}
79+
80+
if (accountStoreRaw instanceof Resource) {
81+
return ((Resource) accountStoreRaw).getHref();
82+
}
83+
else {
84+
throw new UnsupportedOperationException("Could not find 'href' for account store.");
6985
}
70-
return href;
7186
}
7287

7388
public AccountStoreMapping setAccountStore(AccountStore accountStore) {

impl/src/main/java/com/stormpath/sdk/impl/application/LocalApplication.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public Date getModifiedAt() {
371371

372372
@Override
373373
public String getDomainName() {
374-
throw new UnsupportedOperationException("getDomainName() method hasn't been implemented.");
374+
return "hack";
375375
}
376376

377377
@Override
@@ -386,7 +386,7 @@ public ApplicationWebConfig setDnsLabel(String dnsLabel) {
386386

387387
@Override
388388
public ApplicationWebConfigStatus getStatus() {
389-
throw new UnsupportedOperationException("getStatus() method hasn't been implemented.");
389+
return ApplicationWebConfigStatus.ENABLED;
390390
}
391391

392392
@Override
@@ -416,7 +416,19 @@ public RegisterConfig getRegister() {
416416

417417
@Override
418418
public LoginConfig getLogin() {
419-
throw new UnsupportedOperationException("getLogin() method hasn't been implemented.");
419+
return new LoginConfig() {
420+
private boolean enabled = true;
421+
@Override
422+
public LoginConfig setEnabled(Boolean enabled) {
423+
this.enabled = enabled;
424+
return this;
425+
}
426+
427+
@Override
428+
public Boolean isEnabled() {
429+
return enabled;
430+
}
431+
};
420432
}
421433

422434
@Override

impl/src/main/java/com/stormpath/sdk/impl/ds/DefaultResourceConverter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package com.stormpath.sdk.impl.ds;
1818

19+
import com.stormpath.sdk.account.Account;
1920
import com.stormpath.sdk.directory.CustomData;
2021
import com.stormpath.sdk.impl.authc.BasicLoginAttempt;
22+
import com.stormpath.sdk.impl.okta.OktaUserAccountConverter;
2123
import com.stormpath.sdk.impl.resource.AbstractResource;
2224
import com.stormpath.sdk.impl.resource.ReferenceFactory;
2325
import com.stormpath.sdk.lang.Assert;
@@ -70,6 +72,11 @@ private LinkedHashMap<String, Object> toMap(final AbstractResource resource, boo
7072
props.put(propName, value);
7173
}
7274

75+
// Convert Stormpath Account to Okta User map
76+
if (resource instanceof Account) {
77+
props = new LinkedHashMap<>(new OktaUserAccountConverter().toUser(props));
78+
}
79+
7380
return props;
7481
}
7582

impl/src/main/java/com/stormpath/sdk/impl/okta/OktaUserAccountConverter.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.stormpath.sdk.account.AccountStatus;
44
import com.stormpath.sdk.lang.Collections;
55
import com.stormpath.sdk.lang.Objects;
6+
import com.stormpath.sdk.lang.Strings;
67
import com.stormpath.sdk.okta.UserStatus;
78

89
import java.util.LinkedHashMap;
@@ -18,7 +19,7 @@ public class OktaUserAccountConverter {
1819
/*
1920
Stormpath Account field | Okta User field
2021
-----------------------------|--------------------------------
21-
href | <generated>
22+
href | _links.self.href
2223
username | profile.login
2324
email | profile.email
2425
password | credentials.password.value
@@ -99,6 +100,15 @@ public Map<String, Object> toAccount(Map<String, Object> userMap) {
99100
accountMap.put("status", fromUserStatus(userMap.get("status")));
100101
}
101102

103+
// _links.self.href -> href
104+
Map<String, Object> linksMap = (Map<String, Object>) userMap.get("_links");
105+
if (!Collections.isEmpty(linksMap)) {
106+
Map<String, Object> self = (Map<String, Object>) linksMap.get("self");
107+
if (!Collections.isEmpty(self)) {
108+
nullSafePut(accountMap, "href", self.get("href"));
109+
}
110+
}
111+
102112
// pretty sure this logic is NOT needed when mapping User -> Account
103113
// Map<String, Object> credentialsMap = (Map<String, Object>) userMap.get("credentials");
104114
// if (!Collections.isEmpty(profileMap)) {
@@ -117,12 +127,16 @@ public Map<String, Object> toUser(Map<String, Object> accountMap) {
117127
Map<String, Object> profileMap = new LinkedHashMap<>();
118128
userMap.put("profile", profileMap);
119129

120-
nullSafePut(userMap, "login", accountMap.get("username"));
121-
nullSafePut(userMap, "email", accountMap.get("email"));
130+
String username = (String) accountMap.get("username");
131+
if (!Strings.hasText(username)) {
132+
username = (String) accountMap.get("email");
133+
}
134+
nullSafePut(profileMap, "login", username);
135+
nullSafePut(profileMap, "email", accountMap.get("email"));
122136

123-
nullSafePut(userMap, "firstName", accountMap.get("givenName"));
124-
nullSafePut(userMap, "middleName", accountMap.get("middleName"));
125-
nullSafePut(userMap, "lastName", accountMap.get("surname"));
137+
nullSafePut(profileMap, "firstName", accountMap.get("givenName"));
138+
nullSafePut(profileMap, "middleName", accountMap.get("middleName"));
139+
nullSafePut(profileMap, "lastName", accountMap.get("surname"));
126140
// nullSafePut(userMap, "displayName", accountMap.get("fullName")); // generated field from Stormpath
127141
nullSafePut(userMap, "created", accountMap.get("createdAt"));
128142
nullSafePut(userMap, "lastUpdated", accountMap.get("modifiedAt"));
@@ -140,7 +154,9 @@ public Map<String, Object> toUser(Map<String, Object> accountMap) {
140154
}
141155

142156
// custom data, just drop it in profile map
143-
profileMap.putAll((Map<String, Object>)accountMap.get("customData"));
157+
if (accountMap.containsKey("customData")) {
158+
profileMap.putAll((Map<String, Object>) accountMap.get("customData"));
159+
}
144160

145161
return userMap;
146162
}

0 commit comments

Comments
 (0)