~thomas-voss/location-service/add_controller_and_service_configuration

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/service/skeleton.cpp

  • Committer: thomas-voss
  • Date: 2014-06-24 07:56:00 UTC
  • Revision ID: thomas.voss@canonical.com-20140624075600-x7wkfmyqulzqwr2h
Factor out resolution of client credentials and object path creation into interfaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
}
37
37
}
38
38
 
 
39
culs::Skeleton::DBusDaemonCredentialsResolver::DBusDaemonCredentialsResolver(const dbus::Bus::Ptr& bus)
 
40
    : daemon(bus)
 
41
{
 
42
}
 
43
 
 
44
culs::Credentials
 
45
culs::Skeleton::DBusDaemonCredentialsResolver::resolve_credentials_for_incoming_message(const dbus::Message::Ptr& msg)
 
46
{
 
47
    return culs::Credentials
 
48
    {
 
49
        daemon.get_connection_unix_process_id(msg->sender()),
 
50
        daemon.get_connection_unix_user(msg->sender())
 
51
    };
 
52
}
 
53
 
 
54
core::dbus::types::ObjectPath culs::Skeleton::ObjectPathGenerator::object_path_for_caller_credentials(const culs::Credentials&)
 
55
{
 
56
    static std::uint32_t index{0};
 
57
    std::stringstream ss; ss << "/sessions/" << index;
 
58
 
 
59
    return core::dbus::types::ObjectPath{ss.str()};
 
60
}
 
61
 
 
62
 
39
63
culs::Skeleton::Skeleton(const culs::Skeleton::Configuration& configuration)
40
64
    : dbus::Skeleton<culs::Interface>(configuration.incoming),
41
65
      configuration(configuration),
42
 
      daemon(configuration.outgoing),
43
66
      object(access_service()->add_object_for_path(culs::Interface::path())),
44
67
      properties
45
68
      {
72
95
        Criteria criteria;
73
96
        in->reader() >> criteria;
74
97
 
75
 
        Credentials credentials
 
98
        auto credentials =
 
99
            configuration.credentials_resolver->resolve_credentials_for_incoming_message(in);
 
100
 
 
101
        auto result =
 
102
            configuration.permission_manager->check_permission_for_credentials(criteria, credentials);
 
103
 
 
104
        if (PermissionManager::Result::rejected == result) throw std::runtime_error
76
105
        {
77
 
            static_cast<pid_t>(daemon.get_connection_unix_process_id(sender)),
78
 
            static_cast<uid_t>(daemon.get_connection_unix_user(sender))
 
106
            "Client lacks permissions to access the service with the given criteria"
79
107
        };
80
108
 
81
 
        auto result = configuration.permission_manager->check_permission_for_credentials(
82
 
                    criteria,
83
 
                    credentials);
84
 
 
85
 
        if (PermissionManager::Result::rejected == result)
86
 
            throw std::runtime_error("Client lacks permissions to access the service with the given criteria");
87
 
 
88
 
        // TODO(tvoss): Factor session path creation out into its own interface.
89
 
        std::stringstream ss; ss << "/sessions/" << credentials.pid;
90
 
        dbus::types::ObjectPath path{ss.str()};
91
 
 
92
 
        auto stub = dbus::Service::use_service(configuration.outgoing, sender);
 
109
        auto path =
 
110
            configuration.object_path_generator->object_path_for_caller_credentials(credentials);
 
111
 
 
112
        auto stub =
 
113
            dbus::Service::use_service(configuration.outgoing, sender);
93
114
 
94
115
        culss::Skeleton::Configuration config
95
116
        {
105
126
            }
106
127
        };
107
128
 
108
 
        auto session = culss::Interface::Ptr{new culss::Skeleton{config}};
 
129
        culss::Interface::Ptr session
 
130
        {
 
131
            new culss::Skeleton{config}
 
132
        };
109
133
 
110
134
        if (not add_to_session_store_for_path(path, session))
111
135
        {