Skip to content
Snippets Groups Projects
Commit 2ff1e861 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Removed deprecated attribute handling code. Replaced by auth proc filters......

Removed deprecated attribute handling code. Replaced by auth proc filters... Full documentation will be published tomorrow.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1106 44740490-163a-0410-bde0-09ae8108e29a
parent 50447315
No related branches found
No related tags found
No related merge requests found
<?php
/**
* AttributeFilter is a mapping between attribute names.
*
* @author Andreas Åkre Solberg, UNINETT AS. <andreas.solberg@uninett.no>
* @package simpleSAMLphp
* @version $Id$
*/
class SimpleSAML_XML_AttributeFilter {
private $attributes = null;
function __construct(SimpleSAML_Configuration $configuration, $attributes) {
$this->configuration = $configuration;
$this->attributes = $attributes;
}
/**
* Will process attribute napping, and altering based on metadata.
*/
public function process($idpmetadata, $spmetadata) {
if (isset($idpmetadata['attributemap'])) {
SimpleSAML_Logger::debug('Applying IdP specific attributemap: ' . $idpmetadata['attributemap']);
$this->namemap($idpmetadata['attributemap']);
}
if (isset($spmetadata['attributemap'])) {
SimpleSAML_Logger::debug('Applying SP specific attributemap: ' . $spmetadata['attributemap']);
$this->namemap($spmetadata['attributemap']);
}
if (isset($idpmetadata['attributealter'])) {
if (!is_array($idpmetadata['attributealter'])) {
SimpleSAML_Logger::debug('Applying IdP specific attribute alter: ' . $idpmetadata['attributealter']);
$this->alter($idpmetadata['attributealter'],$spmetadata['entityid'],$idpmetadata['entityid']);
} else {
foreach($idpmetadata['attributealter'] AS $alterfunc) {
SimpleSAML_Logger::debug('Applying IdP specific attribute alter: ' . $alterfunc);
$this->alter($alterfunc,$spmetadata['entityid'],$idpmetadata['entityid']);
}
}
}
if (isset($spmetadata['attributealter'])) {
if (!is_array($spmetadata['attributealter'])) {
SimpleSAML_Logger::debug('Applying SP specific attribute alter: ' . $spmetadata['attributealter']);
$this->alter($spmetadata['attributealter'],$spmetadata['entityid'],$idpmetadata['entityid']);
} else {
foreach($spmetadata['attributealter'] AS $alterfunc) {
SimpleSAML_Logger::debug('Applying SP specific attribute alter: ' . $alterfunc);
$this->alter($alterfunc,$spmetadata['entityid'],$idpmetadata['entityid']);
}
}
}
}
public function processFilter($idpmetadata, $spmetadata) {
/**
* Filter away attributes that are not allowed for this SP.
*/
if (isset($spmetadata['attributes'])) {
SimpleSAML_Logger::debug('Applying SP specific attribute filter: ' . join(',', $spmetadata['attributes']));
$this->filter($spmetadata['attributes']);
}
}
public function namemap($map) {
$mapfile = $this->configuration->getPathValue('attributenamemapdir') . $map . '.php';
if (!file_exists($mapfile)) throw new Exception('Could not find attributemap file: ' . $mapfile);
include($mapfile);
$newattributes = array();
foreach ($this->attributes AS $a => $value) {
if (isset($attributemap[$a])) {
$newattributes[$attributemap[$a]] = $value;
} else {
$newattributes[$a] = $value;
}
}
$this->attributes = $newattributes;
}
/**
* This function will call custom alter plugins.
*/
public function alter($rule, $spentityid = null, $idpentityid = null) {
$alterfile = $this->configuration->getBaseDir() . 'attributealter/' . $rule . '.php';
if (!file_exists($alterfile)) throw new Exception('Could not find attributealter file: ' . $alterfile);
include_once($alterfile);
$function = 'attributealter_' . $rule;
if (function_exists($function)) {
$function($this->attributes, $spentityid, $idpentityid);
} else {
throw new Exception('Could not find attribute alter fucntion: ' . $function . ' in file ' .$alterfile);
}
}
private function addValue($name, $value) {
if (array_key_exists($name, $this->attributes)) {
$this->attributes[$name][] = $value;
} else {
$this->attributes[$name] = array($value);
}
}
public function filter($allowedattributes) {
$newattributes = array();
foreach($this->attributes AS $key => $value) {
if (in_array($key, $allowedattributes)) {
$newattributes[$key] = $value;
}
}
$this->attributes = $newattributes;
}
public function getAttributes() {
return $this->attributes;
}
}
?>
\ No newline at end of file
...@@ -249,30 +249,22 @@ if($needAuth && !$isPassive) { ...@@ -249,30 +249,22 @@ if($needAuth && !$isPassive) {
* Attribute handling * Attribute handling
*/ */
$attributes = $session->getAttributes(); $attributes = $session->getAttributes();
$afilter = new SimpleSAML_XML_AttributeFilter($config, $attributes);
$afilter->process($idpmetadata, $spmetadata);
/** /*
* Make a log entry in the statistics for this SSO login. Need to be replaced by a auth proc filter that does the log entry....
*/
$tempattr = $afilter->getAttributes(); $realmattr = $config->getValue('statistics.realmattr', null);
$realmattr = $config->getValue('statistics.realmattr', null); $realmstr = 'NA';
$realmstr = 'NA'; if (!empty($realmattr)) {
if (!empty($realmattr)) { if (array_key_exists($realmattr, $tempattr) && is_array($tempattr[$realmattr]) ) {
if (array_key_exists($realmattr, $tempattr) && is_array($tempattr[$realmattr]) ) { $realmstr = $tempattr[$realmattr][0];
$realmstr = $tempattr[$realmattr][0]; } else {
} else { SimpleSAML_Logger::warning('Could not get realm attribute to log [' . $realmattr. ']');
SimpleSAML_Logger::warning('Could not get realm attribute to log [' . $realmattr. ']'); }
} }
} */
SimpleSAML_Logger::stats('saml20-idp-SSO ' . $spentityid . ' ' . $idpentityid . ' ' . $realmstr); SimpleSAML_Logger::stats('saml20-idp-SSO ' . $spentityid . ' ' . $idpentityid . ' NA');
$afilter->processFilter($idpmetadata, $spmetadata);
$filteredattributes = $afilter->getAttributes();
/* Authentication processing operations. */ /* Authentication processing operations. */
if (array_key_exists('AuthProcState', $requestcache)) { if (array_key_exists('AuthProcState', $requestcache)) {
/* Processed earlier, saved in requestcache. */ /* Processed earlier, saved in requestcache. */
...@@ -289,17 +281,17 @@ if($needAuth && !$isPassive) { ...@@ -289,17 +281,17 @@ if($needAuth && !$isPassive) {
$authProcState = array( $authProcState = array(
'core:saml20-idp:requestcache' => $requestcache, 'core:saml20-idp:requestcache' => $requestcache,
'ReturnURL' => SimpleSAML_Utilities::selfURLNoQuery(), 'ReturnURL' => SimpleSAML_Utilities::selfURLNoQuery(),
'Attributes' => $filteredattributes, 'Attributes' => $attributes,
'Destination' => $spmetadata, 'Destination' => $spmetadata,
'Source' => $idpmetadata, 'Source' => $idpmetadata,
); );
$pc->processState($authProcState); $pc->processState($authProcState);
$requestcache['AuthProcState'] = $authProcState; $requestcache['AuthProcState'] = $authProcState;
} }
$filteredattributes = $authProcState['Attributes']; $attributes = $authProcState['Attributes'];
...@@ -310,7 +302,7 @@ if($needAuth && !$isPassive) { ...@@ -310,7 +302,7 @@ if($needAuth && !$isPassive) {
// Generate an SAML 2.0 AuthNResponse message // Generate an SAML 2.0 AuthNResponse message
$ar = new SimpleSAML_XML_SAML20_AuthnResponse($config, $metadata); $ar = new SimpleSAML_XML_SAML20_AuthnResponse($config, $metadata);
$authnResponseXML = $ar->generate($idpentityid, $spentityid, $requestcache['RequestID'], null, $filteredattributes); $authnResponseXML = $ar->generate($idpentityid, $spentityid, $requestcache['RequestID'], null, $attributes);
// Sending the AuthNResponse using HTTP-Post SAML 2.0 binding // Sending the AuthNResponse using HTTP-Post SAML 2.0 binding
$httppost = new SimpleSAML_Bindings_SAML20_HTTPPost($config, $metadata); $httppost = new SimpleSAML_Bindings_SAML20_HTTPPost($config, $metadata);
......
...@@ -118,12 +118,12 @@ try { ...@@ -118,12 +118,12 @@ try {
* Attribute handling * Attribute handling
*/ */
$attributes = $authnResponse->getAttributes(); $attributes = $authnResponse->getAttributes();
$afilter = new SimpleSAML_XML_AttributeFilter($config, $attributes);
$afilter->process($idpmetadata, $spmetadata);
/** /**
* Make a log entry in the statistics for this SSO login. * Make a log entry in the statistics for this SSO login.
*/ *
* Needs to be replaced by auth proc
*
$tempattr = $authnResponse->getAttributes(); $tempattr = $authnResponse->getAttributes();
$realmattr = $config->getValue('statistics.realmattr', null); $realmattr = $config->getValue('statistics.realmattr', null);
$realmstr = 'NA'; $realmstr = 'NA';
...@@ -134,14 +134,8 @@ try { ...@@ -134,14 +134,8 @@ try {
SimpleSAML_Logger::warning('Could not get realm attribute to log [' . $realmattr. ']'); SimpleSAML_Logger::warning('Could not get realm attribute to log [' . $realmattr. ']');
} }
} }
SimpleSAML_Logger::stats('saml20-sp-SSO ' . $metadata->getMetaDataCurrentEntityID() . ' ' . $idpentityid . ' ' . $realmstr); */
SimpleSAML_Logger::stats('saml20-sp-SSO ' . $metadata->getMetaDataCurrentEntityID() . ' ' . $idpentityid . ' NA');
$afilter->processFilter($idpmetadata, $spmetadata);
$attributes = $afilter->getAttributes();
SimpleSAML_Logger::info('SAML2.0 - SP.AssertionConsumerService: Completed attribute handling');
/* Begin module attribute processing */ /* Begin module attribute processing */
......
...@@ -157,38 +157,28 @@ if (!$session->isAuthenticated($authority) ) { ...@@ -157,38 +157,28 @@ if (!$session->isAuthenticated($authority) ) {
$spentityid = $requestcache['Issuer']; $spentityid = $requestcache['Issuer'];
$spmetadata = $metadata->getMetaData($spentityid, 'shib13-sp-remote'); $spmetadata = $metadata->getMetaData($spentityid, 'shib13-sp-remote');
$sp_name = (isset($spmetadata['name']) ? $spmetadata['name'] : $spentityid); $sp_name = (isset($spmetadata['name']) ? $spmetadata['name'] : $spentityid);
/*
* Attribute handling
*/
$attributes = $session->getAttributes(); $attributes = $session->getAttributes();
$afilter = new SimpleSAML_XML_AttributeFilter($config, $attributes);
$afilter->process($idpmetadata, $spmetadata);
/**
* Make a log entry in the statistics for this SSO login.
*/
$tempattr = $afilter->getAttributes();
$realmattr = $config->getValue('statistics.realmattr', null);
$realmstr = 'NA';
if (!empty($realmattr)) {
if (array_key_exists($realmattr, $tempattr) && is_array($tempattr[$realmattr]) ) {
$realmstr = $tempattr[$realmattr][0];
} else {
SimpleSAML_Logger::warning('Could not get realm attribute to log [' . $realmattr. ']');
}
}
SimpleSAML_Logger::stats('shib13-idp-SSO ' . $spentityid . ' ' . $idpentityid . ' ' . $realmstr);
/** /**
* Filter away attributes that are not allowed for this SP. * Make a log entry in the statistics for this SSO login.
*/
$afilter->processFilter($idpmetadata, $spmetadata); Need to be replaced by a authproc
$filteredattributes = $afilter->getAttributes(); $tempattr = $afilter->getAttributes();
$realmattr = $config->getValue('statistics.realmattr', null);
$realmstr = 'NA';
if (!empty($realmattr)) {
if (array_key_exists($realmattr, $tempattr) && is_array($tempattr[$realmattr]) ) {
$realmstr = $tempattr[$realmattr][0];
} else {
SimpleSAML_Logger::warning('Could not get realm attribute to log [' . $realmattr. ']');
}
}
*/
SimpleSAML_Logger::stats('shib13-idp-SSO ' . $spentityid . ' ' . $idpentityid . ' NA');
/* Authentication processing operations. */ /* Authentication processing operations. */
if (array_key_exists('AuthProcState', $requestcache)) { if (array_key_exists('AuthProcState', $requestcache)) {
...@@ -206,7 +196,7 @@ if (!$session->isAuthenticated($authority) ) { ...@@ -206,7 +196,7 @@ if (!$session->isAuthenticated($authority) ) {
$authProcState = array( $authProcState = array(
'core:shib13-idp:requestcache' => $requestcache, 'core:shib13-idp:requestcache' => $requestcache,
'ReturnURL' => SimpleSAML_Utilities::selfURLNoQuery(), 'ReturnURL' => SimpleSAML_Utilities::selfURLNoQuery(),
'Attributes' => $filteredattributes, 'Attributes' => $attributes,
'Destination' => $spmetadata, 'Destination' => $spmetadata,
'Source' => $idpmetadata, 'Source' => $idpmetadata,
); );
...@@ -216,7 +206,7 @@ if (!$session->isAuthenticated($authority) ) { ...@@ -216,7 +206,7 @@ if (!$session->isAuthenticated($authority) ) {
$requestcache['AuthProcState'] = $authProcState; $requestcache['AuthProcState'] = $authProcState;
} }
$filteredattributes = $authProcState['Attributes']; $attributes = $authProcState['Attributes'];
...@@ -224,7 +214,7 @@ if (!$session->isAuthenticated($authority) ) { ...@@ -224,7 +214,7 @@ if (!$session->isAuthenticated($authority) ) {
// Generating a Shibboleth 1.3 Response. // Generating a Shibboleth 1.3 Response.
$ar = new SimpleSAML_XML_Shib13_AuthnResponse($config, $metadata); $ar = new SimpleSAML_XML_Shib13_AuthnResponse($config, $metadata);
$authnResponseXML = $ar->generate($idpentityid, $requestcache['Issuer'], $authnResponseXML = $ar->generate($idpentityid, $requestcache['Issuer'],
$requestcache['RequestID'], null, $filteredattributes); $requestcache['RequestID'], null, $attributes);
#echo $authnResponseXML; #echo $authnResponseXML;
......
...@@ -71,7 +71,9 @@ try { ...@@ -71,7 +71,9 @@ try {
/** /**
* Make a log entry in the statistics for this SSO login. * Make a log entry in the statistics for this SSO login.
*/
Need to be replaced by a auth proc
$tempattr = $authnResponse->getAttributes(); $tempattr = $authnResponse->getAttributes();
$realmattr = $config->getValue('statistics.realmattr', null); $realmattr = $config->getValue('statistics.realmattr', null);
$realmstr = 'NA'; $realmstr = 'NA';
...@@ -82,7 +84,8 @@ try { ...@@ -82,7 +84,8 @@ try {
SimpleSAML_Logger::warning('Could not get realm attribute to log [' . $realmattr. ']'); SimpleSAML_Logger::warning('Could not get realm attribute to log [' . $realmattr. ']');
} }
} }
SimpleSAML_Logger::stats('shib13-sp-SSO ' . $metadata->getMetaDataCurrentEntityID('shib13-sp-hosted') . ' ' . $idpmetadata['entityid'] . ' ' . $realmstr); */
SimpleSAML_Logger::stats('shib13-sp-SSO ' . $metadata->getMetaDataCurrentEntityID('shib13-sp-hosted') . ' ' . $idpmetadata['entityid'] . ' NA');
$relayState = $authnResponse->getRelayState(); $relayState = $authnResponse->getRelayState();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment