/** * Encode string. * * @param data the data * @return the string */ default String encode(final String data) { return encode(data, Optional.empty()); }
/** * Encrypt resolved username. * * @param principal the principal * @param service the service * @param registeredService the registered service * @param username the username * @return the encrypted username or null */ protected String encryptResolvedUsername(final Principal principal, final Service service, final RegisteredService registeredService, final String username) { val applicationContext = ApplicationContextProvider.getApplicationContext(); val cipher = applicationContext.getBean("registeredServiceCipherExecutor", RegisteredServiceCipherExecutor.class); return cipher.encode(username, Optional.of(registeredService)); }
/** * Encrypt, encode and put the attribute into attributes map. * * @param attributes the attributes * @param cachedAttributesToEncode the cached attributes to encode * @param cachedAttributeName the cached attribute name * @param cipher the cipher * @param registeredService the registered service */ protected void encryptAndEncodeAndPutIntoAttributesMap(final Map<String, Object> attributes, final Map<String, String> cachedAttributesToEncode, final String cachedAttributeName, final RegisteredServiceCipherExecutor cipher, final RegisteredService registeredService) { val cachedAttribute = cachedAttributesToEncode.remove(cachedAttributeName); if (StringUtils.isNotBlank(cachedAttribute)) { LOGGER.trace("Retrieved [{}] as a cached model attribute...", cachedAttributeName); val encodedValue = cipher.encode(cachedAttribute, Optional.of(registeredService)); if (StringUtils.isNotBlank(encodedValue)) { attributes.put(cachedAttributeName, encodedValue); LOGGER.trace("Encrypted and encoded [{}] as an attribute to [{}].", cachedAttributeName, encodedValue); } else { LOGGER.warn("Attribute [{}] cannot be encoded and is removed from the collection of attributes", cachedAttributeName); } } else { LOGGER.trace("[{}] is not available as a cached model attribute to encrypt...", cachedAttributeName); } }