veyron/services/wsprd: Added label support to wsprd.

Change-Id: I091138fabf44f0e41c3b647778d049c3e52cbd94
diff --git a/services/wsprd/ipc/server/dispatcher.go b/services/wsprd/ipc/server/dispatcher.go
index e850cd5..ca83e40 100644
--- a/services/wsprd/ipc/server/dispatcher.go
+++ b/services/wsprd/ipc/server/dispatcher.go
@@ -21,7 +21,7 @@
 }
 
 type invokerFactory interface {
-	createInvoker(handle int64, signature signature.JSONServiceSignature) (ipc.Invoker, error)
+	createInvoker(handle int64, signature signature.JSONServiceSignature, label security.Label) (ipc.Invoker, error)
 }
 
 type authFactory interface {
@@ -31,6 +31,7 @@
 type lookupReply struct {
 	Handle        int64
 	HasAuthorizer bool
+	Label         security.Label
 	Signature     signature.JSONServiceSignature
 	Err           *verror.Standard
 }
@@ -101,7 +102,7 @@
 		return nil, nil, verror.NoExistf("ipc: dispatcher for %s not found", suffix)
 	}
 
-	invoker, err := d.invokerFactory.createInvoker(request.Handle, request.Signature)
+	invoker, err := d.invokerFactory.createInvoker(request.Handle, request.Signature, request.Label)
 	if err != nil {
 		return nil, nil, err
 	}
diff --git a/services/wsprd/ipc/server/dispatcher_test.go b/services/wsprd/ipc/server/dispatcher_test.go
index c3a20be..20b3b41 100644
--- a/services/wsprd/ipc/server/dispatcher_test.go
+++ b/services/wsprd/ipc/server/dispatcher_test.go
@@ -1,6 +1,7 @@
 package server
 
 import (
+	"fmt"
 	"reflect"
 	"testing"
 	"veyron.io/veyron/veyron/services/wsprd/lib"
@@ -24,10 +25,11 @@
 type mockInvoker struct {
 	handle int64
 	sig    signature.JSONServiceSignature
+	label  security.Label
 }
 
-func (mockInvoker) Prepare(string, int) ([]interface{}, security.Label, error) {
-	return nil, 0, nil
+func (m mockInvoker) Prepare(string, int) ([]interface{}, security.Label, error) {
+	return nil, m.label, nil
 }
 
 func (mockInvoker) Invoke(string, ipc.ServerCall, []interface{}) ([]interface{}, error) {
@@ -36,8 +38,8 @@
 
 type mockInvokerFactory struct{}
 
-func (mockInvokerFactory) createInvoker(handle int64, sig signature.JSONServiceSignature) (ipc.Invoker, error) {
-	return &mockInvoker{handle: handle, sig: sig}, nil
+func (mockInvokerFactory) createInvoker(handle int64, sig signature.JSONServiceSignature, label security.Label) (ipc.Invoker, error) {
+	return &mockInvoker{handle: handle, sig: sig, label: label}, nil
 }
 
 type mockAuthorizer struct {
@@ -66,7 +68,7 @@
 			t.Fail()
 		}
 		signature := `{"add":{"inArgs":["foo","bar"],"numOutArgs":1,"isStreaming":false}}`
-		jsonResponse := `{"handle":1,"hasAuthorizer":false,"signature":` + signature + "}"
+		jsonResponse := fmt.Sprintf(`{"handle":1,"hasAuthorizer":false,"label":%d,"signature":%s}`, security.WriteLabel, signature)
 		d.handleLookupResponse(0, jsonResponse)
 	}()
 
@@ -82,7 +84,7 @@
 			NumOutArgs: 1,
 		},
 	}
-	expectedInvoker := &mockInvoker{handle: 1, sig: expectedSig}
+	expectedInvoker := &mockInvoker{handle: 1, sig: expectedSig, label: security.WriteLabel}
 	if !reflect.DeepEqual(invoker, expectedInvoker) {
 		t.Errorf("wrong invoker returned, expected: %v, got :%v", expectedInvoker, invoker)
 	}
@@ -114,7 +116,7 @@
 			t.Fail()
 		}
 		signature := `{"add":{"inArgs":["foo","bar"],"numOutArgs":1,"isStreaming":false}}`
