Search in sources :

Example 1 with DiscoverabilityLevel

use of io.apiman.manager.api.beans.idm.DiscoverabilityLevel in project apiman by apiman.

the class AbstractSecurityContext method getDiscoverabilities.

private Set<DiscoverabilityLevel> getDiscoverabilities() {
    HttpServletRequest request = servletRequest.get();
    if (request.getRemoteUser() != null) {
        Set<DiscoverabilityLevel> discoverabilities = new HashSet<>(4);
        discoverabilityConfig.getSourceToDiscoverability().forEach((source, discoverabilityConfig) -> {
            switch(source) {
                case IDM_ROLE:
                    if (request.isUserInRole(discoverabilityConfig.getName())) {
                        discoverabilities.addAll(discoverabilityConfig.getDiscoverabilities());
                    }
                    break;
                case IDM_ATTRIBUTE:
                case APIMAN_ROLE:
                case APIMAN_PERMISSION:
                    throw new UnsupportedOperationException("Support for " + source + " not available on this platform.");
                default:
                    throw new IllegalStateException("Unexpected value: " + source);
            }
        });
        // TODO(msavy): make default discoverability configurable, perhaps?
        if (discoverabilities.isEmpty()) {
            discoverabilities.add(DiscoverabilityLevel.PORTAL);
            discoverabilities.add(DiscoverabilityLevel.ANONYMOUS);
        }
        return discoverabilities;
    } else {
        return Set.of(DiscoverabilityLevel.PORTAL, DiscoverabilityLevel.ANONYMOUS);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DiscoverabilityLevel(io.apiman.manager.api.beans.idm.DiscoverabilityLevel) HashSet(java.util.HashSet)

Example 2 with DiscoverabilityLevel

use of io.apiman.manager.api.beans.idm.DiscoverabilityLevel in project apiman by apiman.

the class ApiVersionDiscoverabilityTrigger method insertOrUpdate.

private void insertOrUpdate(Connection conn, ResultSet oldRow, ResultSet newRow) throws SQLException {
    String apiOrgId = newRow.getString("api_org_id");
    String apiId = newRow.getString("api_id");
    String apiVersion = newRow.getString("version");
    DiscoverabilityLevel level = Optional.ofNullable(newRow.getString("discoverability")).map(DiscoverabilityLevel::valueOf).orElse(DiscoverabilityLevel.ORG_MEMBERS);
    String pdeKey = String.join(":", apiOrgId, apiId, apiVersion);
    if (oldRow != null) {
        DiscoverabilityLevel oldLevel = Optional.ofNullable(oldRow.getString("discoverability")).map(DiscoverabilityLevel::valueOf).orElse(DiscoverabilityLevel.ORG_MEMBERS);
        // If no change, just exit.
        if (oldLevel == level) {
            return;
        }
    }
    Jdbi.create(conn).withHandle(h -> h.createUpdate("MERGE INTO discoverability(id, org_id, api_id, api_version, plan_id, plan_version, discoverability) KEY(id) " + "VALUES (:id, :orgId, :apiId, :apiVersion, NULL, NULL, :discoverability)").bind("id", pdeKey).bind("orgId", apiOrgId).bind("apiId", apiId).bind("apiVersion", apiVersion).bind("discoverability", level).execute());
}
Also used : DiscoverabilityLevel(io.apiman.manager.api.beans.idm.DiscoverabilityLevel)

Example 3 with DiscoverabilityLevel

use of io.apiman.manager.api.beans.idm.DiscoverabilityLevel in project apiman by apiman.

the class ApiPlanDiscoverabilityTrigger method insertOrUpdate.

private void insertOrUpdate(Connection conn, ResultSet oldRow, ResultSet newRow) throws SQLException {
    Long apiVersionId = newRow.getLong("api_version_id");
    String planId = newRow.getString("plan_id");
    String planVersion = newRow.getString("version");
    DiscoverabilityLevel level = Optional.ofNullable(newRow.getString("discoverability")).map(DiscoverabilityLevel::valueOf).orElse(DiscoverabilityLevel.ORG_MEMBERS);
    Jdbi jdbi = Jdbi.create(conn);
    FlatApiVersionBeanView av = jdbi.withHandle(h -> h.createQuery("select avb.* FROM api_versions avb WHERE avb.id = :id").bind("id", apiVersionId)).mapToBean(FlatApiVersionBeanView.class).first();
    String pdeKey = String.join(":", av.getApiOrgId(), av.getApiId(), av.getVersion(), planId, planVersion);
    if (oldRow != null) {
        DiscoverabilityLevel oldLevel = Optional.ofNullable(oldRow.getString("discoverability")).map(DiscoverabilityLevel::valueOf).orElse(DiscoverabilityLevel.ORG_MEMBERS);
        // If no change, just exit.
        if (oldLevel == level) {
            return;
        }
    }
    jdbi.withHandle(h -> h.createUpdate("MERGE INTO discoverability(id, org_id, api_id, api_version, plan_id, plan_version, discoverability) KEY(id) " + "VALUES (:id, :orgId, :apiId, :apiVersion, :planId, :planVersion, :discoverability)").bind("id", pdeKey).bind("orgId", av.getApiOrgId()).bind("apiId", av.getApiId()).bind("apiVersion", av.getVersion()).bind("planId", planId).bind("planVersion", planVersion).bind("discoverability", level).execute());
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) DiscoverabilityLevel(io.apiman.manager.api.beans.idm.DiscoverabilityLevel)

Aggregations

DiscoverabilityLevel (io.apiman.manager.api.beans.idm.DiscoverabilityLevel)3 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Jdbi (org.jdbi.v3.core.Jdbi)1