Merge branch 'sch_sso' into 'develop'

casost module: redirect response with cookie, destroy session on logout. front end: retrieve cookie data and remove

See merge request !58
parents 6252fe24 b2513ef9
...@@ -13,6 +13,8 @@ use Symfony\Component\HttpFoundation\Response; ...@@ -13,6 +13,8 @@ use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Cookie;
require ('RedirectResponseWithCookie.php');
class CASLogin extends ControllerBase class CASLogin extends ControllerBase
{ {
...@@ -177,7 +179,12 @@ class CASLogin extends ControllerBase ...@@ -177,7 +179,12 @@ class CASLogin extends ControllerBase
// $this->logger->warning('cn=' . $filterAttribute('cn')); // $this->logger->warning('cn=' . $filterAttribute('cn'));
$epalToken = $this->authenticatePhase2($request, $CASUser, $filterAttribute('cn')); $epalToken = $this->authenticatePhase2($request, $CASUser, $filterAttribute('cn'));
if ($epalToken) { if ($epalToken) {
return new RedirectResponse($this->redirectUrl . '?auth_token=' . $epalToken.'&auth_role=director', 302, []); $cookie = new Cookie('auth_token', $epalToken, 0, '/', null, false, false);
$cookie2 = new Cookie('auth_role', 'director', 0, '/', null, false, false);
return new RedirectResponseWithCookie($this->redirectUrl, 302, array ($cookie, $cookie2));
// $headers = array("auth_token" => $epalToken, "auth_role" => "director");
// return new RedirectResponse($this->redirectUrl, 302, $headers);
} else { } else {
$response = new Response(); $response = new Response();
$response->setContent('forbidden'); $response->setContent('forbidden');
......
...@@ -70,6 +70,7 @@ class CASLogout extends ControllerBase ...@@ -70,6 +70,7 @@ class CASLogout extends ControllerBase
$this->serverHostname = $CASOSTConfig->serverhostname->value; $this->serverHostname = $CASOSTConfig->serverhostname->value;
$this->serverPort = $CASOSTConfig->serverport->value; $this->serverPort = $CASOSTConfig->serverport->value;
$this->serverUri = $CASOSTConfig->serveruri->value === null ? '' : $CASOSTConfig->serveruri->value; $this->serverUri = $CASOSTConfig->serveruri->value === null ? '' : $CASOSTConfig->serveruri->value;
$this->redirectUrl = $CASOSTConfig->redirecturl->value;
$this->changeSessionId = $CASOSTConfig->changesessionid->value; $this->changeSessionId = $CASOSTConfig->changesessionid->value;
$this->CASServerCACert = $CASOSTConfig->casservercacert->value; $this->CASServerCACert = $CASOSTConfig->casservercacert->value;
$this->CASServerCNValidate = $CASOSTConfig->casservercnvalidate->value; $this->CASServerCNValidate = $CASOSTConfig->casservercnvalidate->value;
...@@ -116,15 +117,15 @@ class CASLogout extends ControllerBase ...@@ -116,15 +117,15 @@ class CASLogout extends ControllerBase
return $response; return $response;
} }
// phpCAS::handleLogoutRequests(); // phpCAS::handleLogoutRequests();
// phpCAS::logout(); // phpCAS::logoutWithRedirectService('http://eduslim2.minedu.gov.gr/dist/#/school');
session_unset();
session_destroy();
$user->setPassword(uniqid('pw')); $user->setPassword(uniqid('pw'));
$user->save(); $user->save();
$response = new Response(); $response = new Response();
$response->setContent('logout successful'); $response->setContent('logout successful');
$response->setStatusCode(Response::HTTP_OK); $response->setStatusCode(Response::HTTP_OK);
$response->headers->set('Content-Type', 'application/json'); $response->headers->set('Content-Type', 'application/json');
$this->logger->warning("/dist/#/school?auth_token=&auth_role=");
// return new RedirectResponse('/dist/#/school?auth_token=&auth_role=', 302, []);
return $response; return $response;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->warning($e->getMessage()); $this->logger->warning($e->getMessage());
......
<?php
/*
* A RedirectResponse object with cookie sending
*/
namespace Drupal\casost\Controller;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* RedirectResponseWithCookie represents an HTTP response doing a redirect and sending cookies.
*/
class RedirectResponseWithCookie extends RedirectResponse
{
/**
* Creates a redirect response so that it conforms to the rules defined for a redirect status code.
*
* @param string $url The URL to redirect to
* @param integer $status The status code (302 by default)
* @param Symfony\Component\HttpFoundation\Cookie[] $cookies An array of Cookie objects
*/
public function __construct($url, $status = 302, $cookies = array ())
{
parent::__construct($url, $status);
foreach ($cookies as $cookie)
{
if (!$cookie instanceof Cookie)
{
throw new \InvalidArgumentException(sprintf('Third parameter is not a valid Cookie object.'));
}
$this->headers->setCookie($cookie);
}
}
}
// export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal'; // export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal';
export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal-8.2.6'; export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal';
export class AppSettings { export class AppSettings {
public static get API_ENDPOINT(): string { public static get API_ENDPOINT(): string {
// return 'http://eduslim2.minedu.gov.gr/drupal'; // return 'http://eduslim2.minedu.gov.gr/drupal';
return 'http://eduslim2.minedu.gov.gr/drupal-8.2.6'; return 'http://eduslim2.minedu.gov.gr/drupal';
} }
} }
...@@ -5,6 +5,7 @@ import 'core-js/es7/reflect'; ...@@ -5,6 +5,7 @@ import 'core-js/es7/reflect';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { NgReduxModule, DevToolsExtension, NgRedux } from 'ng2-redux'; import { NgReduxModule, DevToolsExtension, NgRedux } from 'ng2-redux';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import { CookieModule } from 'ngx-cookie';
import { import {
FormsModule, FormsModule,
ReactiveFormsModule, ReactiveFormsModule,
...@@ -63,7 +64,8 @@ class MyLocalization extends NgLocalization { ...@@ -63,7 +64,8 @@ class MyLocalization extends NgLocalization {
Ng2SmartTableModule, Ng2SmartTableModule,
NgReduxModule, NgReduxModule,
ModalModule.forRoot(), ModalModule.forRoot(),
AlertModule.forRoot() AlertModule.forRoot(),
CookieModule.forRoot()
], ],
declarations: [ declarations: [
Main, FooterComponent, HeaderComponent, NavbarComponent, MainComponent, Main, FooterComponent, HeaderComponent, NavbarComponent, MainComponent,
......
...@@ -6,6 +6,7 @@ import { NgRedux, select } from 'ng2-redux'; ...@@ -6,6 +6,7 @@ import { NgRedux, select } from 'ng2-redux';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { IAppState } from '../store/store'; import { IAppState } from '../store/store';
import { HelperDataService } from '../services/helper-data-service'; import { HelperDataService } from '../services/helper-data-service';
import { CookieService } from 'ngx-cookie';
import { import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
...@@ -49,7 +50,8 @@ export default class SchoolHome implements OnInit { ...@@ -49,7 +50,8 @@ export default class SchoolHome implements OnInit {
private _ngRedux: NgRedux<IAppState>, private _ngRedux: NgRedux<IAppState>,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private _hds: HelperDataService, private _hds: HelperDataService,
private router: Router private router: Router,
private _cookieService:CookieService
) { ) {
this.authToken = ''; this.authToken = '';
this.authRole = ''; this.authRole = '';
...@@ -59,6 +61,14 @@ export default class SchoolHome implements OnInit { ...@@ -59,6 +61,14 @@ export default class SchoolHome implements OnInit {
}; };
ngOnInit() { ngOnInit() {
this.authToken = this.getCookie('auth_token');
this.authRole = this.getCookie('auth_role');
if (this.authToken && this.authRole) {
this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole });
this.removeCookie('auth_token');
this.removeCookie('auth_role');
}
this.loginInfo$ = this._ngRedux.select(state => { this.loginInfo$ = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) { if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => { state.loginInfo.reduce(({}, loginInfoToken) => {
...@@ -72,26 +82,16 @@ export default class SchoolHome implements OnInit { ...@@ -72,26 +82,16 @@ export default class SchoolHome implements OnInit {
return state.loginInfo; return state.loginInfo;
}); });
}
// subscribe to router event getCookie(key: string){
this.activatedRoute.queryParams.subscribe((params: Params) => { return this._cookieService.get(key);
if (params) { }
this.authToken = params['auth_token'];
console.log("NIKOS1");
console.log(this.authToken );
this.authRole = params['auth_role'];
console.log("NIKOS2");
console.log(this.authRole );
}
if (this.authToken && this.authRole)
this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole });
}); removeCookie(key: string){
return this._cookieService.remove(key);
} }
checkvalidation() { checkvalidation() {
} }
......
...@@ -428,6 +428,7 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -428,6 +428,7 @@ export class HelperDataService implements OnInit, OnDestroy {
"Content-Type": "application/json", "Content-Type": "application/json",
"Accept": "*/*", "Accept": "*/*",
"Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Origin": "*",
// "Content-Type": "text/plain", // try to skip preflight // "Content-Type": "text/plain", // try to skip preflight
//"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY" //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
//"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8" //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment