Page History
...
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
package ...; import com.blueriq.component.api.storeexternalflow.data.externalflowmapping.IExternalFlowStoreAuthenticationMapper; // other imports ... @Component public class HazelcastExternalFlowStoreCustomAuthenticationMapper implements IExternalFlowStoreAuthenticationMapper { private final IMap<String, byte[]> map; @Override public HazelcastExternalFlowStoreString authenticationType() { ClientConfig config = new ClientConfig(); // configureprovide a Hazelcastunique propertiesauthentication here type identifier that will HazelcastInstancebe hazelcastInstance used to identity which mapper should =be HazelcastClientused.newHazelcastClient(config); map = hazelcastInstance.getMap("blueriq")return "custom-blueriq-token-authentication"; } @Override public voidboolean deletesupportsContract(StringContractVersion keycontractVersion) { throws// ExternalFlowStoreException,check IllegalArgumentExceptionif { the AuthenticationMapper supports writing if (isInvalid(key)) { throw new IllegalArgumentException("Invalid key."and reading for the incoming contract version. return SupportedContractVersions.V_1_0.equals(contractVersion); } try {@Override public boolean canMap(Authentication map.delete(key);authentication) { }// catchcheck (Exceptionif e)the { provided authentication is supported by the throwAuthenticationMapper new ExternalFlowStoreException("Something went wrong", e); }return authentication instanceof CustomBlueriqAuthentication; } @Override public void ObjectModelRetrieval T get(String key)fillModel(ObjectModelCreation objectModel, Authentication authentication) { // throws ExternalFlowStoreException, IllegalArgumentException {verify that we still have the supported Authentication object. if (isInvalid(key!(authentication instanceof CustomBlueriqAuthentication)) { throw new IllegalArgumentException("Invalid key."); } "Unable to fill authentication model, unexpected authentication implementation: " try { byte[] storedValue = map.get(key+ authentication.getClass().getSimpleName()); } ifCustomBlueriqAuthentication (storedValuecustomAuthentication == null(CustomBlueriqAuthentication) {authentication; // We need to returnsupply null; the objectModel with enough information that } it is able to the return new ObjectModel(storedValue); } catch (Exception e) { throw new ExternalFlowStoreException("Something went wrong", ereconstruct the // CustomBlueriqAuthentication object in the toAuthentication method. objectModel.put("token", customAuthentication.getToken()); } } objectModel.put("user", customAuthentication.getName()); @Override public boolean hasKey(String key) objectModel.put("authenticated", customAuthentication.isAuthenticated()); throwsObjectModelCreation ExternalFlowStoreException,claims IllegalArgumentException {= objectModel.createObject("claims"); if (isInvalid(key))customAuthentication.getClaimNames().forEach(key -> { ArrayModelCreation throwvalues new= IllegalArgumentException("Invalid key."claims.createArray(key); } customAuthentication.getClaim(key).forEach(values::add); try {}); ArrayModelCreation roles return= mapobjectModel.getcreateArray(key) != null"roles"); } catch (Exception e) {customAuthentication.getRoles().forEach(roles::add); ArrayModelCreation teams throw new ExternalFlowStoreException("Something went wrong", e= objectModel.createArray("teams"); }customAuthentication.getTeams().forEach(teams::add); } @Override public voidAuthentication settoAuthentication(StringObjectModelRetrieval key, ObjectModelStorage value) throws ExternalFlowStoreException, IllegalArgumentException { if (isInvalid(key)) { throw new IllegalArgumentException("Invalid key."); } if (model == null) {objectModel) { // We retrieve all of the filled information from the objectModel, in order to recreate the // CustomBlueriqAuthentication String token = objectModel.getString("token"); String user throw new IllegalArgumentException("external flow model must not be null= objectModel.getString("user"); } try {boolean isAuthenticated = objectModel.getBoolean("authenticated"); List<String> map.set(key, value.toBytes(), 1, TimeUnit.MINUTES)roles = objectModel.getStringList("roles"); }List<String> teams catch= (Exception e) {objectModel.getStringList("teams"); ObjectModelRetrieval claimsModel throw new ExternalFlowStoreException("Something went wrong", e= objectModel.getObject("claims"); } } private boolean isInvalid(String key) { // define what an invalid key means return false Map<String, List<String>> claims = claimsModel.getProperties().collect(Collectors.toMap(Function.identity(), claimsModel::getStringList)); return new CustomBlueriqAuthentication(user, token, teams, roles, claims, isAuthenticated); } } } |
Overview
Content Tools