1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::ExternalLocalInfo;
use ockam_core::access_control::AccessControl;
use ockam_core::{allow, LocalMessage, Result};
use ockam_core::{
async_trait,
compat::{boxed::Box, vec::Vec},
TransportType,
};
#[derive(Debug)]
pub struct LocalOriginOnly;
#[async_trait]
impl AccessControl for LocalOriginOnly {
async fn is_authorized(&self, local_msg: &LocalMessage) -> Result<bool> {
Ok(ExternalLocalInfo::find_info(local_msg).is_err())
}
}
#[derive(Debug)]
pub struct AllowedTransport {
allowed_transport: Vec<TransportType>,
}
impl AllowedTransport {
pub fn multiple(allowed_transport: Vec<TransportType>) -> Self {
Self { allowed_transport }
}
pub fn single(allowed_transport: TransportType) -> Self {
Self {
allowed_transport: vec![allowed_transport],
}
}
}
#[async_trait]
impl AccessControl for AllowedTransport {
async fn is_authorized(&self, local_msg: &LocalMessage) -> Result<bool> {
for transport in ExternalLocalInfo::find_all(local_msg)?
.into_iter()
.map(|x| x.transport_type())
{
if !self.allowed_transport.contains(&transport) {
return Ok(false);
}
}
allow()
}
}