use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project hub-fortify-ssc-integration-service by blackducksoftware.
the class FortifyService method getHeader.
public static Builder getHeader(final PropertyConstants propertyConstants, final String token) {
final HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
if (propertyConstants.getLogLevel().equalsIgnoreCase("INFO")) {
logging.setLevel(Level.BASIC);
} else {
logging.setLevel(Level.BODY);
}
final OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.authenticator(new Authenticator() {
@Override
public Request authenticate(final Route route, final Response response) throws IOException {
if (token.equals(response.request().header("Authorization"))) {
try {
FortifyExceptionUtil.verifyFortifyResponseCode(response.code(), "Unauthorized access of Fortify Api");
} catch (final IntegrationException e) {
throw new IOException(e);
}
return null;
}
return response.request().newBuilder().header("Authorization", token).build();
}
});
okBuilder.addInterceptor(logging);
return okBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project hub-fortify-ssc-integration-service by blackducksoftware.
the class FortifyUnifiedLoginTokenApi method getHeader.
private static Builder getHeader(final PropertyConstants propertyConstants) {
final HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
if (propertyConstants.getLogLevel().equalsIgnoreCase("INFO")) {
logging.setLevel(Level.BASIC);
} else {
logging.setLevel(Level.BODY);
}
final OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.authenticator(new Authenticator() {
@Override
public Request authenticate(final Route route, final Response response) throws IOException {
final String credential = Credentials.basic(propertyConstants.getFortifyUserName(), propertyConstants.getFortifyPassword());
if (credential.equals(response.request().header("Authorization"))) {
try {
FortifyExceptionUtil.verifyFortifyResponseCode(response.code(), "Unauthorized access of Fortify Api");
} catch (final IntegrationException e) {
throw new IOException(e);
}
return null;
}
return response.request().newBuilder().header("Authorization", credential).build();
}
});
okBuilder.addInterceptor(logging);
return okBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project openhab-android by openhab.
the class MjpegStreamer method httpRequest.
public InputStream httpRequest(String url, final String usr, final String pwd) {
Request request = new Request.Builder().url(url).build();
OkHttpClient client = new OkHttpClient.Builder().authenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
Log.d(TAG, "Authenticating for response: " + response);
Log.d(TAG, "Challenges: " + response.challenges());
// Get username/password from preferences
String credential = Credentials.basic(usr, pwd);
return response.request().newBuilder().header("Authorization", credential).build();
}
}).build();
try {
Log.d(TAG, "1. Sending http request");
Response response = client.newCall(request).execute();
Log.d(TAG, "2. Request finished, status = " + response.code());
if (response.code() == 401) {
// You must turn off camera User Access Control before this will work
return null;
}
return response.body().byteStream();
} catch (IOException e) {
Log.e(TAG, "Request failed-IOException", e);
// Error connecting to camera
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project autorest-clientruntime-for-java by Azure.
the class AzureTokenCredentials method applyCredentialsFilter.
@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
clientBuilder.interceptors().add(new AzureTokenCredentialsInterceptor(this));
clientBuilder.authenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
String authenticateHeader = response.header("WWW-Authenticate");
if (authenticateHeader != null && !authenticateHeader.isEmpty()) {
Pattern pattern = Pattern.compile("resource=\"([a-zA-Z0-9.:/-_]+)\"");
Matcher matcher = pattern.matcher(authenticateHeader);
if (matcher.find()) {
String resource = matcher.group(1);
return response.request().newBuilder().header("Authorization", "Bearer " + getToken(resource)).build();
}
}
// Otherwise cannot satisfy the challenge
return null;
}
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class BaseVrfEntryHandler method makeConnectedRoute.
// Allow deprecated TransactionRunner calls for now
@SuppressWarnings("ForbidCertainMethod")
protected void makeConnectedRoute(Uint64 dpId, Uint32 vpnId, VrfEntry vrfEntry, String rd, @Nullable List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx, @Nullable List<SubTransaction> subTxns) {
if (tx == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, newTx -> makeConnectedRoute(dpId, vpnId, vrfEntry, rd, instructions, addOrRemove, TransactionAdapter.toWriteTransaction(newTx), subTxns)), LOG, "Error making connected route");
return;
}
LOG.trace("makeConnectedRoute: vrfEntry {}", vrfEntry);
String[] values = vrfEntry.getDestPrefix().split("/");
String ipAddress = values[0];
int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
if (addOrRemove == NwConstants.ADD_FLOW) {
LOG.debug("Adding route to DPN {} for rd {} prefix {} ", dpId, rd, vrfEntry.getDestPrefix());
} else {
LOG.debug("Removing route from DPN {} for rd {} prefix {}", dpId, rd, vrfEntry.getDestPrefix());
}
InetAddress destPrefix;
try {
destPrefix = InetAddress.getByName(ipAddress);
} catch (UnknownHostException e) {
LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpId, e);
return;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
if (destPrefix instanceof Inet4Address) {
matches.add(MatchEthernetType.IPV4);
if (prefixLength != 0) {
matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
}
} else {
matches.add(MatchEthernetType.IPV6);
if (prefixLength != 0) {
matches.add(new MatchIpv6Destination(destPrefix.getHostAddress() + "/" + prefixLength));
}
}
int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
String flowRef = FibUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, priority, destPrefix);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
Flow flow = flowEntity.getFlowBuilder().build();
String flowId = flowEntity.getFlowId();
FlowKey flowKey = new FlowKey(new FlowId(flowId));
Node nodeDpn = FibUtil.buildDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.key()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
SubTransaction subTransaction = new SubTransactionImpl();
if (addOrRemove == NwConstants.ADD_FLOW) {
subTransaction.setInstanceIdentifier(flowInstanceId);
subTransaction.setInstance(flow);
subTransaction.setAction(SubTransaction.CREATE);
} else {
subTransaction.setInstanceIdentifier(flowInstanceId);
subTransaction.setAction(SubTransaction.DELETE);
}
subTxns.add(subTransaction);
}
if (addOrRemove == NwConstants.ADD_FLOW) {
tx.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow);
} else {
tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
}
Aggregations