/** * Set the verification response. * @param mfaVerificationCode Required: The TOTP code. * @param mfaFriendlyName Optional: The friendly name for the new TOTP device. */ public void setVerificationResponse(final String mfaVerificationCode, final String mfaFriendlyName) { if (StringUtils.isBlank(mfaVerificationCode)) { throw new CognitoParameterInvalidException("verification code is invalid"); } this.verificationCode = mfaVerificationCode; if (!StringUtils.isBlank(mfaFriendlyName)) { this.friendlyName = mfaFriendlyName; } }
private static String findAttributeValue( String qnameToFind, Attributes attrs) { if (StringUtils.isBlank(qnameToFind) || attrs == null) { return null; } for (int i = 0; i < attrs.getLength(); i++) { final String qname = attrs.getQName(i); if (qname.trim().equalsIgnoreCase(qnameToFind.trim())) { return attrs.getValue(i); } } return null; }
private Map<String, Double> loadMetrics() { final Map<String, Double> outputMap = new ConcurrentHashMap<String, Double>(); final String jsonString = this.context.getSystem().getPreferences().getString(CUSTOM_METRICS_KEY, null); if (StringUtils.isBlank(jsonString)) { return outputMap; } try { final JSONObject jsonObject = new JSONObject(jsonString); final Iterator<String> keysItr = jsonObject.keys(); while (keysItr.hasNext()) { final String key = keysItr.next(); final Double value = jsonObject.getDouble(key); outputMap.put(key, value); } } catch (final JSONException e) { e.printStackTrace(); } return outputMap; }
/** * Adds the session token, returned on successful MFA registration, to allow user authentication * to continue. * @param sessionToken the session token. */ public void setSessionToken(String sessionToken) { if (StringUtils.isBlank(sessionToken)) { throw new CognitoParameterInvalidException("session token cannot be null"); } setResponseSessionCode(sessionToken); }
private Map<String, List<String>> loadAttributes() { final Map<String, List<String>> outputMap = new ConcurrentHashMap<String, List<String>>(); final String jsonString = this.context.getSystem().getPreferences().getString(CUSTOM_ATTRIBUTES_KEY, null); if (StringUtils.isBlank(jsonString)) { return outputMap; } try { final JSONObject jsonObject = new JSONObject(jsonString); final Iterator<String> keysItr = jsonObject.keys(); while (keysItr.hasNext()) { final String key = keysItr.next(); final JSONArray jsonArray = jsonObject.getJSONArray(key); final List<String> listValues = new ArrayList<String>(); for (int i = 0; i < jsonArray.length(); i++) { listValues.add(jsonArray.getString(i)); } outputMap.put(key, listValues); } } catch (final JSONException e) { e.printStackTrace(); } return outputMap; }
if (StringUtils.isBlank(clientSecret)) { return null;
final CognitoUserSession cognitoTokens = user.getCachedSession(); AssociateSoftwareTokenResult result; if (!StringUtils.isBlank(sessionToken)) { result = associateTotpMfaInternalWithSession(sessionToken); useSessionToken = true;
@Override public List<byte[]> sendBatch(String streamName, List<byte[]> data) { if (data == null || data.isEmpty()) { return Collections.emptyList(); } final PutRecordsRequest request = new PutRecordsRequest(); request.setStreamName(streamName); final List<PutRecordsRequestEntry> records = new ArrayList<PutRecordsRequestEntry>(data.size()); for (final byte[] d : data) { final String partKey = StringUtils.isBlank(this.partitionKey) ? UUID.randomUUID().toString() : this.partitionKey; final PutRecordsRequestEntry r = new PutRecordsRequestEntry(); r.setData(ByteBuffer.wrap(d)); r.setPartitionKey(partKey); records.add(r); } request.setRecords(records); request.getRequestClientOptions().appendUserAgent(userAgent); final PutRecordsResult result = client.putRecords(request); final int size = result.getRecords().size(); final List<byte[]> failures = new ArrayList<byte[]>(result.getFailedRecordCount()); for (int i = 0; i < size; i++) { if (result.getRecords().get(i).getErrorCode() != null) { // always retry failed record failures.add(data.get(i)); } } return failures; }
private static boolean isKeyAttribute(Table table, String indexName, String attributeName) { GlobalSecondaryIndexDescription gsi = null; final LocalSecondaryIndexDescription lsi; if (StringUtils.isBlank(indexName)) { return table.getKeys().containsKey(attributeName); } else if (table.getGlobalSecondaryIndexes().get(indexName) != null) { gsi = table.getGlobalSecondaryIndexes().get(indexName); for (final KeySchemaElement element : gsi.getKeySchema()) { return isKeyAttribute(element, attributeName); } } else if (table.getLocalSecondaryIndexes().get(indexName) != null) { lsi = table.getLocalSecondaryIndexes().get(indexName); for (final KeySchemaElement element : lsi.getKeySchema()) { return isKeyAttribute(element, attributeName); } } else { throw new IllegalStateException(String.format( "Unable to locate index %s on table %s", indexName, table.getTableName())); } return false; }
VerifySoftwareTokenResult result; boolean useSessionToken; if (!StringUtils.isBlank(sessionToken)) { result = verifyTotpAssociationWithSession(sessionToken, totpCode, friendlyName); useSessionToken = true;
/** * Registers an MFA based on Time-based One-time Password, run on current thread. * @param sessionToken Optional: If a session token has to be used to register the MFA. * @param callback Required: Callback handler {@link VerifyMfaContinuation}. */ public void associateSoftwareToken(final String sessionToken, final RegisterMfaHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } final CognitoUser user = this; boolean useSessionToken; try { final CognitoUserSession cognitoTokens = user.getCachedSession(); AssociateSoftwareTokenResult result; if (!StringUtils.isBlank(sessionToken)) { result = associateTotpMfaInternalWithSession(sessionToken); useSessionToken = true; } else { result = associateTotpMfaInternalWithTokens(cognitoTokens); useSessionToken = false; } final String nextSessionToken = result.getSession(); final Map<String, String> parameters = new HashMap<String, String>(); parameters.put("type", CognitoServiceConstants.CHLG_TYPE_SOFTWARE_TOKEN_MFA); parameters.put("secretKey", result.getSecretCode()); callback.onVerify(new VerifyMfaContinuation(context, clientId, user, callback, parameters, useSessionToken, nextSessionToken, VerifyMfaContinuation.RUN_IN_CURRENT)); } catch (Exception e) { callback.onFailure(e); } }
if (!StringUtils.isBlank(this.indexName)) { request.withIndexName(indexName);
@Test public void removeQuotes() { final String noQuote = "noQuote"; assertEquals("noQuote", ServiceUtils.removeQuotes(noQuote)); final String quotes = "\"quotes\""; assertEquals("quotes", ServiceUtils.removeQuotes(quotes)); assertTrue(StringUtils.isBlank(ServiceUtils.removeQuotes(null))); }
/** * Set the verification response. * @param mfaVerificationCode Required: The TOTP code. * @param mfaFriendlyName Optional: The friendly name for the new TOTP device. */ public void setVerificationResponse(final String mfaVerificationCode, final String mfaFriendlyName) { if (StringUtils.isBlank(mfaVerificationCode)) { throw new CognitoParameterInvalidException("verification code is invalid"); } this.verificationCode = mfaVerificationCode; if (!StringUtils.isBlank(mfaFriendlyName)) { this.friendlyName = mfaFriendlyName; } }
final CognitoUserSession cognitoTokens = user.getCachedSession(); VerifySoftwareTokenResult result; if (!StringUtils.isBlank(sessionToken)) { result = verifyTotpAssociationWithSession(sessionToken, totpCode, friendlyName); useSessionToken = true;
private static String findAttributeValue( String qnameToFind, Attributes attrs) { if (StringUtils.isBlank(qnameToFind) || attrs == null) { return null; } for (int i = 0; i < attrs.getLength(); i++) { final String qname = attrs.getQName(i); if (qname.trim().equalsIgnoreCase(qnameToFind.trim())) { return attrs.getValue(i); } } return null; }
.withConsistentRead(isConsistentRead); if (!StringUtils.isBlank(this.indexName)) { request.withIndexName(indexName);
/** * Adds the session token, returned on successful MFA registration, to allow user authentication * to continue. * @param sessionToken the session token. */ public void setSessionToken(String sessionToken) { if (StringUtils.isBlank(sessionToken)) { throw new CognitoParameterInvalidException("session token cannot be null"); } setResponseSessionCode(sessionToken); }