@@ -26,15 +26,37 @@ class OpenStackIdAuthenticator extends Controller
2626 */
2727 private $ member_repository ;
2828
29- public function __construct ()
29+ /**
30+ * @var Auth_OpenID_Consumer
31+ */
32+ private $ openid_consumer ;
33+
34+ /**
35+ * @var Auth_OpenID_OpenIDStore
36+ */
37+ private $ openid_repository ;
38+
39+ /**
40+ * OpenStackIdAuthenticator constructor.
41+ * @param IMemberRepository $member_repository
42+ * @param Auth_OpenID_OpenIDStore $openid_repository
43+ * @param Auth_OpenID_Consumer $openid_consumer
44+ */
45+ public function __construct
46+ (
47+ IMemberRepository $ member_repository ,
48+ Auth_OpenID_OpenIDStore $ openid_repository ,
49+ Auth_OpenID_Consumer $ openid_consumer
50+ )
3051 {
3152 parent ::__construct ();
32- $ this ->member_repository = new SapphireCLAMemberRepository ();
53+ $ this ->member_repository = $ member_repository ;
54+ $ this ->openid_repository = $ openid_repository ;
55+ $ this ->openid_consumer = $ openid_consumer ;
3356 }
3457
3558 function index ()
3659 {
37-
3860 try {
3961
4062 $ member = Member::currentUser ();
@@ -43,27 +65,27 @@ function index()
4365 // user is already logged in
4466 return $ this ->redirect (OpenStackIdCommon::getRedirectBackUrl ());
4567 }
46-
47- $ consumer = Injector::inst ()->get ('MyOpenIDConsumer ' );
48-
4968 $ query = Auth_OpenID::getQuery ();
69+
5070 $ message = Auth_OpenID_Message::fromPostArgs ($ query );
5171 $ nonce = $ message ->getArg (Auth_OpenID_OPENID2_NS,'response_nonce ' );
5272 list ($ timestamp , $ salt ) = Auth_OpenID_splitNonce ($ nonce );
5373 $ claimed_id = $ message ->getArg (Auth_OpenID_OPENID2_NS,'claimed_id ' );
5474
55- SS_Log::log (sprintf ('OpenStackIdAuthenticator : id %s - salt %s - timestamp %s ' ,$ claimed_id , $ salt , $ timestamp ), SS_Log::DEBUG );
75+ SS_Log::log (sprintf ('OpenStackIdAuthenticator : id %s - salt %s - timestamp %s - query %s ' ,$ claimed_id , $ salt , $ timestamp, implode ( ' , ' , $ query ) ), SS_Log::DEBUG );
5676
5777 // Complete the authentication process using the server's response.
58- $ response = $ consumer ->complete (OpenStackIdCommon::getReturnTo ());
78+ $ response = $ this -> openid_consumer ->complete (OpenStackIdCommon::getReturnTo ());
5979
6080 if ($ response ->status == Auth_OpenID_CANCEL) {
6181 SS_Log ::log ('OpenStackIdAuthenticator : Auth_OpenID_CANCEL ' , SS_Log::WARN );
6282 throw new Exception ('The verification was cancelled. Please try again. ' );
63-
6483 } else if ($ response ->status == Auth_OpenID_FAILURE) {
65- SS_Log ::log ('OpenStackIdAuthenticator : Auth_OpenID_FAILURE ' , SS_Log::WARN );
66- throw new Exception ("The OpenID authentication failed. " );
84+ SS_Log ::log ("OpenStackIdAuthenticator : Auth_OpenID_FAILURE {$ response ->message }" , SS_Log::WARN );
85+ // delete associations
86+ SS_Log ::log ("OpenStackIdAuthenticator : Auth_OpenID_FAILURE cleaning openid_repository ... " , SS_Log::WARN );
87+ $ this ->openid_repository ->reset ();
88+ throw new Exception ("The OpenID authentication failed " );
6789
6890 } else if ($ response ->status == Auth_OpenID_SUCCESS) {
6991 SS_Log ::log ('OpenStackIdAuthenticator : Auth_OpenID_SUCCESS ' , SS_Log::DEBUG );
@@ -98,10 +120,8 @@ function index()
98120 throw new Exception ("The OpenID authentication failed: can not find user " .$ openid );
99121 }
100122 } catch (Exception $ ex ) {
101- Session::set ("Security.Message.message " , $ ex ->getMessage ());
102- Session::set ("Security.Message.type " , "bad " );
103- SS_Log ::log ($ ex , SS_Log::DEBUG );
104- return $ this ->redirect ("Security/badlogin " );
123+ SS_Log ::log ($ ex , SS_Log::WARN );
124+ return OpenStackIdCommon::error ($ ex ->getMessage (), OpenStackIdCommon::getRedirectBackUrl ());
105125 }
106126 }
107127
0 commit comments