Skip to content

Commit 2a2708e

Browse files
crewjamKevin Coxe
andauthored
update package name (crewjam#594)
more updates to package name use new saml handler change from application handler to assertion handler remove useless coment Add SamlAssertionHandler to middleware keep import order fix spelling add in BassicAssertionHandler to do nothing by default fix lint fix lint Co-authored-by: Kevin Coxe <[email protected]>
1 parent ff03323 commit 2a2708e

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

samlsp/basic_assertion_handler.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package samlsp
2+
3+
import (
4+
"github.com/crewjam/saml"
5+
)
6+
7+
var _ AssertionHandler = NopAssertionHandler{}
8+
9+
// NopAssertionHandler is an implementation of AssertionHandler that does nothing.
10+
type NopAssertionHandler struct{}
11+
12+
// HandleAssertion is called and passed a SAML assertion. This implementation does nothing.
13+
func (as NopAssertionHandler) HandleAssertion(_ *saml.Assertion) error {
14+
return nil
15+
}

samlsp/middleware.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ import (
4040
// SAML service provider already has a private key, we borrow that key
4141
// to sign the JWTs as well.
4242
type Middleware struct {
43-
ServiceProvider saml.ServiceProvider
44-
OnError func(w http.ResponseWriter, r *http.Request, err error)
45-
Binding string // either saml.HTTPPostBinding or saml.HTTPRedirectBinding
46-
ResponseBinding string // either saml.HTTPPostBinding or saml.HTTPArtifactBinding
47-
RequestTracker RequestTracker
48-
Session SessionProvider
43+
ServiceProvider saml.ServiceProvider
44+
OnError func(w http.ResponseWriter, r *http.Request, err error)
45+
Binding string // either saml.HTTPPostBinding or saml.HTTPRedirectBinding
46+
ResponseBinding string // either saml.HTTPPostBinding or saml.HTTPArtifactBinding
47+
RequestTracker RequestTracker
48+
Session SessionProvider
49+
AssertionHandler AssertionHandler
4950
}
5051

5152
// ServeHTTP implements http.Handler and serves the SAML-specific HTTP endpoints
@@ -99,6 +100,11 @@ func (m *Middleware) ServeACS(w http.ResponseWriter, r *http.Request) {
99100
return
100101
}
101102

103+
if handlerErr := m.AssertionHandler.HandleAssertion(assertion); handlerErr != nil {
104+
m.OnError(w, r, handlerErr)
105+
return
106+
}
107+
102108
m.CreateSessionFromAssertion(w, r, assertion, m.ServiceProvider.DefaultRedirectURI)
103109
}
104110

samlsp/new.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ func DefaultServiceProvider(opts Options) saml.ServiceProvider {
131131
}
132132
}
133133

134+
// DefaultAssertionHandler returns the default AssertionHandler for the provided options,
135+
// a NopAssertionHandler configured to do nothing.
136+
func DefaultAssertionHandler(_ Options) NopAssertionHandler {
137+
return NopAssertionHandler{}
138+
}
139+
134140
// New creates a new Middleware with the default providers for the
135141
// given options.
136142
//
@@ -139,11 +145,12 @@ func DefaultServiceProvider(opts Options) saml.ServiceProvider {
139145
// in the returned Middleware.
140146
func New(opts Options) (*Middleware, error) {
141147
m := &Middleware{
142-
ServiceProvider: DefaultServiceProvider(opts),
143-
Binding: "",
144-
ResponseBinding: saml.HTTPPostBinding,
145-
OnError: DefaultOnError,
146-
Session: DefaultSessionProvider(opts),
148+
ServiceProvider: DefaultServiceProvider(opts),
149+
Binding: "",
150+
ResponseBinding: saml.HTTPPostBinding,
151+
OnError: DefaultOnError,
152+
Session: DefaultSessionProvider(opts),
153+
AssertionHandler: DefaultAssertionHandler(opts),
147154
}
148155
m.RequestTracker = DefaultRequestTracker(opts, &m.ServiceProvider)
149156
if opts.UseArtifactResponse {

samlsp/saml_assertion_handler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package samlsp
2+
3+
import "github.com/crewjam/saml"
4+
5+
// AssertionHandler is an interface implemented by types that can handle
6+
// assertions and add extra functionality
7+
type AssertionHandler interface {
8+
HandleAssertion(assertion *saml.Assertion) error
9+
}

0 commit comments

Comments
 (0)