Git Product home page Git Product logo

Comments (3)

literallyjustroy avatar literallyjustroy commented on August 19, 2024

Also of note, the type is a String instead of an enum.

from okta-sdk-java.

duttkin avatar duttkin commented on August 19, 2024

Curious if there has been any progress on this issue as it is blocking me from using the API for creating an dpDiscoveryPolicyRule with an action containing the IdpPolicyRuleActionProvider.

It also looks like this issue is preventing the PolicyApi from populating the actions when retrieving the rule from the server as the actions providers object is always null.

from okta-sdk-java.

literallyjustroy avatar literallyjustroy commented on August 19, 2024

@duttkin This can be done directly using invokeApi until the proper solution is resolved:

private PolicyRule createOktaIdpDiscoveryRuleForOrg(OrganizationRecord orgRec) {
    final Policy idpDiscoveryPolicy = getOktaIdpDiscoveryPolicy();

    HashMap<String, Object> idpPolicyRuleMap = buildIdpPolicyRuleBody(orgRec);

    PolicyRule createdIdpPolicyRule = oktaPolicyApi.getApiClient()
        .invokeAPI(String.format("/api/v1/policies/%s/rules", idpDiscoveryPolicy.getId()),
                HttpMethod.POST.name(),
                null,
                null,
                null,
                idpPolicyRuleMap,
                new HashMap<>(),
                new HashMap<>(),
                new HashMap<>(),
                MediaType.APPLICATION_JSON_VALUE,
                MediaType.APPLICATION_JSON_VALUE,
                new String[]{"apiToken", "oauth2"},
                new TypeReference<>() {}
        );

    if (createdIdpPolicyRule == null || createdIdpPolicyRule.getId() == null) {
        throw new IllegalStateException("Failed to create Okta IDP Discovery Rule, no PolicyRule returned.");
    }

    orgRec.setOktaIdpDiscoveryRuleId(createdIdpPolicyRule.getId());

    return createdIdpPolicyRule;
}

private Policy getOktaIdpDiscoveryPolicy() {
    final List<Policy> idpDiscoveryPolicies = oktaPolicyApi.listPolicies(PolicyType.IDP_DISCOVERY.getValue(), null, null);

    // There should only be one IDP Discovery Policy. Each Organization will have its own Policy Rule
    if (idpDiscoveryPolicies.size() != 1) {
        throw new IllegalArgumentException("Unexpected IDP Discovery policy size of " + idpDiscoveryPolicies.size());
    }

    return idpDiscoveryPolicies.get(0);
}

private static HashMap<String, Object> buildIdpPolicyRuleBody(OrganizationRecord orgRec) {
    Map<String, Object> conditionsMap = buildRoutingRuleConditions(orgRec);
    Map<String, Object> actionsMap = buildRoutingRuleActions(orgRec);

    HashMap<String, Object> idpRoutingRuleMap = new HashMap<>();
    idpRoutingRuleMap.put("type", PolicyRuleType.IDP_DISCOVERY);
    idpRoutingRuleMap.put("name", "routingRuleNameLimit50SpecificToEachIDP");
    idpRoutingRuleMap.put("actions", actionsMap);
    idpRoutingRuleMap.put("conditions", conditionsMap);

    return idpRoutingRuleMap;
}

private static Map<String, Object> buildRoutingRuleActions(OrganizationRecord orgRec) {
    Map<String, Object> providerMap = new HashMap<>();
    providerMap.put("id", orgRec.getOktaIdpId());

    Map<String, Object> idpMap = new HashMap<>();
    idpMap.put("providers", List.of(providerMap));
    idpMap.put("idpSelectionType", "SPECIFIC");

    return Map.of("idp", idpMap);
}

private static Map<String, Object> buildRoutingRuleConditions(OrganizationRecord orgRec) {
    HashMap<String, String> patternMap = new HashMap<>();
    patternMap.put("matchType", "SUFFIX");
    patternMap.put("value", orgRec.getSpDomain());

    HashMap<String, Object> userIdentifierMap = new HashMap<>();
    userIdentifierMap.put("type", "IDENTIFIER");
    userIdentifierMap.put("patterns", List.of(patternMap));

    return Map.of("userIdentifier", userIdentifierMap);
}

from okta-sdk-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.