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

Commit 54021ea

Browse files
committed
Corrected ExternalAccountStoreModelFactory login test
1 parent edf17fa commit 54021ea

File tree

4 files changed

+67
-14
lines changed

4 files changed

+67
-14
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public boolean isNotAllowedIfAuthenticated() {
174174
protected void appendModel(HttpServletRequest request, HttpServletResponse response, Form form, List<ErrorModel> errors,
175175
Map<String, Object> model) {
176176

177-
// final List<AccountStoreModel> accountStores = accountStoreModelFactory.getAccountStores(request);
177+
178178

179179
// 748: If stormpath.web.idSite.enabled is false and stormpath.web.callback.enabled is false AND
180180
// there are SAML directories mapped to the application, that is a configuration error.
@@ -189,8 +189,8 @@ protected void appendModel(HttpServletRequest request, HttpServletResponse respo
189189
errors.add(ErrorModel.builder().setStatus(HttpServletResponse.SC_OK).setMessage(errorMsg).build());
190190
}
191191
}
192-
193-
// model.put("accountStores", accountStores);
192+
final List<AccountStoreModel> accountStores = accountStoreModelFactory.getAccountStores(request);
193+
model.put("accountStores", accountStores);
194194

195195
if (isHtmlPreferred(request, response)) {
196196
model.put("forgotPasswordEnabled", forgotPasswordEnabled);

extensions/servlet/src/main/java/com/stormpath/sdk/servlet/mvc/provider/ExternalAccountStoreModelFactory.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,11 @@ public List<AccountStoreModel> getAccountStores(HttpServletRequest request) {
5959
AccountStoreModelVisitor visitor =
6060
new AccountStoreModelVisitor(accountStores, getAuthorizeBaseUri(request, app.getWebConfig()));
6161

62-
// TODO - if introduced for Okta. Need to deal with for real when we add social support
63-
if (mappings.getHref() != null) {
64-
for (ApplicationAccountStoreMapping mapping : mappings) {
62+
for (ApplicationAccountStoreMapping mapping : mappings) {
6563

66-
final AccountStore accountStore = mapping.getAccountStore();
64+
final AccountStore accountStore = mapping.getAccountStore();
6765

68-
accountStore.accept(visitor);
69-
}
66+
accountStore.accept(visitor);
7067
}
7168

7269
return visitor.getAccountStores();

extensions/servlet/src/test/groovy/com/stormpath/sdk/servlet/mvc/LoginControllerTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class LoginControllerTest {
195195

196196
List<AccountStoreModel> accountStores = new ArrayList<AccountStoreModel>()
197197
accountStores.add(new DefaultAccountStoreModel(null, new DefaultProviderModel('foo', 'saml'), null))
198-
// expect(accountStoreModelFactory.getAccountStores(request)).andReturn(accountStores)
198+
expect(accountStoreModelFactory.getAccountStores(request)).andReturn(accountStores)
199199
expect(request.getAttribute(UserAgents.USER_AGENT_REQUEST_ATTRIBUTE_NAME)).andReturn new DefaultUserAgent(request)
200200
expect(request.getParameter("status")).andReturn null
201201
expect(request.getHeader("Accept")).andReturn "text/html"

impl/src/main/java/com/stormpath/sdk/impl/application/okta/OktaApplication.java

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@
7575
import com.stormpath.sdk.saml.SamlPolicy;
7676
import com.stormpath.sdk.tenant.Tenant;
7777

78+
import java.util.Collection;
79+
import java.util.Collections;
7880
import java.util.Date;
81+
import java.util.Iterator;
7982
import java.util.LinkedHashMap;
8083
import java.util.List;
8184
import java.util.Map;
@@ -84,7 +87,7 @@ public class OktaApplication extends AbstractResource implements Application, OA
8487

8588
private final Directory OKTA_TENANT_DIR;
8689

87-
private final ApplicationAccountStoreMappingList applicationAccountStoreMappingList;
90+
private final ApplicationAccountStoreMappingCollectionBackedList applicationAccountStoreMappingList;
8891

8992
private String name;
9093

@@ -101,9 +104,14 @@ public OktaApplication(InternalDataStore dataStore, Map<String, Object> properti
101104
mappingProperties.put("application", this);
102105
mappingProperties.put("accountStore", OKTA_TENANT_DIR);
103106

104-
ApplicationAccountStoreMapping mapping = new DefaultApplicationAccountStoreMapping(dataStore, mappingProperties);
105-
106-
applicationAccountStoreMappingList = AbstractCollectionResource.singletonCollectionResource(dataStore, DefaultApplicationAccountStoreMappingList.class, mapping);
107+
ApplicationAccountStoreMapping mapping = new DefaultApplicationAccountStoreMapping(dataStore, mappingProperties) {
108+
@Override
109+
public AccountStore getAccountStore() {
110+
return OKTA_TENANT_DIR;
111+
}
112+
};
113+
mapping.setAccountStore(OKTA_TENANT_DIR);
114+
applicationAccountStoreMappingList = new ApplicationAccountStoreMappingCollectionBackedList(Collections.singletonList(mapping));
107115
}
108116

109117
@Override
@@ -577,4 +585,52 @@ public IdSiteAuthenticator createIdSiteAuthenticator() {
577585
public OAuthTokenRevocator createOAuhtTokenRevocator() {
578586
return new DefaultOAuthTokenRevocator(this, getDataStore(), "/oauth2/v1/token");
579587
}
588+
589+
590+
public static class ApplicationAccountStoreMappingCollectionBackedList implements ApplicationAccountStoreMappingList {
591+
592+
final private Collection<ApplicationAccountStoreMapping> accountStoreMappings;
593+
594+
public ApplicationAccountStoreMappingCollectionBackedList(Collection<ApplicationAccountStoreMapping> accountStoreMappings) {
595+
this.accountStoreMappings = accountStoreMappings;
596+
}
597+
598+
@Override
599+
public String getHref() {
600+
return null;
601+
}
602+
603+
@Override
604+
public int getOffset() {
605+
return 0;
606+
}
607+
608+
@Override
609+
public int getLimit() {
610+
return getSize();
611+
}
612+
613+
@Override
614+
public int getSize() {
615+
return accountStoreMappings.size();
616+
}
617+
618+
@Override
619+
public ApplicationAccountStoreMapping single() {
620+
Iterator<ApplicationAccountStoreMapping> iterator = iterator();
621+
if (!iterator.hasNext()) {
622+
throw new IllegalStateException("This list is empty while it was expected to contain one (and only one) element.");
623+
}
624+
ApplicationAccountStoreMapping itemToReturn = iterator.next();
625+
if (iterator.hasNext()) {
626+
throw new IllegalStateException("Only a single resource was expected, but this list contains more than one item.");
627+
}
628+
return itemToReturn;
629+
}
630+
631+
@Override
632+
public Iterator<ApplicationAccountStoreMapping> iterator() {
633+
return accountStoreMappings.iterator();
634+
}
635+
}
580636
}

0 commit comments

Comments
 (0)