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

Okta Password Policy #1315

Merged
merged 2 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.stormpath.sdk.directory;

import com.stormpath.sdk.resource.Resource;

import java.util.Date;
import java.util.Map;

public interface OktaPasswordPolicy extends Resource {

String getType();
String getId();
String getStatus();
String getName();
String getDescription();
int getPriority();
boolean getSystem();
Map<String, Object> getConditions();
Date getCreated();
Date getLastUpdated();
Map<String, Object> getSettings();
Map<String, Object> getDelegation();
Map<String, Object> getRules();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.stormpath.sdk.directory;

import com.stormpath.sdk.resource.CollectionResource;

public interface OktaPasswordPolicyList extends CollectionResource<OktaPasswordPolicy> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ public List<AccountStoreModel> getAccountStores(HttpServletRequest request) {
AccountStoreModelVisitor visitor =
new AccountStoreModelVisitor(accountStores, getAuthorizeBaseUri(request, app.getWebConfig()));

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

final AccountStore accountStore = mapping.getAccountStore();
final AccountStore accountStore = mapping.getAccountStore();

accountStore.accept(visitor);
accountStore.accept(visitor);
}
}

return visitor.getAccountStores();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.stormpath.sdk.impl.directory;

import com.stormpath.sdk.directory.OktaPasswordPolicy;
import com.stormpath.sdk.impl.ds.InternalDataStore;
import com.stormpath.sdk.impl.resource.AbstractInstanceResource;
import com.stormpath.sdk.impl.resource.BooleanProperty;
import com.stormpath.sdk.impl.resource.DateProperty;
import com.stormpath.sdk.impl.resource.IntegerProperty;
import com.stormpath.sdk.impl.resource.MapProperty;
import com.stormpath.sdk.impl.resource.Property;
import com.stormpath.sdk.impl.resource.StringProperty;

import java.util.Date;
import java.util.Map;

