use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.
the class ApiManagementConfigurationTest method testParseYaml.
@Test
public void testParseYaml() throws Exception {
String source = new String(Files.readAllBytes(Paths.get(System.getProperty("user.dir") + "\\src\\test\\resources\\apimanagement\\api.yaml")), Charset.defaultCharset());
ApiManagementConfiguration conf = new ApiManagementConfiguration();
conf.setLocation(source);
Map<String, Policy> policies = conf.getPolicies();
for (Policy p : policies.values()) {
System.out.println(p);
}
Map<String, Key> keys = conf.getKeys();
for (Key k : keys.values()) {
System.out.println(k);
}
}
use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.
the class ApiManagementConfiguration method parsePoliciesForKeys.
private Map<String, Key> parsePoliciesForKeys(Map<String, Object> yaml) {
Map<String, Key> result = new HashMap<String, Key>();
// assumption: the yaml is valid
List<Object> keys = (List<Object>) yaml.get("keys");
if (keys == null) {
log.info("No API keys in policy file");
return result;
}
for (Object keyObject : keys) {
LinkedHashMap<String, Object> key = (LinkedHashMap<String, Object>) keyObject;
Key keyRes = new Key();
String keyName = (String) key.get("key");
keyRes.setName(keyName);
parseExpiration(key, keyRes);
List<Object> policiesForKey = (List<Object>) key.get("policies");
HashSet<Policy> policies = new HashSet<Policy>();
for (Object polObj : policiesForKey) {
String policyName = (String) polObj;
Policy p = this.policies.get(policyName);
policies.add(p);
}
keyRes.setPolicies(policies);
result.put(keyName, keyRes);
}
return result;
}
use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.
the class AMRateLimiter method addRequestEntry.
private void addRequestEntry(String apiKey) {
synchronized (keyInformation) {
if (!keyInformation.containsKey(apiKey)) {
ApiKeyRequestCounter value = new ApiKeyRequestCounter();
Key key = amc.getKeys().get(apiKey);
for (Policy p : key.getPolicies()) {
value.getPolicyCounters().put(p.getName(), new AtomicInteger());
}
keyInformation.put(apiKey, value);
}
}
ApiKeyRequestCounter keyInfo = keyInformation.get(apiKey);
for (AtomicInteger counter : keyInfo.getPolicyCounters().values()) {
counter.incrementAndGet();
}
}
use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.
the class OtpProvider method computePin.
/**
* Computes the one-time PIN given the secret key.
*
* @param secret
* the secret key
* @param otp_state
* current token state (counter or time-interval)
* @param challenge
* optional challenge bytes to include when computing passcode.
* @return the PIN
*/
private String computePin(String secret, long otp_state) {
if (secret == null || secret.length() == 0) {
throw new RuntimeException("Null or empty secret");
}
try {
Signer signer = getSigningOracle(secret);
PasscodeGenerator pcg = new PasscodeGenerator(signer, PIN_LENGTH);
return pcg.generateResponseCode(otp_state);
} catch (GeneralSecurityException e) {
throw new RuntimeException("Crypto failure", e);
}
}
use of com.predic8.membrane.core.interceptor.apimanagement.Key in project service-proxy by membrane.
the class HttpServletHandler method createHeader.
private Header createHeader() {
Header header = new Header();
Enumeration<?> e = request.getHeaderNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
Enumeration<?> e2 = request.getHeaders(key);
while (e2.hasMoreElements()) {
String value = (String) e2.nextElement();
header.add(key, value);
}
}
return header;
}
Aggregations