-		jsonResponse := `{"handle":1,"hasAuthorizer":true,"signature":` + signature + "}"
+		jsonResponse := fmt.Sprintf(`{"handle":1,"hasAuthorizer":true,"label":%d,"signature":%s}`, security.ReadLabel, signature)
 		d.handleLookupResponse(0, jsonResponse)
 	}()
 
@@ -130,7 +132,7 @@
 			NumOutArgs: 1,
 		},
 	}
-	expectedInvoker := &mockInvoker{handle: 1, sig: expectedSig}
+	expectedInvoker := &mockInvoker{handle: 1, sig: expectedSig, label: security.ReadLabel}
 	if !reflect.DeepEqual(invoker, expectedInvoker) {
 		t.Errorf("wrong invoker returned, expected: %v, got :%v", expectedInvoker, invoker)
 	}
diff --git a/services/wsprd/ipc/server/invoker.go b/services/wsprd/ipc/server/invoker.go
index f6d668e..2f7736d 100644
--- a/services/wsprd/ipc/server/invoker.go
+++ b/services/wsprd/ipc/server/invoker.go
@@ -17,16 +17,18 @@
 	invokeFunc remoteInvokeFunc
 	// map of special methods like "Signature" which invoker handles on behalf of the actual service
 	predefinedInvokers map[string]ipc.Invoker
+
+	label security.Label
 }
 
 // newInvoker is an invoker factory
-func newInvoker(sig ipc.ServiceSignature, invokeFunc remoteInvokeFunc) ipc.Invoker {
+func newInvoker(sig ipc.ServiceSignature, label security.Label, invokeFunc remoteInvokeFunc) ipc.Invoker {
 	predefinedInvokers := make(map[string]ipc.Invoker)
 
 	// Special handling for predefined "signature" method
 	predefinedInvokers["Signature"] = newSignatureInvoker(sig)
 
-	i := &invoker{sig, invokeFunc, predefinedInvokers}
+	i := &invoker{sig, invokeFunc, predefinedInvokers, label}
 	return i
 }
 
@@ -49,7 +51,11 @@
 		argptrs[ix] = &x // Accept AnyData
 	}
 
-	securityLabel := methodSecurityLabel(method)
+	securityLabel := i.label
+
+	if !security.IsValidLabel(securityLabel) {
+		securityLabel = security.AdminLabel
+	}
 
 	return argptrs, securityLabel, nil
 }
@@ -90,9 +96,3 @@
 
 	return results, nil
 }
-
-// methodSecurityLabel returns the security label for a given method.
-func methodSecurityLabel(methodSig ipc.MethodSignature) security.Label {
-	// TODO(bprosnitz) Get the security label and return it here.
-	return security.AdminLabel
-}
diff --git a/services/wsprd/ipc/server/server.go b/services/wsprd/ipc/server/server.go
index dff31bc..3f4c73d 100644
--- a/services/wsprd/ipc/server/server.go
+++ b/services/wsprd/ipc/server/server.go
@@ -337,14 +337,14 @@
 	s.helper.CleanupFlow(id)
 }
 
-func (s *Server) createInvoker(handle int64, sig signature.JSONServiceSignature) (ipc.Invoker, error) {
+func (s *Server) createInvoker(handle int64, sig signature.JSONServiceSignature, label security.Label) (ipc.Invoker, error) {
 	serviceSig, err := sig.ServiceSignature()
 	if err != nil {
 		return nil, err
 	}
 
 	remoteInvokeFunc := s.createRemoteInvokerFunc(handle)
-	return newInvoker(serviceSig, remoteInvokeFunc), nil
+	return newInvoker(serviceSig, label, remoteInvokeFunc), nil
 }
 
 func (s *Server) createAuthorizer(handle int64, hasAuthorizer bool) (security.Authorizer, error) {