Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Refactor the SP metadata loading logic.
Browse files Browse the repository at this point in the history
The SP metadata get loaded once at the start from all sources to
index the entities ids and where the come from.

Upon every request from an SP, the metadata of that SP gets reloaded
from the last known source: if it's not there anymore the server
tries to look in all known sources again.

Protip! Using:
```
metadata:
    local:
        - conf/*.xml
```

Allows to drop config files to the directory at runtime and have their
configuration picked up without restarting the server.

Other goodies:
* Invalid SP metadata are logged and discarded, but no longer prevent
  the rest of metadata from loading. (Fix #210)
* Duplicate entityIds are discarded with precedence given to local
  sources (local > db > remote) (Fix #205).
* Display the source of the SP metadata in the UI
  • Loading branch information
bfabio committed Jan 14, 2021
1 parent 8e9da3e commit f3fd0b1
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 84 deletions.
9 changes: 6 additions & 3 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ <h3 class="border-bottom mt-2 mb-2 border-italia">Service Provider configurati</
<tbody>
{% for item in sp_list %}
<tr>
<td >
{{ item['entityID'] }}
<td>
{{ item['entityID'] }}
<small class="float-right">
<mark>loaded from {{ item['location'] }}</mark>
</small>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% endblock %}
15 changes: 8 additions & 7 deletions testenv/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _handle_http_post(self, action):

def _get_certificates_by_issuer(self, issuer):
try:
return self._registry.get(issuer).certs()
return self._registry.load(issuer).certs()
except KeyError:
self._raise_error(
'entity ID {} non registrato, impossibile ricavare'
Expand Down Expand Up @@ -357,7 +357,7 @@ def users(self):
'primary_attributes': spid_main_fields,
'secondary_attributes': spid_secondary_fields,
'users': self.user_manager.all(),
'sp_list': self._registry.all(),
'sp_list': self._registry.load_all().keys(),
'can_add_user': can_add_user
}
)
Expand Down Expand Up @@ -393,8 +393,9 @@ def index(self):
**{
'sp_list': [
{
"entityID": sp
} for sp in self._registry.all()
"entityID": entity_id,
"location": sp_metadata.location,
} for (entity_id, sp_metadata) in self._registry.load_all().items()
],
}
)
Expand All @@ -405,7 +406,7 @@ def get_destination(self, req, sp_id):
acs_index = getattr(req, 'assertion_consumer_service_index', None)
protocol_binding = getattr(req, 'protocol_binding', None)
if acs_index is not None:
acss = self._registry.get(
acss = self._registry.load(
sp_id).assertion_consumer_service(index=acs_index)
if acss:
destination = acss[0].get('Location')
Expand Down Expand Up @@ -590,7 +591,7 @@ def login(self):
atcs_idx
)
)
sp_metadata = self._registry.get(sp_id)
sp_metadata = self._registry.load(sp_id)
required = []
optional = []
if atcs_idx and sp_metadata:
Expand Down Expand Up @@ -791,7 +792,7 @@ def continue_response(self):
def _sp_single_logout_service(self, issuer_name):
_slo = None
try:
_slo = self._registry.get(issuer_name).single_logout_services[0]
_slo = self._registry.load(issuer_name).single_logout_services[0]
except Exception:
pass
return _slo
Expand Down
Loading

0 comments on commit f3fd0b1

Please sign in to comment.