Search in sources :

Example 1 with Key

use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.

the class OAuth2ResourceInterceptor method setPublicURL.

private void setPublicURL(Exchange exc) {
    String xForwardedProto = exc.getRequest().getHeader().getFirstValue(Header.X_FORWARDED_PROTO);
    boolean isHTTPS = xForwardedProto != null ? "https".equals(xForwardedProto) : exc.getRule().getSslInboundContext() != null;
    publicURL = (isHTTPS ? "https://" : "http://") + exc.getOriginalHostHeader();
    RuleKey key = exc.getRule().getKey();
    if (!key.isPathRegExp() && key.getPath() != null)
        publicURL += key.getPath();
    normalizePublicURL();
    initPublicURLOnFirstExchange = false;
}
Also used : RuleKey(com.predic8.membrane.core.rules.RuleKey)

Example 2 with Key

use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.

the class NamespaceInfo method writeInfo.

public void writeInfo(Model m) {
    try {
        FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/membrane.namespaces");
        OutputStream oo = o.openOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(oo);
        try {
            Properties p = new Properties();
            int i = 1;
            for (MainInfo mi : m.getMains()) {
                String key = "schema" + (i++);
                p.put(key + "-targetNamespace", mi.getAnnotation().targetNamespace());
                p.put(key + "-outputPackage", mi.getAnnotation().outputPackage());
                p.put(key + "-outputName", mi.getAnnotation().outputName());
            }
            p.store(bos, "Autogenerated by " + getClass().getName());
        } finally {
            bos.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : MainInfo(com.predic8.membrane.annot.model.MainInfo) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileObject(javax.tools.FileObject) IOException(java.io.IOException) Properties(java.util.Properties) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with Key

use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.

the class RuleManager method getMatchingRule.

public Rule getMatchingRule(String hostHeader, String method, String uri, String version, int port, String localIP) {
    for (Rule rule : rules) {
        RuleKey key = rule.getKey();
        log.debug("Host from rule: " + key.getHost() + ";   Host from parameter rule key: " + hostHeader);
        if (!rule.isActive())
            continue;
        if (!key.matchesVersion(version))
            continue;
        if (key.getIp() != null && !key.getIp().equals(localIP))
            continue;
        if (!key.matchesHostHeader(hostHeader))
            continue;
        if (key.getPort() != -1 && port != -1 && key.getPort() != port)
            continue;
        if (!key.getMethod().equals(method) && !key.isMethodWildcard())
            continue;
        if (key.isUsePathPattern() && !key.matchesPath(uri))
            continue;
        if (!key.complexMatch(hostHeader, method, uri, version, port, localIP))
            continue;
        return rule;
    }
    return null;
}
Also used : RuleKey(com.predic8.membrane.core.rules.RuleKey) Rule(com.predic8.membrane.core.rules.Rule)

Example 4 with Key

use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.

the class AbstractExchange method getPublicUrl.

public String getPublicUrl() {
    String xForwardedProto = getRequest().getHeader().getFirstValue(Header.X_FORWARDED_PROTO);
    boolean isHTTPS = xForwardedProto != null ? "https".equals(xForwardedProto) : getRule().getSslInboundContext() != null;
    String publicURL = (isHTTPS ? "https://" : "http://") + getRequest().getHeader().getHost().replaceFirst(".*:", "");
    RuleKey key = getRule().getKey();
    if (!key.isPathRegExp() && key.getPath() != null)
        publicURL += key.getPath();
    return publicURL;
}
Also used : RuleKey(com.predic8.membrane.core.rules.RuleKey)

Example 5 with Key

use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.

the class ApiManagementConfiguration method parseExpiration.

private void parseExpiration(LinkedHashMap<String, Object> keyYaml, Key key) {
    String expirationString = parseString(keyYaml.get("expires"), null);
    Instant expiration = null;
    if (expirationString != null)
        try {
            expiration = Instant.parse(expirationString);
        } catch (Exception e) {
            log.error("Could not read expiration");
        }
    key.setExpiration(expiration);
}
Also used : Instant(java.time.Instant) URISyntaxException(java.net.URISyntaxException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException)

Aggregations

Policy (com.predic8.membrane.core.interceptor.apimanagement.policy.Policy)5 RuleKey (com.predic8.membrane.core.rules.RuleKey)3 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)3 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)3 IOException (java.io.IOException)3 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)2 Request (com.predic8.membrane.core.http.Request)2 Key (com.predic8.membrane.core.interceptor.apimanagement.Key)2 ResourceRetrievalException (com.predic8.membrane.core.resolver.ResourceRetrievalException)2 StatisticCollector (com.predic8.membrane.core.rules.StatisticCollector)2 MalformedURLException (java.net.MalformedURLException)2 MCAttribute (com.predic8.membrane.annot.MCAttribute)1 MCChildElement (com.predic8.membrane.annot.MCChildElement)1 MCElement (com.predic8.membrane.annot.MCElement)1 MCOtherAttributes (com.predic8.membrane.annot.MCOtherAttributes)1 MCTextContent (com.predic8.membrane.annot.MCTextContent)1 MainInfo (com.predic8.membrane.annot.model.MainInfo)1 HttpRouter (com.predic8.membrane.core.HttpRouter)1 SSLParser (com.predic8.membrane.core.config.security.SSLParser)1 Exchange (com.predic8.membrane.core.exchange.Exchange)1