public class DefaultOktaPasswordPolicy extends AbstractInstanceResource implements OktaPasswordPolicy {

// SIMPLE PROPERTIES
static final StringProperty TYPE = new StringProperty("type");
static final StringProperty ID = new StringProperty("id");
static final StringProperty STATUS = new StringProperty("status");
static final StringProperty NAME = new StringProperty("name");
static final StringProperty DESCRIPTION = new StringProperty("description");
static final IntegerProperty PRIORITY = new IntegerProperty("priority");
static final BooleanProperty SYSTEM = new BooleanProperty("system");
static final DateProperty CREATED = new DateProperty("created");
static final DateProperty LAST_UPDATED = new DateProperty("lastUpdated");

// MAP Properties
static final MapProperty CONDITIONS = new MapProperty("conditions");
static final MapProperty SETTINGS = new MapProperty("settings");
static final MapProperty DELEGATION = new MapProperty("delegation");
static final MapProperty RULES = new MapProperty("rules");

private static final Map<String, Property> PROPERTY_DESCRIPTORS = createPropertyDescriptorMap(
TYPE, ID, STATUS, NAME, DESCRIPTION, PRIORITY, SYSTEM, CREATED, LAST_UPDATED, CONDITIONS, SETTINGS, DELEGATION, RULES
);

public DefaultOktaPasswordPolicy(InternalDataStore dataStore) {
super(dataStore);
}

public DefaultOktaPasswordPolicy(InternalDataStore dataStore, Map<String, Object> properties) {
super(dataStore, properties);
}

@Override
public Map<String, Property> getPropertyDescriptors() {
return PROPERTY_DESCRIPTORS;
}


@Override
public String getType() {
return getString(TYPE);
}

@Override
public String getId() {
return getString(ID);
}

@Override
public String getStatus() {
return getString(STATUS);
}

@Override
public String getName() {
return getString(NAME);
}

@Override
public String getDescription() {
return getString(DESCRIPTION);
}

@Override
public int getPriority() {
return getInt(PRIORITY);
}

@Override
public boolean getSystem() {
return getBoolean(SYSTEM);
}

@Override
public Map<String, Object> getConditions() {
return getMap(CONDITIONS);
}

@Override
public Date getCreated() {
return getDateProperty(CREATED);
}

@Override
public Date getLastUpdated() {
return getDateProperty(LAST_UPDATED);
}

@Override
public Map<String, Object> getSettings() {
return getMap(SETTINGS);
}

@Override
public Map<String, Object> getDelegation() {
return getMap(DELEGATION);
}

@Override
public Map<String, Object> getRules() {
return getMap(RULES);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.stormpath.sdk.impl.directory;

import com.stormpath.sdk.directory.OktaPasswordPolicy;
import com.stormpath.sdk.directory.OktaPasswordPolicyList;
import com.stormpath.sdk.impl.ds.InternalDataStore;
import com.stormpath.sdk.impl.resource.AbstractCollectionResource;
import com.stormpath.sdk.impl.resource.ArrayProperty;
import com.stormpath.sdk.impl.resource.Property;

import java.util.Map;

public class DefaultOktaPasswordPolicyList extends AbstractCollectionResource<OktaPasswordPolicy> implements OktaPasswordPolicyList {

private static final ArrayProperty<OktaPasswordPolicy> ITEMS = new ArrayProperty<>("items", OktaPasswordPolicy.class);

private static final Map<String, Property> PROPERTY_DESCRIPTORS = createPropertyDescriptorMap(OFFSET, LIMIT, ITEMS);

public DefaultOktaPasswordPolicyList(InternalDataStore dataStore) {
super(dataStore);
}

public DefaultOktaPasswordPolicyList(InternalDataStore dataStore, Map<String, Object> properties) {
super(dataStore, properties);
}

public DefaultOktaPasswordPolicyList(InternalDataStore dataStore, Map<String, Object> properties, Map<String, Object> queryParams) {
super(dataStore, properties, queryParams);
}

@Override
public Map<String, Property> getPropertyDescriptors() {
return PROPERTY_DESCRIPTORS;
}

@Override
protected Class<OktaPasswordPolicy> getItemType() {
return OktaPasswordPolicy.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import com.stormpath.sdk.directory.Directory;
import com.stormpath.sdk.directory.DirectoryOptions;
import com.stormpath.sdk.directory.DirectoryStatus;
import com.stormpath.sdk.directory.OktaPasswordPolicy;
import com.stormpath.sdk.directory.PasswordPolicy;
import com.stormpath.sdk.directory.OktaPasswordPolicyList;
import com.stormpath.sdk.directory.PasswordStrength;
import com.stormpath.sdk.group.CreateGroupRequest;
import com.stormpath.sdk.group.Group;
import com.stormpath.sdk.group.GroupCriteria;
Expand All @@ -21,6 +24,9 @@
import com.stormpath.sdk.impl.resource.AbstractResource;
import com.stormpath.sdk.impl.resource.Property;
import com.stormpath.sdk.lang.Assert;
import com.stormpath.sdk.mail.EmailStatus;
import com.stormpath.sdk.mail.ModeledEmailTemplateList;
import com.stormpath.sdk.mail.UnmodeledEmailTemplateList;
import com.stormpath.sdk.organization.OrganizationAccountStoreMappingCriteria;
import com.stormpath.sdk.organization.OrganizationAccountStoreMappingList;
import com.stormpath.sdk.organization.OrganizationCriteria;
Expand Down Expand Up @@ -187,7 +193,10 @@ public Provider getProvider() {

@Override
public PasswordPolicy getPasswordPolicy() {
throw new UnsupportedOperationException("Not implemented.");
String passwordPolicyHref = getHref() + "/policies?type=PASSWORD";
OktaPasswordPolicyList policies = getDataStore().getResource(passwordPolicyHref, OktaPasswordPolicyList.class);
OktaPasswordPolicy oktaPasswordPolicy = policies.single();
return transformOktaPasswordPolicy(oktaPasswordPolicy);
}

@Override
Expand Down Expand Up @@ -234,4 +243,79 @@ public OrganizationAccountStoreMappingList getOrganizationAccountStoreMappings(O
public Schema getAccountSchema() {
throw new UnsupportedOperationException("Not implemented.");
}

@SuppressWarnings("unchecked")
private PasswordPolicy transformOktaPasswordPolicy(OktaPasswordPolicy oktaPasswordPolicy) {
// ref: http://developer.okta.com/docs/api/resources/policy.html#GroupPasswordPolicy
final Map<String, Object> strengthMap = (Map<String, Object>)
((Map<String, Object>)oktaPasswordPolicy.getSettings().get("password")).get("complexity");
PasswordPolicy ret = new PasswordPolicy() {
@Override
public int getResetTokenTtlHours() {
return 0;
}

@Override
public PasswordPolicy setResetTokenTtlHours(int resetTokenTtl) {
return null;
}

@Override
public EmailStatus getResetEmailStatus() {
return null;
}

@Override
public PasswordPolicy setResetEmailStatus(EmailStatus status) {
return null;
}

@Override
public EmailStatus getResetSuccessEmailStatus() {
return null;
}

@Override
public PasswordPolicy setResetSuccessEmailStatus(EmailStatus status) {
return null;
}

@Override
public PasswordStrength getStrength() {
PasswordStrength p = new DefaultPasswordStrength(getDataStore());

p.setMinLength((Integer) strengthMap.get("minLength"));
p.setMinLowerCase((Integer) strengthMap.get("minLowerCase"));
p.setMinUpperCase((Integer) strengthMap.get("minUpperCase"));
p.setMinNumeric((Integer) strengthMap.get("minNumber"));
p.setMinSymbol((Integer) strengthMap.get("minSymbol"));
p.setMaxLength(1024);
p.setMinDiacritic(0);
p.setPreventReuse(0);

return p;
}

@Override
public ModeledEmailTemplateList getResetEmailTemplates() {
return null;
}

@Override
public UnmodeledEmailTemplateList getResetSuccessEmailTemplates() {
return null;
}

@Override
public String getHref() {
return "local";
}

@Override
public void save() {

}
};
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.stormpath.sdk.impl.ds.cache.ReadCacheFilter;
import com.stormpath.sdk.impl.ds.cache.WriteCacheFilter;
import com.stormpath.sdk.impl.error.DefaultError;
import com.stormpath.sdk.impl.error.OktaError;
import com.stormpath.sdk.impl.http.CanonicalUri;
import com.stormpath.sdk.impl.http.HttpHeaders;
import com.stormpath.sdk.impl.http.HttpHeadersHolder;
Expand Down Expand Up @@ -65,6 +66,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
Expand Down Expand Up @@ -105,6 +107,8 @@ public class DefaultDataStore implements InternalDataStore {

private static final boolean COLLECTION_CACHING_ENABLED = false; //EXPERIMENTAL - set to true only while developing.

private static boolean oktaEnabled;

private final RequestExecutor requestExecutor;
private final ResourceFactory resourceFactory;
private final MapMarshaller mapMarshaller;
Expand Down Expand Up @@ -160,6 +164,12 @@ public DefaultDataStore(RequestExecutor requestExecutor, BaseUrlResolver baseUrl
this.cacheResolver = new DefaultCacheResolver(this.cacheManager, new DefaultCacheRegionNameResolver());
this.apiKeyResolver = apiKeyResolver;

if (baseUrlResolver.getBaseUrl().toLowerCase().contains("okta")) {
oktaEnabled = true;
} else {
oktaEnabled = false;
}

ReferenceFactory referenceFactory = new ReferenceFactory();
this.resourceConverter = new DefaultResourceConverter(referenceFactory);

Expand Down Expand Up @@ -600,7 +610,15 @@ private Response execute(Request request) throws ResourceException {
body.put(DefaultError.REQUEST_ID.getName(), requestId);
}

DefaultError error = new DefaultError(body);
com.stormpath.sdk.error.Error error;
if (oktaEnabled) {
OktaError oktaError = new OktaError(body);
// Okta Error response doesn't have status
oktaError.setProperty(OktaError.STATUS.getName(), response.getHttpStatus());
error = oktaError;
} else {
error = new DefaultError(body);
}

throw new ResourceException(error);
}
Expand Down
Loading