1616
1717package com .iexec .sms .authorization ;
1818
19-
2019import com .iexec .commons .poco .chain .ChainDeal ;
2120import com .iexec .commons .poco .chain .ChainTask ;
2221import com .iexec .commons .poco .chain .ChainTaskStatus ;
@@ -49,52 +48,49 @@ public AuthorizationService(IexecHubService iexecHubService) {
4948
5049 /**
5150 * Checks whether this execution is authorized.
52- * If not authorized, return the reason.
53- * Otherwise, returns an empty {@link Optional}.
51+ *
52+ * @param workerpoolAuthorization The workerpool authorization to check
53+ * @return {@code Optional.empty()} if all checks passed, the failure reason otherwise
5454 */
55- public Optional <AuthorizationError > isAuthorizedOnExecutionWithDetailedIssue (WorkerpoolAuthorization workerpoolAuthorization , boolean isTeeTask ) {
55+ public Optional <AuthorizationError > isAuthorizedOnExecutionWithDetailedIssue (WorkerpoolAuthorization workerpoolAuthorization ) {
5656 if (workerpoolAuthorization == null || StringUtils .isEmpty (workerpoolAuthorization .getChainTaskId ())) {
5757 log .error ("Not authorized with empty params" );
5858 return Optional .of (EMPTY_PARAMS_UNAUTHORIZED );
5959 }
6060
61- String chainTaskId = workerpoolAuthorization .getChainTaskId ();
62- Optional < ChainTask > optionalChainTask = iexecHubService .getChainTask (chainTaskId );
63- if (optionalChainTask . isEmpty () ) {
61+ final String chainTaskId = workerpoolAuthorization .getChainTaskId ();
62+ final ChainTask chainTask = iexecHubService .getChainTask (chainTaskId ). orElse ( null );
63+ if (chainTask == null ) {
6464 log .error ("Could not get chainTask [chainTaskId:{}]" , chainTaskId );
6565 return Optional .of (GET_CHAIN_TASK_FAILED );
6666 }
67- ChainTask chainTask = optionalChainTask .get ();
68- ChainTaskStatus taskStatus = chainTask .getStatus ();
69- String chainDealId = chainTask .getDealid ();
67+ final String chainDealId = chainTask .getDealid ();
7068
71- if (taskStatus != ChainTaskStatus .ACTIVE ) {
72- log .error ("Task not active onchain [chainTaskId:{}, status:{}]" ,
73- chainTaskId , taskStatus );
69+ if (chainTask . getStatus () != ChainTaskStatus .ACTIVE ) {
70+ log .error ("Task not active on chain [chainTaskId:{}, status:{}]" ,
71+ chainTaskId , chainTask . getStatus () );
7472 return Optional .of (TASK_NOT_ACTIVE );
7573 }
7674
77- Optional < ChainDeal > optionalChainDeal = iexecHubService .getChainDeal (chainDealId );
78- if (optionalChainDeal . isEmpty () ) {
75+ final ChainDeal chainDeal = iexecHubService .getChainDeal (chainDealId ). orElse ( null );
76+ if (chainDeal == null ) {
7977 log .error ("isAuthorizedOnExecution failed (getChainDeal failed) [chainTaskId:{}]" , chainTaskId );
8078 return Optional .of (GET_CHAIN_DEAL_FAILED );
8179 }
82- ChainDeal chainDeal = optionalChainDeal .get ();
8380
84- boolean isTeeTaskOnchain = TeeUtils .isTeeTag (chainDeal .getTag ());
85- if (isTeeTask != isTeeTaskOnchain ) {
86- log .error ("Could not match onchain task type [isTeeTask:{}, isTeeTaskOnchain:{}, chainTaskId:{}, walletAddress :{}]" ,
87- isTeeTask , isTeeTaskOnchain , chainTaskId , workerpoolAuthorization . getWorkerWallet () );
81+ final boolean isTeeTaskOnchain = TeeUtils .isTeeTag (chainDeal .getTag ());
82+ if (! isTeeTaskOnchain ) {
83+ log .error ("Could not match onchain task type [isTeeTaskOnchain:{}, chainTaskId:{}]" ,
84+ isTeeTaskOnchain , chainTaskId );
8885 return Optional .of (NO_MATCH_ONCHAIN_TYPE );
8986 }
9087
91- String workerpoolAddress = chainDeal .getPoolOwner ();
92- boolean isSignerByWorkerpool = isSignedByHimself (workerpoolAuthorization .getHash (),
93- workerpoolAuthorization .getSignature ().getValue (), workerpoolAddress );
88+ final boolean isSignedByWorkerpool = isSignedByHimself (workerpoolAuthorization .getHash (),
89+ workerpoolAuthorization .getSignature ().getValue (), chainDeal .getPoolOwner ());
9490
95- if (!isSignerByWorkerpool ) {
96- log .error ("isAuthorizedOnExecution failed (invalid signature) [chainTaskId:{}, isWorkerpoolSignatureValid :{}]" ,
97- chainTaskId , isSignerByWorkerpool );
91+ if (!isSignedByWorkerpool ) {
92+ log .error ("isAuthorizedOnExecution failed (invalid signature) [chainTaskId:{}, isSignedByWorkerpool :{}]" ,
93+ chainTaskId , isSignedByWorkerpool );
9894 return Optional .of (INVALID_SIGNATURE );
9995 }
10096
@@ -110,14 +106,6 @@ public boolean isSignedByOwner(String message, String signature, String address)
110106 String owner = iexecHubService .getOwner (address );
111107 return !owner .isEmpty () && isSignedByHimself (message , signature , owner );
112108 }
113-
114- public String getChallengeForSetWeb3Secret (String secretAddress ,
115- String secretValue ) {
116- return HashUtils .concatenateAndHash (
117- Hash .sha3String (DOMAIN ),
118- secretAddress ,
119- Hash .sha3String (secretValue ));
120- }
121109 // endregion
122110
123111 // region challenges
@@ -152,6 +140,14 @@ public String getChallengeForSetWeb2Secret(String ownerAddress,
152140 Hash .sha3String (secretValue ));
153141 }
154142
143+ public String getChallengeForSetWeb3Secret (String secretAddress ,
144+ String secretValue ) {
145+ return HashUtils .concatenateAndHash (
146+ Hash .sha3String (DOMAIN ),
147+ secretAddress ,
148+ Hash .sha3String (secretValue ));
149+ }
150+
155151 public String getChallengeForWorker (WorkerpoolAuthorization workerpoolAuthorization ) {
156152 return HashUtils .concatenateAndHash (
157153 workerpoolAuthorization .getWorkerWallet (),
0 commit comments