// +build examples package main import ( "encoding/hex" "fmt" "log" "net/http" "os" //"github.com/pkg/profile" "gopkg.in/jcmturner/gokrb5.v5/credentials" "gopkg.in/jcmturner/gokrb5.v5/keytab" "gopkg.in/jcmturner/gokrb5.v5/service" "gopkg.in/jcmturner/gokrb5.v5/testdata" ) const ( port = ":9080" ) func main() { //defer profile.Start(profile.TraceProfile).Stop() // Create logger l := log.New(os.Stderr, "GOKRB5 Service: ", log.Ldate|log.Ltime|log.Lshortfile) // Load the service's keytab b, _ := hex.DecodeString(testdata.HTTP_KEYTAB) kt, _ := keytab.Parse(b) // Create the application's specific handler th := http.HandlerFunc(testAppHandler) // Set up handler mappings wrapping in the SPNEGOKRB5Authenticate handler wrapper mux := http.NewServeMux() mux.Handle("/", service.SPNEGOKRB5Authenticate(th, kt, "", false, l)) // Start up the web server log.Fatal(http.ListenAndServe(port, mux)) } // Simple application specific handler func testAppHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) ctx := r.Context() creds := ctx.Value(service.CTXKeyCredentials).(credentials.Credentials) fmt.Fprintf(w, `

GOKRB5 Handler