HEAD ======= >>>>>>> release-0.2.0
1 <?php
2 /**
3 * Copyright 2012 Native5. All Rights Reserved
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * You may not use this file except in compliance with the License.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 * PHP version 5.3+
14 *
15 * @category Identity
16 * @package Native5\<package>
17 * @author Barada Sahu <barry@native5.com>
18 * @copyright 2012 Native5. All Rights Reserved
19 * @license See attached LICENSE for details
20 * @version GIT: $gitid$
21 * @link http://www.docs.native5.com
22 */
23
24 namespace Native5\Services\Identity;
25
26 use Native5\Services\Common\ApiClient;
27 use Native5\Identity\Authenticator;
28 use Native5\Identity\Logout;
29 use Native5\Identity\AuthenticationException;
<<<<<<< HEAD
30
31 /**
32 * RemoteAuthenticationService
33 *
34 * @category Services\Identity
35 * @package Native5\Services\Identity
36 * @author Barada Sahu <barry@native5.com>
37 * @copyright 2012 Native5. All Rights Reserved
38 * @license See attached NOTICE.md for details
39 * @version Release: 1.0
40 * @link http://www.docs.native5.com
41 * Created : 27-11-2012
42 * Last Modified : Fri Dec 21 09:11:53 2012
43 */
44 class RemoteAuthenticationService extends ApiClient implements Authenticator, Logout
45 {
46
47
48 /**
49 * authenticate
50 *
51 * @param mixed $token The AuthenticationToken
52 *
53 * @access public
54 * @return <code>AuthInfo</code>
55 * @throws AuthenticationException
56 */
57 public function authenticate($token)
58 {
59 $logger = $GLOBALS['logger'];
60 $path = 'users/authenticate';
61 $request = $this->_remoteServer->get($path);
62 $request->getQuery()->set('username', $token->getUser());
63 $request->getQuery()->set('password', $token->getPassword());
64 try {
65 $response = $request->send();
66 if ($response->getStatusCode() !== 200) {
67 throw new AuthenticationException();
68 }
69
70 $rawResponse = $response->json();
71 $logger->debug(print_r($rawResponse, 1));
72
73 $authInfo = new SimpleAuthInfo();
74 $authInfo->addPrincipal('Barada Sahu');
75 $authInfo->addPrincipal('Native5 Inc.');
76 return $authInfo;
77 } catch (\Exception $e) {
78 throw new AuthenticationException();
79 }
80
81 }//end authenticate()
82
83
84 /**
85 * logout
86 *
87 * @param mixed $principal Principals to logout.
88 *
89 * @access public
90 * @return void
91 */
92 public function onLogout($principal)
93 {
94 $path = 'users/logout';
95 $request = $this->_remoteServer->get($path);
96 $request->getQuery()->set('token', $principal->serialize('json'));
97 $request->send();
98
99 }//end onLogout()
100
101
102 }//end class
103
104 ?>
105
=======
30 use Native5\Identity\SimpleAuthInfo;
31
32 /**
33 * RemoteAuthenticationService
34 *
35 * @category Services\Identity
36 * @package Native5\Services\Identity
37 * @author Barada Sahu <barry@native5.com>
38 * @copyright 2012 Native5. All Rights Reserved
39 * @license See attached NOTICE.md for details
40 * @version Release: 1.0
41 * @link http://www.docs.native5.com
42 * Created : 27-11-2012
43 * Last Modified : Fri Dec 21 09:11:53 2012
44 */
45 class RemoteAuthenticationService extends ApiClient implements Authenticator, Logout
46 {
47
48
49 /**
50 * authenticate
51 *
52 * @param mixed $token The AuthenticationToken
53 *
54 * @access public
55 * @return <code>AuthInfo</code>
56 * @throws AuthenticationException
57 */
58 public function authenticate($token)
59 {
60 $logger = $GLOBALS['logger'];
61 $path = 'users/authenticate';
62 $request = $this->_remoteServer->get($path);
63 $request->getQuery()->set('username', $token->getUser());
64 $request->getQuery()->set('password', $token->getPassword());
65 try {
66 $response = $request->send();
67 if ($response->getStatusCode() !== 200) {
68 throw new AuthenticationException();
69 }
70
71 $rawResponse = $response->json();
72
73 $roles = isset($rawResponse['roles'])?explode(',',$rawResponse['roles']):array();
74 $authInfo = new SimpleAuthInfo();
75 $authInfo->addPrincipal($rawResponse['displayName']);
76 $authInfo->addPrincipal($rawResponse['email']);
77 $authInfo->addPrincipal($rawResponse['account']);
78
79 $tokens = isset($rawResponse['token'])?$rawResponse['token']: array();
80 return array($authInfo, $roles, $tokens);
81 } catch (\Exception $e) {
82 throw new AuthenticationException();
83 }
84
85 }//end authenticate()
86
87
88 /**
89 * logout
90 *
91 * @param mixed $principal Principals to logout.
92 *
93 * @access public
94 * @return void
95 */
96 public function onLogout($principal)
97 {
98 $path = 'users/logout';
99 $request = $this->_remoteServer->get($path);
100 $request->getQuery()->set('token', $principal->serialize('json'));
101 $request->send();
102
103 }//end onLogout()
104
105
106 }//end class
107
108 ?>
109
>>>>>>> release-0.2.0