Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cas support #233

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ module.exports.initialize = function (config) {
}
return config.get('application').favicon.trim()
},
get topMenus () {
return []
},
get accountMenus () {
return []
},

isAnonymous: function () {
return !req.user
Expand Down
6 changes: 6 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ module.exports = (function () {
passwordHash: '',
email: ''
},
cas: {
enabled: false,
ssoBaseURL: '',
serverBaseURL: ''
},
local: {
enabled: false,
accounts: [{
Expand Down Expand Up @@ -167,6 +172,7 @@ module.exports = (function () {
!config.authentication.github.enabled &&
!config.authentication.ldap.enabled &&
!config.authentication.alone.enabled &&
!config.authentication.cas.enabled &&
!config.authentication.local.enabled
) {
error = 'No authentication method provided.'
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@
"morgan": "^1.5.0",
"node-syntaxhighlighter": "*",
"passport": "^0.2.0",
"passport-cas": "^0.1.1",
"passport-github": "^0.1.5",
"passport-google-oauth": "^0.1.5",
"passport-local": "^1.0.0",
"pug": "^2.0.0-beta11",
"semver": "^5.3.0",
"serve-favicon": "^2.1.7",
"transliteration": "^0.2.1",
"pug": "^2.0.0-beta11"
"ssl-certs": "^1.0.0",
"transliteration": "^0.2.1"
},
"devDependencies": {
"chai": "*",
Expand Down
37 changes: 27 additions & 10 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ a.logout i {
padding-right: 0;
}

.navbar a[href^="https://"],
.navbar a[href^="http://"] {
background: none;
padding-right: 0;
}

.navbar li{
margin-bottom: 0;
}

p.user {
color: white;
padding: 8px 0 0;
Expand Down Expand Up @@ -247,8 +257,8 @@ hr {

/* Overrides Bootstrap */

.navbar-right {
float: right;
.navbar-brand{
display: none;
}

.navbar-form {
Expand All @@ -258,19 +268,18 @@ hr {

.navbar-form.search {
display: none;
margin-left: 15px;
margin-right: 15px;
}

.navbar-header {
width: 100%;
}

.navbar-brand {
overflow: hidden;
max-width: 60%;
.navbar-inverse {
background-color: #24292e;
}

.navbar-inverse {
background-color: rgba(0,0,0);
.navbar-inverse .navbar-nav>li>a{
color: rgba(255, 255, 255, 0.75);
font-weight: bold;
}

.alert {
Expand Down Expand Up @@ -539,6 +548,10 @@ input#pageTitle {
margin-bottom: 20px;
}

.search-xs input{
border: 0;
}

.with-sidebar {
background-color: rgba(255,255,255,0.5);
padding: 10px;
Expand Down Expand Up @@ -567,6 +580,10 @@ li {
margin-bottom: 5px;
}

.navbar-header li {
margin-bottom: 0px;
}

.jumbotron p.discrete {
color: gray;
font-size: 90%
Expand Down
42 changes: 42 additions & 0 deletions routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,44 @@ if (auth.ldap.enabled) {
))
}

if (auth.cas.enabled){
require('ssl-certs');
router.get('/cas_login', function(req, res, next) {
passport.authenticate('cas', function (err, user, info) {
if (err) {
console.error(err);
return next(err);
}
if (!user) {
return next(new Error('cas login failed'));
}
req.logIn(user, function (err) {
if (err) {
return next(err);
}
return res.redirect(proxyPath + '/auth/done');
});
})(req, res, next);
});

passport.use(new(require('passport-cas').Strategy)({
version: 'CAS3.0',
serviceURL: '/cas_login',
ssoBaseURL: auth.cas.ssoBaseURL,
serverBaseURL: auth.cas.serverBaseURL,
validateURL: '/serviceValidate' // for CAS 2.0
}, function(profile, done) {
console.log('cas login', profile.user);
usedAuthentication('cas');
return done(null, {
displayName: profile.attributes && (profile.attributes.displayName || profile.user),
email: profile.attributes && (profile.attributes.email || profile.user+'@saas-plat.com')
});
})
);

}

if (auth.alone.enabled) {
passport.use(new passportLocal.Strategy(

Expand Down Expand Up @@ -234,6 +272,10 @@ function _getLogin (req, res) {

res.locals.errors = req.flash()

if (auth.cas.enabled){
return res.redirect('cas_login');
}

res.render('login', {
title: app.locals.config.get('application').title,
auth: auth
Expand Down
75 changes: 49 additions & 26 deletions views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,69 @@ include mixins/links
body
-var term_ph = (typeof term == "undefined" ? "" : term)
.navbar.navbar-inverse.navbar-fixed-top
.container-fluid
.container-fluid
.navbar-header
+anchor("/", appBrand).navbar-brand
if canSearch()
form(action=`${proxyPath}/search`).navbar-form.search.navbar-left
.input-group.input-group-sm.search
input.form-control(type="text", value=term_ph, data-i-search-input="true",name="term",placeholder="Search the wiki")
span.input-group-btn
button.btn.btn-primary(type="submit") Search
.navbar-right
if isAnonymous()
p.user You're not 
+anchor('/login?destination', 'logged in')#login(title='Access login page')
else
p.user
if hasGravatar()
img(src=gravatar().url(user.email, {s:24}))
b  #{user.displayName} 
+anchor('/logout')(title='Become anonymous')
i.icon.ion-power
button(type="button",data-toggle="collapse" data-target="#navbar-collapse-1" aria-expanded="false").navbar-toggle.collapsed
span.sr-only Toggle navigation
span.icon-bar
span.icon-bar
span.icon-bar
.collapse.navbar-collapse(id="navbar-collapse-1")
if topMenus.length>0
ul.nav.navbar-nav
each m in topMenus
li
+anchor(m.url, m.text)
if canSearch()
form(action=`${proxyPath}/search`).navbar-form.search.navbar-left
.input-group.input-group-sm.search
input.form-control(type="text", value=term_ph, data-i-search-input="true",name="term",placeholder="Search the wiki")
span.input-group-btn
button.btn.btn-primary(type="submit") Search
ul.nav.navbar-nav.navbar-right
li.dropdown
if isAnonymous()
+anchor('/login?destination', 'logged in')#login(title='Access login page')
else
a(href="#",class="dropdown-toggle user",data-toggle="dropdown",role="button",aria-haspopup="true",aria-expanded="false")
if hasGravatar()
img(src=gravatar().url(user.email, {s:24}))
span #{user.displayName}
span.caret
ul.dropdown-menu
each am in accountMenus
li
+anchor(am.url, am.text)
li
a(href="/logout",title='Become anonymous')
i.icon.ion-power
span Logout


.tools
block tools

.container
if canSearch()
form(action=`${proxyPath}/search`).visible-xs-block.search-xs
input.form-control(type="text", value=term_ph, data-i-search-input="true",name="term",placeholder="Search the wiki")

.container

.row
#main.hide-tools.col-md-9
block content

if hasSidebar()
.col-md-2.with-sidebar
.col-md-3.with-sidebar
.content !{_sidebar}
else
.col-md-2

#main.hide-tools.col-md-8
block content
.col-md-3

if hasFooter()
.row
.col-md-2
.col-md-8.with-footer
.col-md-3
.col-md-9.with-footer
.content !{_footer}

script(src=proxyPath + "/vendor/jquery.min.js")
Expand Down
2 changes: 1 addition & 1 deletion views/search.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ block content
+warning()

if canSearch()
form(action=`${proxyPath}/search`).search-form
form(action=`${proxyPath}/search`).search-form.hidden-xs
.input-group.input-group-sm
input.form-control(type="text", value=term_ph, data-i-search-input="true", name="term", placeholder="Search the wiki")
span.input-group-btn
Expand Down