Skip to content

Commit ef4cbd5

Browse files
committed
Merge branch 'auth-cas' of github.com:pitchum/EdPaste into auth-cas
2 parents 2e576ed + 313996f commit ef4cbd5

14 files changed

+199
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ composer.phar
4545
/.vscode
4646
composer.lock
4747
/.vscode
48+
config/cas.php

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Run a `composer install`/`php composer install` (depends of your configuration)
2424
Rename `.env.example` to `.env` and run `php artisan key:generate` from the app's root path.
2525
Open `.env` and fill it with your database details
2626
Run `php artisan migrate` from the app's root path, and you're all done.
27+
Copy and adapt CAS configuration from `config/cas.example.php` to `config/cas.php`.
2728

2829
Go to `http://your.vhost.server.com/` which leads to the DocumentRoot `/app/path/public`, and this should work !
2930

app/Http/Controllers/PasteController.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ public function view($link, Request $request){
102102
$paste = Paste::where('link', $link)->firstOrFail();
103103

104104
// Est-ce que l'utilisateur connecté est celui qui a écrit la paste ?
105-
cas()->isAuthenticated();
106-
$username = cas()->getCurrentUser();
107-
$user = User::where('name', $username)->first();
108-
$isSameUser = (($user->id == $paste->userId && $paste->userId != 0)) ? true : false;
105+
if (cas()->isAuthenticated()) {
106+
$username = cas()->getCurrentUser();
107+
$user = User::where('name', $username)->first();
108+
$isSameUser = (($user->id == $paste->userId && $paste->userId != 0)) ? true : false;
109+
} else {
110+
$isSameUser = false;
111+
}
109112

110113
// Expiration de la paste
111114
if($paste->expiration != 0){

app/Http/Kernel.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class Kernel extends HttpKernel
4949
protected $routeMiddleware = [
5050
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
5151
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
52-
'cas.auth' => \Subfission\Cas\Middleware\CASAuth::class,
53-
'cas.guest' => \Subfission\Cas\Middleware\RedirectCASAuthenticated::class,
52+
'cas.auth' => \Subfission\Cas\Middleware\CASAuth::class,
53+
'cas.guest' => \Subfission\Cas\Middleware\RedirectCASAuthenticated::class,
5454
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
5555
'can' => \Illuminate\Auth\Middleware\Authorize::class,
5656
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,

config/cas.example.php

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
return [
3+
/*
4+
|--------------------------------------------------------------------------
5+
| CAS Hostname
6+
|--------------------------------------------------------------------------
7+
| Example: 'cas.myuniv.edu'.
8+
*/
9+
'cas_hostname' => env('CAS_HOSTNAME', 'sso.mycompany.com'),
10+
11+
/*
12+
|--------------------------------------------------------------------------
13+
| CAS Authorized Hosts
14+
|--------------------------------------------------------------------------
15+
| Example: 'cas.myuniv.edu'. This is used when SAML is active and is
16+
| recommended for protecting against DOS attacks. If using load
17+
| balanced hosts, then separate each with a comma.
18+
*/
19+
'cas_real_hosts' => env('CAS_REAL_HOSTS', 'sso.mycompany.com'),
20+
21+
22+
/*
23+
|--------------------------------------------------------------------------
24+
| Customize CAS Session Cookie Name
25+
|--------------------------------------------------------------------------
26+
*/
27+
'cas_session_name' => env('CAS_SESSION_NAME', 'CASAuth'),
28+
29+
/*
30+
|--------------------------------------------------------------------------
31+
| Laravel has it's own authentication sessions. Unless you want phpCAS
32+
| to manage the session, leave this set to false. Note that the
33+
| middleware and redirect classes will be handling removal
34+
| of the Laravel sessions when this is set to false.
35+
|--------------------------------------------------------------------------
36+
*/
37+
'cas_control_session' => env('CAS_CONTROL_SESSIONS', false),
38+
39+
/*
40+
|--------------------------------------------------------------------------
41+
| Enable using this as a cas proxy
42+
|--------------------------------------------------------------------------
43+
*/
44+
'cas_proxy' => env('CAS_PROXY', false),
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Cas Port
49+
|--------------------------------------------------------------------------
50+
| Usually 443
51+
*/
52+
'cas_port' => env('CAS_PORT', 443),
53+
54+
/*
55+
|--------------------------------------------------------------------------
56+
| CAS URI
57+
|--------------------------------------------------------------------------
58+
| Sometimes is /cas
59+
*/
60+
'cas_uri' => env('CAS_URI', '/idp/cas'),
61+
62+
/*
63+
|--------------------------------------------------------------------------
64+
| CAS Validation
65+
|--------------------------------------------------------------------------
66+
| CAS server SSL validation: 'self' for self-signed certificate, 'ca' for
67+
| certificate from a CA, empty for no SSL validation.
68+
|
69+
| VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL
70+
*/
71+
'cas_validation' => env('CAS_VALIDATION', ''),
72+
73+
/*
74+
|--------------------------------------------------------------------------
75+
| CA Certificate
76+
|--------------------------------------------------------------------------
77+
| Path to the CA certificate file. For production use set
78+
| the CA certificate that is the issuer of the cert
79+
*/
80+
'cas_cert' => env('CAS_CERT', ''),
81+
82+
/*
83+
|--------------------------------------------------------------------------
84+
| CN Validation (if you are using CA certs)
85+
|--------------------------------------------------------------------------
86+
| If for some reason you want to disable validating the certificate
87+
| intermediaries, here is where you can. Recommended to leave
88+
| this set with default (true).
89+
*/
90+
'cas_validate_cn' => env('CAS_VALIDATE_CN', true),
91+
92+
/*
93+
|--------------------------------------------------------------------------
94+
| CAS Login URI
95+
|--------------------------------------------------------------------------
96+
| Empty is fine
97+
*/
98+
'cas_login_url' => env('CAS_LOGIN_URL', ''),
99+
100+
/*
101+
|--------------------------------------------------------------------------
102+
| CAS Logout URI
103+
|--------------------------------------------------------------------------
104+
*/
105+
'cas_logout_url' => env('CAS_LOGOUT_URL', 'https://sso.mycompany.com/idp/cas/logout'),
106+
107+
/*
108+
|--------------------------------------------------------------------------
109+
| CAS Logout Redirect Services
110+
|--------------------------------------------------------------------------
111+
| If your server supports redirection services, enter the redirect url
112+
| in this section. If left blank, it will default to disabled.
113+
*/
114+
'cas_logout_redirect' => env('CAS_LOGOUT_REDIRECT', ''),
115+
116+
/*
117+
|--------------------------------------------------------------------------
118+
| CAS Successful Logon Redirection Url
119+
|--------------------------------------------------------------------------
120+
| By default, CAS will assume that the user should be redirected to the
121+
| page in which the call was initiated. You can override this method
122+
| and force the user to be redirected to a specific URL here.
123+
*/
124+
'cas_redirect_path' => env('CAS_REDIRECT_PATH', ''),
125+
126+
/*
127+
|--------------------------------------------------------------------------
128+
| CAS Supports SAML 1.1, allowing you to retrieve more than just the
129+
| user identifier. If your CAS authentication service supports
130+
| this feature, you may be able to retrieve user meta data.
131+
|--------------------------------------------------------------------------
132+
*/
133+
'cas_enable_saml' => env('CAS_ENABLE_SAML', false),
134+
135+
/*
136+
|--------------------------------------------------------------------------
137+
| CAS will support version 1.0, 2.0, 3.0 of the protocol. It is recommended
138+
| to use version 2.0, 3.0, or SAML 1.1. If you enable SAML, then that
139+
| will override this configuration.
140+
|--------------------------------------------------------------------------
141+
*/
142+
'cas_version' => env('CAS_VERSION', "2.0"),
143+
144+
/*
145+
|--------------------------------------------------------------------------
146+
| Enable PHPCas Debug Mode
147+
| Options are:
148+
| 1) true (defaults logfile creation to /tmp/phpCAS.log)
149+
| 2) 'path/to/logfile'
150+
| 3) false
151+
|--------------------------------------------------------------------------
152+
*/
153+
'cas_debug' => env('CAS_DEBUG', false),
154+
155+
/*
156+
|--------------------------------------------------------------------------
157+
| Enable Verbose error messages. Not recommended for production.
158+
| true | false
159+
|--------------------------------------------------------------------------
160+
*/
161+
'cas_verbose_errors' => env('CAS_VERBOSE_ERRORS', false),
162+
163+
/*
164+
|--------------------------------------------------------------------------
165+
| This will cause CAS to skip authentication and assume this user id.
166+
| This should only be used for developmental purposes. getAttributes()
167+
| will return null in this condition.
168+
*/
169+
'cas_masquerade' => env('CAS_MASQUERADE', '')
170+
];

resources/views/auth/login.blade.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
@section('navbar')
66
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
7+
{{--
78
<li class="nav-item active"><a href="#" class="nav-link">Login</a></li>
89
<li class="nav-item"><a href="/register" class="nav-link">Register</a></li>
10+
--}}
911
@endsection
1012

1113
@section('content')

resources/views/auth/register.blade.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
@section('navbar')
66
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
7+
{{--
78
<li class="nav-item"><a href="/login" class="nav-link">Login</a></li>
89
<li class="nav-item active"><a href="#" class="nav-link">Register</a></li>
10+
--}}
911
@endsection
1012

1113
@section('content')

resources/views/layouts/app.blade.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<ul class="nav navbar-nav">
4646
&nbsp;
4747
</ul>
48-
48+
{{--
4949
<!-- Right Side Of Navbar -->
5050
<ul class="nav navbar-nav navbar-right">
5151
<!-- Authentication Links -->
@@ -74,6 +74,7 @@
7474
</li>
7575
@endif
7676
</ul>
77+
--}}
7778
</div>
7879
</div>
7980
</nav>

resources/views/paste/account.blade.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@section('navbar')
66
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
7+
{{--
78
@if (Auth::check())
89
<li class="nav-item"><a href="/users/dashboard" class="nav-link">Dashboard</a></li>
910
<li class="nav-item active"><a href="/users/account" class="nav-link">My Account</a></li>
@@ -12,6 +13,7 @@
1213
<li class="nav-item"><a href="/login" class="nav-link">Login</a></li>
1314
<li class="nav-item"><a href="/register" class="nav-link">Register</a></li>
1415
@endif
16+
--}}
1517
@endsection
1618

1719
@section('content')<div class="container">

resources/views/paste/dashboard.blade.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@section('navbar')
66
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
7+
{{--
78
@if (Auth::check())
89
<li class="nav-item active"><a href="/users/dashboard" class="nav-link">Dashboard</a></li>
910
<li class="nav-item"><a href="/users/account" class="nav-link">My Account</a></li>
@@ -12,6 +13,7 @@
1213
<li class="nav-item"><a href="/login" class="nav-link">Login</a></li>
1314
<li class="nav-item"><a href="/register" class="nav-link">Register</a></li>
1415
@endif
16+
--}}
1517
@endsection
1618

1719
@section('script')

resources/views/paste/edit.blade.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@section('navbar')
66
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
7+
{{--
78
@if (Auth::check())
89
<li class="nav-item"><a href="/users/dashboard" class="nav-link">Dashboard</a></li>
910
<li class="nav-item"><a href="/users/account" class="nav-link">My Account</a></li>
@@ -12,6 +13,7 @@
1213
<li class="nav-item"><a href="/login" class="nav-link">Login</a></li>
1314
<li class="nav-item"><a href="/register" class="nav-link">Register</a></li>
1415
@endif
16+
--}}
1517
@endsection
1618

1719
@section('script')

resources/views/paste/index.blade.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@section('navbar')
66
<li class="nav-item active"><a href="#" class="nav-link">Home</a></li>
7+
{{--
78
@if (Auth::check())
89
<li class="nav-item"><a href="/users/dashboard" class="nav-link">Dashboard</a></li>
910
<li class="nav-item"><a href="/users/account" class="nav-link">My Account</a></li>
@@ -12,6 +13,7 @@
1213
<li class="nav-item"><a href="/login" class="nav-link">Login</a></li>
1314
<li class="nav-item"><a href="/register" class="nav-link">Register</a></li>
1415
@endif
16+
--}}
1517
@endsection
1618

1719
@section('script')

resources/views/paste/password.blade.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@section('navbar')
66
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
7+
{{--
78
@if (Auth::check())
89
<li class="nav-item"><a href="/users/dashboard" class="nav-link">Dashboard</a></li>
910
<li class="nav-item"><a href="/users/account" class="nav-link">My Account</a></li>
@@ -12,6 +13,7 @@
1213
<li class="nav-item"><a href="/login" class="nav-link">Login</a></li>
1314
<li class="nav-item"><a href="/register" class="nav-link">Register</a></li>
1415
@endif
16+
--}}
1517
@endsection
1618

1719
@section('content')

resources/views/paste/view.blade.php

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
@section('navbar')
77
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
8+
{{--
89
@if (Auth::check())
910
<li class="nav-item"><a href="/users/dashboard" class="nav-link">Dashboard</a></li>
1011
<li class="nav-item"><a href="/users/account" class="nav-link">My Account</a></li>
@@ -13,6 +14,7 @@
1314
<li class="nav-item"><a href="/login" class="nav-link">Login</a></li>
1415
<li class="nav-item"><a href="/register" class="nav-link">Register</a></li>
1516
@endif
17+
--}}
1618
@endsection
1719

1820
@section('style')

0 commit comments

Comments
 (0)