Package org.cyclos.impl.access
Class DeviceConfirmationServiceImpl
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractNetworkedServerComponent
-
- org.cyclos.impl.BaseServiceImpl
-
- org.cyclos.impl.access.DeviceConfirmationServiceImpl
-
- All Implemented Interfaces:
DeviceConfirmationServiceLocal,DeviceConfirmationService,Service
@Service public class DeviceConfirmationServiceImpl extends BaseServiceImpl implements DeviceConfirmationServiceLocal
Implementation forDeviceConfirmationService
-
-
Field Summary
-
Fields inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
authHandler, conversionHandler, customFieldValueHandler, entityManagerHandler, groupsHandler, productsHandler, restBeanPropertyMapping, userLocatorHandler
-
Fields inherited from class org.cyclos.impl.AbstractServerComponent
accountHandler, configurationHandler, dataTranslationHandler, notificationHandler, profileFieldHandler, transactionHandler, translationHandler
-
Fields inherited from interface org.cyclos.services.access.DeviceConfirmationService
DEVICE_CONFIRMATION_VALUE_PREFIX
-
-
Constructor Summary
Constructors Constructor Description DeviceConfirmationServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapprove(long id, long deviceId, String hmac)Approves a confirmation through a trusted device.SerializableInputStreambarcode(DeviceConfirmationBarcodeParams params)Generates a two-dimensional barcode (QR code), only if the confirmation was not already approved nor rejected, containing a URL of the form:
cyclos://confirm?id=confirmation_id&op=i18n_confirmation_type&fields=Label1:Value1|Label2:Value2...
If any of the labels / values contains a ':' or '|' char then they are escaped with a '\' (e.i 'Business One | Big' -> 'Business One \| Big') E.g
cyclos://confirm?id=-6959640208566238428&op=Payment confirmation&fields=from:b1|to:b2|amount:50 units)TrustedDevicecheck(long confirmationId, CreateDeviceConfirmationParams params)Checks if the confirmation was APPROVED and also its QR-content matches the generated from theCreateDeviceConfirmationParamsparameter.voidcheckExists(Long deviceConfirmationId)Checks that a device confirmation with the given id exists, throwingEntityNotFoundExceptionif not.DeviceConfirmationVOcreate(CreateDeviceConfirmationParams params)Creates a new pending for approval device confirmation for the logged user.DeviceConfirmationVOcreate(CreateDeviceConfirmationParams params, BasicUser creatorUser, BasicUser ownerUser, boolean unmaskIds)Creates a new pending for approval device confirmation for the owner user.DeviceConfirmationApprovalDatagetApprovalData(long deviceId)Return data for approve / reject device confirmations for the given device idMap<MessageKey,Object>getQRFields(DeviceConfirmationType type, Map<DeviceConfirmationField,Object> canonicalValues)Returns a map with the fields used to generate the QR content for a given device confirmation typeDeviceConfirmationVOload(Long id)Load a device confirmation by id for the logged user.protected voidregisterNetworkMappings(NetworkPathRegistry networkPathRegistry)Needs to be overridden by subclasses to register the path up to the networkvoidreject(long id, long deviceId, String hmac)Same asDeviceConfirmationService.approve(long, long, String)but for confirmation rejection.voidremove(Long id)Removes a confirmation for the logged user.TrustedDevicevalidate(long id, long deviceId, String hmac)Validates a PENDING confirmation with a device to ensure the device is a valid trusted device.-
Methods inherited from class org.cyclos.impl.BaseServiceImpl
initializeNetworkMappings
-
Methods inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
canManage, checkManagesUser, checkPermission, checkRelatesToUser, checkValue, clearAlreadyValidated, getBaseEntityManagerHandler, getConfiguration, getLoggedBasicUser, getLoggedUser, getProducts, getTranslatedName, getTranslatedValue, hasPermission, hasValue, inSameNetwork, inSameNetworkOrGlobal, isAdmin, isAlreadyValidated, isBroker, isGlobalAdmin, isGlobalAdminInNetwork, isGuest, isLoggedIn, isMember, isMemberOnly, isNetworkAdmin, isOperator, isRelatedToUser, isSystem, isUserManager, isUserManagerOf, message, message, permission, permission, permissionOptionalValue, permissionOptionalValue, toDate, toDateTime, validate
-
Methods inherited from class org.cyclos.impl.AbstractServerComponent
dataTranslationProxy, delete, detach, find, flush, from, getApplicationContext, getFormatter, getFormatter, getFormatter, getLogger, getRemoteAddress, getSessionData, mailContentBuilder, message, message, persist, processBatch, processBatch, refresh, remove, selectFrom, subQuery, update
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cyclos.impl.access.DeviceConfirmationServiceLocal
isDeviceConfirmation
-
-
-
-
Method Detail
-
approve
public void approve(long id, long deviceId, String hmac)Description copied from interface:DeviceConfirmationServiceApproves a confirmation through a trusted device. This operation can be invoked as guests or with a logged user, if guest the final user running the approve will be the device's owner.- Specified by:
approvein interfaceDeviceConfirmationService- Parameters:
id- the identification of the confirmation being approved.deviceId- the identification of the trusted device used to approve.hmac- the Hash-based Message Authentication Code used to verify the authentication of the confirmation and device.
The cryptographic hash function used to compute the HMAC is SHA-256.
-
barcode
public SerializableInputStream barcode(DeviceConfirmationBarcodeParams params)
Description copied from interface:DeviceConfirmationServiceGenerates a two-dimensional barcode (QR code), only if the confirmation was not already approved nor rejected, containing a URL of the form:
cyclos://confirm?id=confirmation_id&op=i18n_confirmation_type&fields=Label1:Value1|Label2:Value2...
If any of the labels / values contains a ':' or '|' char then they are escaped with a '\' (e.i 'Business One | Big' -> 'Business One \| Big') E.g
cyclos://confirm?id=-6959640208566238428&op=Payment confirmation&fields=from:b1|to:b2|amount:50 units)- Specified by:
barcodein interfaceDeviceConfirmationService
-
check
public TrustedDevice check(long confirmationId, CreateDeviceConfirmationParams params)
Description copied from interface:DeviceConfirmationServiceLocalChecks if the confirmation was APPROVED and also its QR-content matches the generated from theCreateDeviceConfirmationParamsparameter. Also, if the confirmation was found and is approved then it's removed.- Specified by:
checkin interfaceDeviceConfirmationServiceLocal- Returns:
- the device used to approve the given confirmation
-
checkExists
public void checkExists(Long deviceConfirmationId)
Description copied from interface:DeviceConfirmationServiceLocalChecks that a device confirmation with the given id exists, throwingEntityNotFoundExceptionif not.- Specified by:
checkExistsin interfaceDeviceConfirmationServiceLocal
-
create
public DeviceConfirmationVO create(CreateDeviceConfirmationParams params)
Description copied from interface:DeviceConfirmationServiceCreates a new pending for approval device confirmation for the logged user.- Specified by:
createin interfaceDeviceConfirmationService
-
create
public DeviceConfirmationVO create(CreateDeviceConfirmationParams params, BasicUser creatorUser, BasicUser ownerUser, boolean unmaskIds)
Description copied from interface:DeviceConfirmationServiceLocalCreates a new pending for approval device confirmation for the owner user. If the ids present in the 'params' object are masked then set the 'unmaskIds' flag to true. If a 'creatorUser' is given then the push-notification will be send to that user instead of to the owner user.- Specified by:
createin interfaceDeviceConfirmationServiceLocal
-
getApprovalData
public DeviceConfirmationApprovalData getApprovalData(long deviceId)
Description copied from interface:DeviceConfirmationServiceReturn data for approve / reject device confirmations for the given device id- Specified by:
getApprovalDatain interfaceDeviceConfirmationService- Returns:
-
getQRFields
public Map<MessageKey,Object> getQRFields(DeviceConfirmationType type, Map<DeviceConfirmationField,Object> canonicalValues)
Returns a map with the fields used to generate the QR content for a given device confirmation type- Specified by:
getQRFieldsin interfaceDeviceConfirmationServiceLocal- Parameters:
canonicalValues- the values obtained after parsing theCreateDeviceConfirmationParams.FIELDSmap
-
load
public DeviceConfirmationVO load(Long id)
Description copied from interface:DeviceConfirmationServiceLoad a device confirmation by id for the logged user.- Specified by:
loadin interfaceDeviceConfirmationService
-
reject
public void reject(long id, long deviceId, String hmac)Description copied from interface:DeviceConfirmationServiceSame asDeviceConfirmationService.approve(long, long, String)but for confirmation rejection.- Specified by:
rejectin interfaceDeviceConfirmationService
-
remove
public void remove(Long id)
Description copied from interface:DeviceConfirmationServiceRemoves a confirmation for the logged user.- Specified by:
removein interfaceDeviceConfirmationService
-
validate
public TrustedDevice validate(long id, long deviceId, String hmac)
Description copied from interface:DeviceConfirmationServiceLocalValidates a PENDING confirmation with a device to ensure the device is a valid trusted device. This method perform the same validation as forDeviceConfirmationService.approve(long, long, String)but immediately remove the confirmation and do not send any push-notification if the validation success.- Specified by:
validatein interfaceDeviceConfirmationServiceLocal- Returns:
- the device associated to the given id
-
registerNetworkMappings
protected void registerNetworkMappings(NetworkPathRegistry networkPathRegistry)
Description copied from class:BaseServiceImplNeeds to be overridden by subclasses to register the path up to the network- Specified by:
registerNetworkMappingsin classBaseServiceImpl
-
-