Skip to content

Commit

Permalink
Merge pull request #9 from LizardM4/master
Browse files Browse the repository at this point in the history
Several bugfixes to work with the newest Kanboard
  • Loading branch information
trajche authored Mar 19, 2018
2 parents e4e45a0 + d67e0cd commit b08d757
Show file tree
Hide file tree
Showing 54 changed files with 39 additions and 9,790 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Thirdparty/php-saml"]
path = Thirdparty/php-saml
url = https://github.com/onelogin/php-saml.git
30 changes: 9 additions & 21 deletions Auth/SamlAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,33 @@ public function authenticate(){


//Get attributes for SAML from configModel
$atrb_email = $this->configModel->get('samlauth_name_attribute');
$atrb_email = $this->configModel->get('samlauth_email_attribute');
$atrb_username = $this->configModel->get('samlauth_username_attribute');
$atrb_firstname = $this->configModel->get('samlauth_firstname_attribute');
$atrb_lastname = $this->configModel->get('samlauth_lastname_attribute');
$atrb_fullname = $this->configModel->get('samlauth_fullname_attribute');
$atrb_replacer = $this->configModel->get('samlauth_replace_attribute');

//Get user information via specified attributes
$email = $samlResponse->getAttributes()["$atrb_email"]['0'];
$username = $samlResponse->getAttributes()["$atrb_username"]['0'];
$firstname = $samlResponse->getAttributes()["$atrb_firstname"]['0'];
$lastname = $samlResponse->getAttributes()["$atrb_lastname"]['0'];
$fullname = $samlResponse->getAttributes()["$atrb_fullname"]['0'];

//Replace text for a clean username
if(!empty($atrb_replacer)) {
$username = str_replace($atrb_replacer,"", $username);
}
//$username = str_replace("companyname\\","", $samlResponse->getNameId());


//Check if firstname & lastname is set
if(!empty($firstname)) {
$name .= $firstname;
if(!empty($lastname)) {
$name .= ' '.$lastname;
}
//Otherwise check if lastname
} elseif (!empty($lastname)){
$name = $lastname;
//Otherwise pass empty
} else {
$name = '';

// If the full name is missing, fall back on the username; at least
// we display something meaningful
if (empty($fullname)) {
$fullname = $username;
}


//Check if username and email are set
if (!empty($username) && !empty($email)) {

//Create user by having email as username
$this->userInfo = new SamlUserProvider($username, $email, $name);
$this->userInfo = new SamlUserProvider($username, $email, $fullname);
return true;

} else {
Expand Down
12 changes: 6 additions & 6 deletions Auth/SamlSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function getSettings() {
$sp['techname'] = $this->configModel->get('samlauth_techcontact_name');
$sp['techemail'] = $this->configModel->get('samlauth_techcontact_email');

$sp['privatecert'] = file_get_contents('/var/kanboard-certs/sp-private.crt');
$sp['publiccert'] = file_get_contents('/var/kanboard-certs/sp-public.crt');
$sp['privatekey'] = $this->configModel->get('samlauth_sp_key');
$sp['certificate'] = $this->configModel->get('samlauth_sp_cert');

$login = htmlspecialchars($sp['signon'], ENT_XML1);
$logout = htmlspecialchars($sp['signout'], ENT_XML1);
Expand All @@ -33,7 +33,7 @@ public function getSettings() {
$idp['signon'] = $this->configModel->get('samlauth_idp_signon');
$idp['signout'] = $this->configModel->get('samlauth_idp_signout');

$idp['publiccert'] = file_get_contents('/var/kanboard-certs/idp-public.crt');
$idp['certificate'] = $this->configModel->get('samlauth_idp_cert');


$settingsInfo = array(
Expand Down Expand Up @@ -65,8 +65,8 @@ public function getSettings() {
),
//'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:entity',
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
'x509cert' => $sp['publiccert'],
'privateKey' => $sp['privatecert'],
'x509cert' => $sp['certificate'],
'privateKey' => $sp['privatekey'],
),
'idp' => array(
'entityId' => $idp['entityid'],
Expand All @@ -77,7 +77,7 @@ public function getSettings() {
'singleLogoutService' => array(
'url' => $idp['signout'],
),
'x509cert' => $idp['publiccert'],
'x509cert' => $idp['certificate'],
),
);
return $settingsInfo;
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Plugin for [Kanboard](https://github.com/fguillot/kanboard) :ok_hand:
This is a plugin that allows Kanboard to be used as a SP (Service Provider) and authenticate against an IDP (Identity Provider) via the SAML2 protocol.

## Instructions
Download the plugin and upload it to the /plugins directory of your Kanboard install. Then login with your admin account and fill out the required fields under **Settings****Integrations**.
Download the plugin and upload it to the /plugins directory of your Kanboard install. Then login with your admin account and fill out the required fields under **Settings****Integrations**. Click **Save settings** to store the data, and then **Generate metadata**. The resulting XML file can be used to set up your identity provider.

## Contributors
* [Trajche](http://tj.mk) Kralev
* Pietro Saccardi
30 changes: 18 additions & 12 deletions Template/config/integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,49 @@
<div class="listing">

<h3>Service Provider Configuration (Kanboard Instance)</h3>

<?= $this->form->label(t('SP Entity ID'), 'samlauth_sp_entity_id') ?>
<?= $this->form->text('samlauth_sp_entity_id', $values, array(), array('required')) ?>

<?= $this->form->label(t('Single Signon Service'), 'samlauth_sp_signon') ?>
<?= $this->form->text('samlauth_sp_signon', $values, array('placeholder="http://your-kanboard-url.com"')) ?>
<?= $this->form->text('samlauth_sp_signon', $values, array(''), array('placeholder="http://your-kanboard-url.com"')) ?>

<?= $this->form->label(t('Single Logout Service'), 'samlauth_sp_signout') ?>
<?= $this->form->text('samlauth_sp_signout', $values, array('placeholder="http://your-kanboard-url.com/logout"')) ?>
<?= $this->form->text('samlauth_sp_signout', $values, array(''), array('placeholder="http://your-kanboard-url.com/logout"')) ?>

<?= $this->form->label(t('Technical Contact (Name)'), 'samlauth_techcontact_name') ?>
<?= $this->form->text('samlauth_techcontact_name', $values, array(''), array('required', 'placeholder="Trajche Kralev"')) ?>

<?= $this->form->label(t('Technical Contact (Email)'), 'samlauth_techcontact_email') ?>
<?= $this->form->text('samlauth_techcontact_email', $values, array(''), array('required', 'placeholder="trajche@kralev.eu"')) ?>

<?= $this->form->label(t('SP Certificate'), 'samlauth_sp_cert') ?>
<?= $this->form->textarea('samlauth_sp_cert', $values, array(), array('placeholder=""')) ?>

<?= $this->form->label(t('SP Certificate Private Key'), 'samlauth_sp_key') ?>
<?= $this->form->textarea('samlauth_sp_key', $values, array(), array('placeholder=""')) ?>

<hr style="margin:20px 0;">

<h3>Identity Provider Configuration</h3>
<?= $this->form->label(t('IDP Entity ID'), 'samlauth_idp_entity_id') ?>
<?= $this->form->text('samlauth_idp_entity_id', $values, array(), array('required')) ?>
<?= $this->form->text('samlauth_idp_entity_id', $values, array(''), array('required')) ?>

<?= $this->form->label(t('Single Signon Service'), 'samlauth_idp_signon') ?>
<?= $this->form->text('samlauth_idp_signon', $values, array('placeholder="http://youridpurl.com/uas/SingleSignOnService"')) ?>
<?= $this->form->text('samlauth_idp_signon', $values, array(''), array('placeholder="http://youridpurl.com/uas/SingleSignOnService"')) ?>

<?= $this->form->label(t('Single Logout Service'), 'samlauth_idp_signout') ?>
<?= $this->form->text('samlauth_idp_signout', $values, array('placeholder="http://youridpurl.com/uas/SingleSignOutService"')) ?>
<?= $this->form->text('samlauth_idp_signout', $values, array(''), array('placeholder="http://youridpurl.com/uas/SingleSignOutService"')) ?>

<?= $this->form->label(t('IDP Certificate'), 'samlauth_idp_cert') ?>
<?= $this->form->textarea('samlauth_idp_cert', $values, array(), array('placeholder=""')) ?>

<hr style="margin:20px 0;">

<h3>Identity Provider Attribute Mapping</h3>
<?= $this->form->label(t('First-name Attribute'), 'samlauth_firstname_attribute') ?>
<?= $this->form->text('samlauth_firstname_attribute', $values, array(), array('placeholder="fname"')) ?>
<p class="form-help"><?= t('Enter the attribute that is returned by your IDP. Default is "fname"') ?></p>

<?= $this->form->label(t('Last-name Attribute'), 'samlauth_lastname_attribute') ?>
<?= $this->form->text('samlauth_lastname_attribute', $values, array(), array('placeholder="lname"')) ?>
<p class="form-help"><?= t('Enter the attribute that is returned by your IDP. Default is "lname"') ?></p>
<?= $this->form->label(t('Full name Attribute'), 'samlauth_fullname_attribute') ?>
<?= $this->form->text('samlauth_fullname_attribute', $values, array(), array('placeholder="fullname"')) ?>
<p class="form-help"><?= t('Enter the attribute that is returned by your IDP. Default is "fullname"') ?></p>

<?= $this->form->label(t('Username Attribute'), 'samlauth_username_attribute') ?>
<?= $this->form->text('samlauth_username_attribute', $values, array(), array('placeholder="username"')) ?>
Expand Down Expand Up @@ -69,6 +72,9 @@
<?= $this->form->label(t('Login Button Text'), 'samlauth_login_button') ?>
<?= $this->form->text('samlauth_login_button', $values, array(''), array('required', 'placeholder="Login with SAML"')) ?>
<br><br>
<p class="form-help"><?= t('Submit this form to save the settings before generating the metadata!') ?></p>
<br>
<input type="submit" value="<?= t('Save settings') ?>" class='btn'>
<?= $this->url->button('fa-certificate', t('Generate Metadata'), 'SamlAuthController', 'metadata', array('plugin'=>'SamlAuth'), false, '', t('SAML SP Metadata')) ?>

<div style="margin:20px 0;"></div>
Expand Down
1 change: 1 addition & 0 deletions Thirdparty/php-saml
Submodule php-saml added at 9416fa
7 changes: 0 additions & 7 deletions Thirdparty/php-saml/.coveralls.yml

This file was deleted.

14 changes: 0 additions & 14 deletions Thirdparty/php-saml/.gitignore

This file was deleted.

33 changes: 0 additions & 33 deletions Thirdparty/php-saml/.travis.yml

This file was deleted.

113 changes: 0 additions & 113 deletions Thirdparty/php-saml/CHANGELOG

This file was deleted.

22 changes: 0 additions & 22 deletions Thirdparty/php-saml/_toolkit_loader.php

This file was deleted.

Loading

0 comments on commit b08d757

Please sign in to comment.