Ejemplo n.º 1
0
 /**
  * @param string $username
  * @param string $password
  * @return User
  * @throws \Exception
  */
 private function userCasAuthentication($username, $password)
 {
     $client = new CasRestClient();
     $client->setCasServer($this->serverLoginUrl);
     $client->setCasRestContext($this->serverTicket);
     $client->setCredentials($username, $password);
     $client->verifySSL($this->verifySsl());
     if ($client->login()) {
         $response = $client->post($this->getServiceRoute());
         if ($response->getStatusCode() == 200) {
             $user = new User($username, $this->apiRecolnatBaseUri, $this->apiRecolnatUserPath, $this->getContainer()->getParameter('user_group'));
             return $user;
         } else {
             $this->log($this->translator->trans($username . ' access.denied.wrongPermission', [], 'exceptions'));
             throw new AccessDeniedException($this->getContainer()->get('translator')->trans('access.denied.wrongPassword', [], 'exceptions'));
         }
     } else {
         $this->log($this->translator->trans($username . ' access.denied.wrongPermission', [], 'exceptions'));
         throw new AccessDeniedException($this->getContainer()->get('translator')->trans('access.denied.wrongPassword', [], 'exceptions'));
     }
 }
Ejemplo n.º 2
0
 public function testServiceGet()
 {
     $client = new CasRestClient();
     $client->setCasServer('https://example.org');
     $client->setCredentials('user', 'secret');
     // Create a mock subscriber and response.
     $mock = new MockHandler([new Response(201, ['Location' => 'https://example.org/cas/v1/tickets/TGT-1-1qaz2wsx3edc']), new Response(201, [], 'ST-1-abc123'), new Response(200, [], 'test..1..2..3')]);
     $handler = HandlerStack::create($mock);
     // Add the mock subscriber to the client.
     $client->setGuzzleClient(new Client(['base_uri' => 'https://example.org', 'handler' => $handler]));
     $client->login();
     $this->assertEquals((string) $client->get('https://www.example.com?param1=true')->getBody(), 'test..1..2..3');
 }
Ejemplo n.º 3
0
<?php

use epierce\CasRestClient;
require_once 'vendor/autoload.php';
$client = new CasRestClient();
// Configure CAS client
$client->setCasServer('https://cas.exmaple.edu');
$client->setCasRestContext('/v1/tickets');
$client->setCredentials("username", "password");
// Login and save TGT to a file
$client->login('/tmp/cas_tgt.json');
// Make a webservice call
$response = $client->get("https://someservice");
print_r(json_decode($response->getBody(), true));
// Make another call using the same SSO session
$headers = ['User-Agent' => 'testing/1.0'];
$post_params = ['param1' => 'foo', param2 => 'bar'];
$response = $client->post("https://someotherservice", $headers, '', $post_params);
print_r(json_decode($response->getBody(), true));
$client->logout();