55 * @author Bernd Rederlechner <bernd.rederlechner@t-systems.com>
66 *
77 * @license AGPL-3.0
8- *
9- * This code is free software: you can redistribute it and/or modify
10- * it under the terms of the GNU Affero General Public License, version 3,
11- * as published by the Free Software Foundation.
12- *
13- * This program is distributed in the hope that it will be useful,
14- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16- * GNU Affero General Public License for more details.
17- *
18- * You should have received a copy of the GNU Affero General Public License, version 3,
19- * along with this program. If not, see <http://www.gnu.org/licenses/>
20- *
218 */
229
2310namespace OCA \NextMagentaCloudSlup \Controller ;
2411
2512use OCA \NextMagentaCloudProvisioning \Rules \DisplaynameRules ;
2613use OCA \NextMagentaCloudProvisioning \Rules \TariffRules ;
2714use OCA \NextMagentaCloudProvisioning \Rules \UserAccountRules ;
28-
2915use OCA \NextMagentaCloudSlup \Registration \SlupRegistrationManager ;
3016use OCA \NextMagentaCloudSlup \Service \ForbiddenException ;
3117use OCA \NextMagentaCloudSlup \Service \NotFoundException ;
3622class SlupApiController extends SoapApiController {
3723 public const PROVIDER_PREFIX = 'Telekom ' ;
3824
39- /** LoggerInterface already comes from parent class */
40-
4125 /** @var SlupRegistrationManager */
4226 private $ slupRegistrationMgr ;
4327
4428 /** @var TariffRules */
4529 private $ tariffRules ;
4630
47- /** @var UserAccountService */
31+ /** @var UserAccountRules */
4832 private $ accountRules ;
4933
5034 /** @var DisplaynameRules */
5135 private $ displaynameRules ;
5236
53- /**
54- * constructor of the controller
55- *
56- * @param string $appName the name of the app
57- * @param IRequest $request an instance of the request
58- * @param string $corsMethods comma separated string of HTTP verbs which
59- * should be allowed for websites or webapps when calling your API, defaults to
60- * 'POST' only for SOAP messages
61- * @param string $corsAllowedHeaders comma separated string of HTTP headers
62- * which should be allowed for websites or webapps when calling your API,
63- * defaults to 'Authorization, Content-Type, Accept'
64- * @param int $corsMaxAge number in seconds how long a preflighted OPTIONS
65- * request should be cached, defaults to 1728000 seconds
66- */
6737 public function __construct ($ appName ,
6838 IRequest $ request ,
6939 LoggerInterface $ logger ,
@@ -87,9 +57,6 @@ public function __construct($appName,
8757 }
8858
8959 /**
90- * Depending on the settings here,
91- * SOAP could be protected by login or not.
92- *
9360 * @NoAdminRequired
9461 * @NoCSRFRequired
9562 * @PublicPage
@@ -113,22 +80,24 @@ public function getUserDetails($request, string $field, string $prefix = 'urn:te
11380 foreach ($ request ->$ field as $ element ) {
11481 $ claims ->{$ prefix . $ element ->name } = $ element ->val ;
11582 }
83+
11684 return $ claims ;
11785 }
11886
119-
12087 private function extractProperty ($ claims , string $ prefix , string $ property ) {
12188 if ($ claims === null || $ prefix === null || $ property === null ) {
12289 return null ;
12390 }
124- return property_exists ($ claims , $ prefix . $ property ) ? $ claims ->{$ prefix . $ property } : null ;
91+
92+ return property_exists ($ claims , $ prefix . $ property ) ? $ claims ->{$ prefix . $ property } : null ;
12593 }
12694
12795 private function getProperty ($ newFieldsClaims , $ oldFieldsClaims , string $ prefix , string $ property ) {
12896 $ propertyValue = $ this ->extractProperty ($ newFieldsClaims , $ prefix , $ property );
12997 if ($ propertyValue === null ) {
13098 $ propertyValue = $ this ->extractProperty ($ oldFieldsClaims , $ prefix , $ property );
13199 }
100+
132101 return $ propertyValue ;
133102 }
134103
@@ -142,12 +111,11 @@ private function getDisplayName($newFieldsClaims, $oldFieldsClaims, string $pref
142111
143112 private function getEmail ($ newFieldsClaims , $ oldFieldsClaims , string $ prefix = 'urn:telekom.com: ' ) {
144113 $ mainEmail = $ this ->getProperty ($ newFieldsClaims , $ oldFieldsClaims , $ prefix , 'mainEmail ' );
145- if ($ mainEmail != null ) {
114+ if ($ mainEmail !== null ) {
146115 return $ mainEmail ;
147- } else {
148- return $ this ->getProperty ($ newFieldsClaims , $ oldFieldsClaims , $ prefix , 'extMail ' );
149116 }
150117
118+ return $ this ->getProperty ($ newFieldsClaims , $ oldFieldsClaims , $ prefix , 'extMail ' );
151119 }
152120
153121 private function getAltEmail ($ newFieldsClaims , $ oldFieldsClaims , string $ prefix = 'urn:telekom.com: ' ) {
@@ -158,26 +126,18 @@ private function getQuota($newFieldsClaims, string $prefix = 'urn:telekom.com:')
158126 return $ this ->tariffRules ->deriveQuota ($ newFieldsClaims );
159127 }
160128
161- // ---------------- Supported SOAP functions ------------------------
162129 public function SLUP ($ request ) {
163130 $ this ->logger ->info ("Counting message. " );
164131 $ this ->slupRegistrationMgr ->incrementRecvCount ();
165132
166133 $ this ->logger ->info ("Checking token. " );
167134 $ token = strval ($ request ->token );
135+
168136 if (!$ this ->slupRegistrationMgr ->isValidToken ($ token )) {
169137 $ this ->logger ->error ("SLUP invalid token on message. " );
170- // save the currently send token to validate the follow-up disconnect
171- // message that must follow
172- $ this ->slupRegistrationMgr ->setToken ($ token );
173- // signal invalid token
174138 return array ('returncode ' => 'F003 ' , 'detail ' => 'invalid token ' );
175139 }
176140
177- // we should not assume any circuit breaker state here as a parallel
178- // disconnect could happen while processing
179-
180- // process messages
181141 if ($ request ->request != 'UTS ' && $ request ->request != 'UTN ' ) {
182142 $ this ->logger ->warning ("SLUP request type is other than 'UTS' or 'UTN' " );
183143 return array ('returncode ' => '0000 ' , 'detail ' => 'ok ' );
@@ -193,17 +153,26 @@ public function SLUP($request) {
193153
194154 try {
195155 $ this ->logger ->info ("User account modification start " );
196- $ evalResult = $ this ->accountRules ->deriveAccountState ($ userName , $ displayName , $ email , $ quota ,
197- $ newFieldsClaims , false , self ::PROVIDER_PREFIX );
156+ $ evalResult = $ this ->accountRules ->deriveAccountState (
157+ $ userName ,
158+ $ displayName ,
159+ $ email ,
160+ $ quota ,
161+ $ newFieldsClaims ,
162+ false ,
163+ self ::PROVIDER_PREFIX
164+ );
165+
198166 $ this ->logger ->info (json_encode ($ evalResult ));
167+
199168 if ($ evalResult ['changed ' ]) {
200169 return array ('returncode ' => '0010 ' , 'detail ' => $ evalResult ['reason ' ]);
201- } else {
202- return array ('returncode ' => '0000 ' , 'detail ' => $ evalResult ['reason ' ]);
203170 }
171+
172+ return array ('returncode ' => '0000 ' , 'detail ' => $ evalResult ['reason ' ]);
204173 } catch (\InvalidArgumentException | ForbiddenException | NotFoundException | UserExistException | \Exception $ e ) {
205174 $ this ->logger ->logException ($ e , [
206- 'message ' => "SLUP processing error: {$ e ->getMessage ()}): " . PHP_EOL . json_encode ($ request ),
175+ 'message ' => "SLUP processing error: {$ e ->getMessage ()}): " . PHP_EOL . json_encode ($ request ),
207176 'level ' => LoggerInterface::ERROR ,
208177 'app ' => 'nmcslup '
209178 ]);
@@ -214,36 +183,31 @@ public function SLUP($request) {
214183
215184 public function SLUPConnect ($ request ) {
216185 $ token = strval ($ request ->token );
186+
217187 if (!$ this ->slupRegistrationMgr ->isValidToken ($ token )) {
218188 $ this ->logger ->error ("SLUP invalid token on connect. " );
219- // with this, we get a disconnect next
220189 return array ('returncode ' => 'F003 ' , 'detail ' => 'invalid token ' );
221190 }
222191
223- // we should not assume any circuit breaker state here as a parallel
224- // disconnect could happen while processing
225-
226192 return array ('returncode ' => '0000 ' , 'detail ' => 'connected ' );
227193 }
228194
229195 public function SLUPDisconnect ($ request ) {
230196 $ token = strval ($ request ->token );
197+
231198 if ($ token == '0 ' ) {
232- // a special connection test
233199 $ this ->logger ->info ("SLUP gateway connection test ok. " );
234200 return array ('returncode ' => '0000 ' , 'detail ' => 'connection ok ' );
235201 }
236202
237- // we should not assume any circuit breaker state here as a parallel
238- // disconnect could happen while processing
239203 if (!$ this ->slupRegistrationMgr ->isValidToken ($ token )) {
240204 $ this ->logger ->error ("SLUP invalid token on disconnect. " );
241- // with this, we get a disconnect next
242205 return array ('returncode ' => 'F003 ' , 'detail ' => 'invalid token ' );
243- } else {
244- $ this ->slupRegistrationMgr ->clearToken ();
245- $ this ->slupRegistrationMgr ->circuitOpen ();
246- return array ('returncode ' => '0000 ' , 'detail ' => 'disconnected ' );
247206 }
207+
208+ $ this ->slupRegistrationMgr ->clearToken ();
209+ $ this ->slupRegistrationMgr ->circuitOpen ();
210+
211+ return array ('returncode ' => '0000 ' , 'detail ' => 'disconnected ' );
248212 }
249213}
0 commit comments