use of com.amazonaws.mobile.client.internal.oauth2.AuthorizeResponse in project steve by RWTH-i5-IDSG.
the class StressTestSoapOCPP16 method attackInternal.
protected void attackInternal() throws Exception {
final List<String> idTags = getRandomStrings(ID_TAG_COUNT);
final List<String> chargeBoxIds = getRandomStrings(CHARGE_BOX_COUNT);
StressTester.Runnable runnable = new StressTester.Runnable() {
private final ThreadLocal<String> threadLocalChargeBoxId = new ThreadLocal<>();
@Override
public void beforeRepeat() {
CentralSystemService client = getForOcpp16(path);
ThreadLocalRandom localRandom = ThreadLocalRandom.current();
threadLocalChargeBoxId.set(chargeBoxIds.get(localRandom.nextInt(chargeBoxIds.size())));
String chargeBoxId = threadLocalChargeBoxId.get();
// to insert threadLocalChargeBoxId into db
BootNotificationResponse boot = client.bootNotification(new BootNotificationRequest().withChargePointVendor(getRandomString()).withChargePointModel(getRandomString()), chargeBoxId);
Assertions.assertEquals(RegistrationStatus.ACCEPTED, boot.getStatus());
}
@Override
public void toRepeat() {
CentralSystemService client = getForOcpp16(path);
ThreadLocalRandom localRandom = ThreadLocalRandom.current();
String chargeBoxId = threadLocalChargeBoxId.get();
String idTag = idTags.get(localRandom.nextInt(idTags.size()));
int connectorId = localRandom.nextInt(1, CONNECTOR_COUNT_PER_CHARGE_BOX + 1);
int transactionStart = localRandom.nextInt(0, Integer.MAX_VALUE);
int transactionStop = localRandom.nextInt(transactionStart + 1, Integer.MAX_VALUE);
HeartbeatResponse heartbeat = client.heartbeat(new HeartbeatRequest(), chargeBoxId);
Assertions.assertNotNull(heartbeat);
for (int i = 0; i <= CONNECTOR_COUNT_PER_CHARGE_BOX; i++) {
StatusNotificationResponse status = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.NO_ERROR).withStatus(ChargePointStatus.AVAILABLE).withConnectorId(i).withTimestamp(DateTime.now()), chargeBoxId);
Assertions.assertNotNull(status);
}
AuthorizeResponse auth = client.authorize(new AuthorizeRequest().withIdTag(idTag), chargeBoxId);
Assertions.assertNotEquals(AuthorizationStatus.ACCEPTED, auth.getIdTagInfo().getStatus());
StartTransactionResponse start = client.startTransaction(new StartTransactionRequest().withConnectorId(connectorId).withIdTag(idTag).withTimestamp(DateTime.now()).withMeterStart(transactionStart), chargeBoxId);
Assertions.assertNotNull(start);
StatusNotificationResponse statusStart = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.NO_ERROR).withStatus(ChargePointStatus.CHARGING).withConnectorId(connectorId).withTimestamp(DateTime.now()), chargeBoxId);
Assertions.assertNotNull(statusStart);
MeterValuesResponse meter = client.meterValues(new MeterValuesRequest().withConnectorId(connectorId).withTransactionId(start.getTransactionId()).withMeterValue(getMeterValues(transactionStart, transactionStop)), chargeBoxId);
Assertions.assertNotNull(meter);
StopTransactionResponse stop = client.stopTransaction(new StopTransactionRequest().withTransactionId(start.getTransactionId()).withTimestamp(DateTime.now()).withIdTag(idTag).withMeterStop(transactionStop), chargeBoxId);
Assertions.assertNotNull(stop);
StatusNotificationResponse statusStop = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.NO_ERROR).withStatus(ChargePointStatus.AVAILABLE).withConnectorId(connectorId).withTimestamp(DateTime.now()), chargeBoxId);
Assertions.assertNotNull(statusStop);
}
@Override
public void afterRepeat() {
}
};
StressTester tester = new StressTester(THREAD_COUNT, REPEAT_COUNT_PER_THREAD);
tester.test(runnable);
tester.shutDown();
}
use of com.amazonaws.mobile.client.internal.oauth2.AuthorizeResponse in project steve by RWTH-i5-IDSG.
the class Issue73Fix method sendAuth.
private static void sendAuth(CentralSystemService client, String chargeBoxId, AuthorizationStatus expected) {
AuthorizeResponse auth = client.authorize(new AuthorizeRequest().withIdTag(REGISTERED_OCPP_TAG), chargeBoxId);
Assertions.assertNotNull(auth);
Assertions.assertEquals(expected, auth.getIdTagInfo().getStatus());
}
use of com.amazonaws.mobile.client.internal.oauth2.AuthorizeResponse in project aws-sdk-android by aws-amplify.
the class OAuth2Utils method _showSignInOAuth2UI.
private Runnable _showSignInOAuth2UI(final Activity callingActivity, final SignInUIOptions signInUIOptions, final Callback<UserStateDetails> callback) {
return new Runnable() {
@Override
public void run() {
final HostedUIOptions hostedUIOptions = signInUIOptions.getHostedUIOptions();
// Reset settings to JSON
JSONObject hostedUIJSON = getHostedUIJSONFromJSON();
if (hostedUIJSON == null) {
callback.onError(new Exception("Could not create OAuth configuration object"));
}
if (hostedUIOptions.getFederationEnabled() != null) {
mStore.set(FEDERATION_ENABLED_KEY, hostedUIOptions.getFederationEnabled() ? "true" : "false");
} else {
mStore.set(FEDERATION_ENABLED_KEY, "true");
}
mStore.set(SIGN_IN_MODE, SignInMode.OAUTH2.toString());
if (isFederationEnabled() && hostedUIOptions.getFederationProviderName() == null) {
throw new IllegalArgumentException("OAuth flow requires a federation provider name if federation is enabled.");
}
if (hostedUIOptions.getSignOutQueryParameters() != null) {
try {
JSONObject signOutParams = new JSONObject();
for (Map.Entry<String, String> e : hostedUIOptions.getSignOutQueryParameters().entrySet()) {
signOutParams.put(e.getKey(), e.getValue());
}
hostedUIJSON.put("SignOutQueryParameters", signOutParams);
} catch (JSONException e1) {
callback.onError(new Exception("Failed to construct sign-out query parameters", e1));
return;
}
}
if (hostedUIOptions.getTokenQueryParameters() != null) {
try {
JSONObject tokenParams = new JSONObject();
for (Map.Entry<String, String> e : hostedUIOptions.getTokenQueryParameters().entrySet()) {
tokenParams.put(e.getKey(), e.getValue());
}
hostedUIJSON.put("TokenQueryParameters", tokenParams);
} catch (JSONException e1) {
callback.onError(new Exception("Failed to construct token query parameters", e1));
return;
}
}
mStore.set(HOSTED_UI_KEY, hostedUIJSON.toString());
Uri.Builder authorizeUriBuilder;
try {
authorizeUriBuilder = Uri.parse(hostedUIJSON.getString("SignInURI")).buildUpon();
if (hostedUIOptions.getSignInQueryParameters() != null) {
for (Map.Entry<String, String> e : hostedUIOptions.getSignInQueryParameters().entrySet()) {
authorizeUriBuilder.appendQueryParameter(e.getKey(), e.getValue());
}
}
authorizeUriBuilder.appendQueryParameter("redirect_uri", hostedUIJSON.getString("SignInRedirectURI"));
authorizeUriBuilder.appendQueryParameter("scopes", hostedUIJSON.getJSONArray("Scopes").join(" "));
authorizeUriBuilder.appendQueryParameter("client_id", hostedUIJSON.getString("AppClientId"));
} catch (Exception e) {
throw new RuntimeException("Failed to construct authorization url for OAuth", e);
}
Uri.Builder tokensUriBuilder;
final Map<String, String> tokensBody = new HashMap<String, String>();
try {
tokensUriBuilder = Uri.parse(hostedUIJSON.getString("TokenURI")).buildUpon();
if (hostedUIOptions.getTokenQueryParameters() != null) {
for (Map.Entry<String, String> e : hostedUIOptions.getTokenQueryParameters().entrySet()) {
tokensUriBuilder.appendQueryParameter(e.getKey(), e.getValue());
}
}
tokensBody.put("client_id", hostedUIJSON.getString("AppClientId"));
tokensBody.put("redirect_uri", hostedUIJSON.getString("SignInRedirectURI"));
} catch (Exception e) {
throw new RuntimeException("Failed to construct tokens url for OAuth", e);
}
final Uri tokensUri = tokensUriBuilder.build();
mOAuth2Client.authorize(authorizeUriBuilder.build(), new Callback<AuthorizeResponse>() {
@Override
public void onResult(AuthorizeResponse result) {
Log.i(TAG, "onResult: OAuth2 callback occurred, exchanging code for token");
mOAuth2Client.requestTokens(tokensUri, new HashMap<String, String>(), tokensBody, result.getCode(), new Callback<OAuth2Tokens>() {
@Override
public void onResult(OAuth2Tokens result) {
if (isFederationEnabled()) {
federatedSignInWithoutAssigningState(hostedUIOptions.getFederationProviderName(), // TODO verify id token is correct, this would mean OAuth support requires scope openid
result.getIdToken(), new Callback<UserStateDetails>() {
@Override
public void onResult(UserStateDetails result) {
final UserStateDetails userStateDetails = getUserStateDetails(false);
callback.onResult(userStateDetails);
setUserState(userStateDetails);
}
@Override
public void onError(Exception e) {
final UserStateDetails userStateDetails = getUserStateDetails(false);
callback.onResult(userStateDetails);
setUserState(userStateDetails);
}
});
} else {
final UserStateDetails userStateDetails = getUserStateDetails(false);
callback.onResult(userStateDetails);
setUserState(userStateDetails);
}
}
@Override
public void onError(Exception e) {
callback.onError(e);
}
});
}
@Override
public void onError(Exception e) {
callback.onError(e);
}
});
}
};
}
use of com.amazonaws.mobile.client.internal.oauth2.AuthorizeResponse in project EVSUPERVISION by EnergyTIC.
the class OperationalTestSoapOCPP16 method testUnregisteredIdTag.
@Test
public void testUnregisteredIdTag() {
CentralSystemService client = getForOcpp16(path);
AuthorizeResponse auth = client.authorize(new AuthorizeRequest().withIdTag(getRandomString()), REGISTERED_CHARGE_BOX_ID);
Assertions.assertNotNull(auth);
Assertions.assertEquals(AuthorizationStatus.INVALID, auth.getIdTagInfo().getStatus());
}
Aggregations