Jonathan Turner %!s(int64=9) %!d(string=hai) anos
pai
achega
d4558216b4
Modificáronse 5 ficheiros con 8 adicións e 6 borrados
  1. 1 1
      credentials/credentials.go
  2. 2 1
      examples/example.go
  3. 2 1
      examples/httpServer.go
  4. 1 2
      service/http.go
  5. 2 1
      service/http_test.go

+ 1 - 1
credentials/credentials.go

@@ -16,7 +16,7 @@ type Credentials struct {
 	CName      types.PrincipalName
 	Keytab     keytab.Keytab
 	Password   string
-	Attributes []string
+	Attributes map[string]interface{}
 }
 
 // Create a new Credentials struct.

+ 2 - 1
examples/example.go

@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"github.com/jcmturner/gokrb5/client"
 	"github.com/jcmturner/gokrb5/config"
+	"github.com/jcmturner/gokrb5/credentials"
 	"github.com/jcmturner/gokrb5/keytab"
 	"github.com/jcmturner/gokrb5/service"
 	"github.com/jcmturner/gokrb5/testdata"
@@ -85,6 +86,6 @@ func httpServer() *httptest.Server {
 func testAppHandler(w http.ResponseWriter, r *http.Request) {
 	w.WriteHeader(http.StatusOK)
 	ctx := r.Context()
-	fmt.Fprintf(w, "<html>\nTEST.GOKRB5 Handler\nAuthenticed user: %s\nUser's realm: %s\n</html>", ctx.Value("cname").(string), ctx.Value("crealm").(string))
+	fmt.Fprintf(w, "<html>\nTEST.GOKRB5 Handler\nAuthenticed user: %s\nUser's realm: %s\n</html>", ctx.Value("credentials").(credentials.Credentials).Username, ctx.Value("credentials").(credentials.Credentials).Realm)
 	return
 }

+ 2 - 1
examples/httpServer.go

@@ -5,6 +5,7 @@ package main
 import (
 	"encoding/hex"
 	"fmt"
+	"github.com/jcmturner/gokrb5/credentials"
 	"github.com/jcmturner/gokrb5/keytab"
 	"github.com/jcmturner/gokrb5/service"
 	"github.com/jcmturner/gokrb5/testdata"
@@ -36,6 +37,6 @@ func main() {
 func testAppHandler(w http.ResponseWriter, r *http.Request) {
 	w.WriteHeader(http.StatusOK)
 	ctx := r.Context()
-	fmt.Fprintf(w, "<html>\nTEST.GOKRB5 Handler\nAuthenticed user: %s\nUser's realm: %s\n</html>", ctx.Value("cname").(string), ctx.Value("crealm").(string))
+	fmt.Fprintf(w, "<html>\nTEST.GOKRB5 Handler\nAuthenticed user: %s\nUser's realm: %s\n</html>", ctx.Value("credentials").(credentials.Credentials).Username, ctx.Value("credentials").(credentials.Credentials).Realm)
 	return
 }

+ 1 - 2
service/http.go

@@ -56,8 +56,7 @@ func SPNEGOKRB5Authenticate(f http.Handler, kt keytab.Keytab, l *log.Logger) htt
 
 		if ok, creds, err := ValidateAPREQ(mt.APReq, kt, r.RemoteAddr); ok {
 			ctx := r.Context()
-			ctx = context.WithValue(ctx, "cname", creds.Username)
-			ctx = context.WithValue(ctx, "crealm", creds.Realm)
+			ctx = context.WithValue(ctx, "credentials", creds)
 			ctx = context.WithValue(ctx, "authenticated", true)
 			if l != nil {
 				l.Printf("%v %s@%s - SPNEGO authentication succeeded", r.RemoteAddr, creds.Username, creds.Realm)

+ 2 - 1
service/http_test.go

@@ -4,6 +4,7 @@ import (
 	"encoding/hex"
 	"fmt"
 	"github.com/jcmturner/gokrb5/client"
+	"github.com/jcmturner/gokrb5/credentials"
 	"github.com/jcmturner/gokrb5/iana/nametype"
 	"github.com/jcmturner/gokrb5/keytab"
 	"github.com/jcmturner/gokrb5/messages"
@@ -128,6 +129,6 @@ func httpServer() *httptest.Server {
 func testAppHandler(w http.ResponseWriter, r *http.Request) {
 	w.WriteHeader(http.StatusOK)
 	ctx := r.Context()
-	fmt.Fprintf(w, "<html>\nTEST.GOKRB5 Handler\nAuthenticed user: %s\nUser's realm: %s\n</html>", ctx.Value("cname").(string), ctx.Value("crealm").(string))
+	fmt.Fprintf(w, "<html>\nTEST.GOKRB5 Handler\nAuthenticed user: %s\nUser's realm: %s\n</html>", ctx.Value("credentials").(credentials.Credentials).Username, ctx.Value("credentials").(credentials.Credentials).Realm)
 	return
 }