http://git-wip-us.apache.org/repos/asf/mesos/blob/da47646e/src/master/weights_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/weights_handler.cpp b/src/master/weights_handler.cpp
index d8047f2..453bf37 100644
--- a/src/master/weights_handler.cpp
+++ b/src/master/weights_handler.cpp
@@ -36,6 +36,8 @@ namespace http = process::http;
 
 using google::protobuf::RepeatedPtrField;
 
+using mesos::authorization::createSubject;
+
 using std::list;
 using std::string;
 using std::vector;
@@ -49,13 +51,15 @@ using http::OK;
 using process::Future;
 using process::Owned;
 
+using process::http::authentication::Principal;
+
 namespace mesos {
 namespace internal {
 namespace master {
 
 Future<http::Response> Master::WeightsHandler::get(
     const http::Request& request,
-    const Option<string>& principal) const
+    const Option<Principal>& principal) const
 {
   VLOG(1) << "Handling get weights request";
 
@@ -79,7 +83,7 @@ Future<http::Response> Master::WeightsHandler::get(
 
 Future<http::Response> Master::WeightsHandler::get(
     const mesos::master::Call& call,
-    const Option<string>& principal,
+    const Option<Principal>& principal,
     ContentType contentType) const
 {
   CHECK_EQ(mesos::master::Call::GET_WEIGHTS, call.type());
@@ -102,7 +106,7 @@ Future<http::Response> Master::WeightsHandler::get(
 
 
 Future<vector<WeightInfo>> Master::WeightsHandler::_getWeights(
-    const Option<string>& principal) const
+    const Option<Principal>& principal) const
 {
   vector<WeightInfo> weightInfos;
   weightInfos.reserve(master->weights.size());
@@ -155,7 +159,7 @@ Future<vector<WeightInfo>> 
Master::WeightsHandler::_filterWeights(
 
 Future<http::Response> Master::WeightsHandler::update(
     const http::Request& request,
-    const Option<string>& principal) const
+    const Option<Principal>& principal) const
 {
   VLOG(1) << "Updating weights from request: '" << request.body << "'";
 
@@ -185,7 +189,7 @@ Future<http::Response> Master::WeightsHandler::update(
 
 Future<http::Response> Master::WeightsHandler::update(
     const mesos::master::Call& call,
-    const Option<string>& principal,
+    const Option<Principal>& principal,
     ContentType /*contentType*/) const
 {
   CHECK_EQ(mesos::master::Call::UPDATE_WEIGHTS, call.type());
@@ -196,7 +200,7 @@ Future<http::Response> Master::WeightsHandler::update(
 
 
 Future<http::Response> Master::WeightsHandler::_updateWeights(
-    const Option<string>& principal,
+    const Option<Principal>& principal,
     const RepeatedPtrField<WeightInfo>& weightInfos) const {
   vector<WeightInfo> validatedWeightInfos;
   vector<string> roles;
@@ -313,7 +317,7 @@ void Master::WeightsHandler::rescindOffers(
 
 
 Future<bool> Master::WeightsHandler::authorizeUpdateWeights(
-    const Option<string>& principal,
+    const Option<Principal>& principal,
     const vector<string>& roles) const
 {
   if (master->authorizer.isNone()) {
@@ -321,14 +325,15 @@ Future<bool> 
Master::WeightsHandler::authorizeUpdateWeights(
   }
 
   LOG(INFO) << "Authorizing principal '"
-            << (principal.isSome() ? principal.get() : "ANY")
+            << (principal.isSome() ? stringify(principal.get()) : "ANY")
             << "' to update weights for roles '" << stringify(roles) << "'";
 
   authorization::Request request;
   request.set_action(authorization::UPDATE_WEIGHT);
 
-  if (principal.isSome()) {
-    request.mutable_subject()->set_value(principal.get());
+  Option<authorization::Subject> subject = createSubject(principal);
+  if (subject.isSome()) {
+    request.mutable_subject()->CopyFrom(subject.get());
   }
 
   list<Future<bool>> authorizations;
@@ -356,7 +361,7 @@ Future<bool> Master::WeightsHandler::authorizeUpdateWeights(
 
 
 Future<bool> Master::WeightsHandler::authorizeGetWeight(
-    const Option<string>& principal,
+    const Option<Principal>& principal,
     const WeightInfo& weight) const
 {
   if (master->authorizer.isNone()) {
@@ -364,14 +369,15 @@ Future<bool> Master::WeightsHandler::authorizeGetWeight(
   }
 
   LOG(INFO) << "Authorizing principal '"
-            << (principal.isSome() ? principal.get() : "ANY")
+            << (principal.isSome() ? stringify(principal.get()) : "ANY")
             << "' to get weight for role '" << weight.role() << "'";
 
   authorization::Request request;
   request.set_action(authorization::VIEW_ROLE);
 
-  if (principal.isSome()) {
-    request.mutable_subject()->set_value(principal.get());
+  Option<authorization::Subject> subject = createSubject(principal);
+  if (subject.isSome()) {
+    request.mutable_subject()->CopyFrom(subject.get());
   }
 
   request.mutable_object()->mutable_weight_info()->CopyFrom(weight);

Reply via email to