2023-01-17 23:54:16 +00:00
|
|
|
// Copyright 2020-2023 the Pinniped contributors. All Rights Reserved.
|
2020-11-03 20:06:07 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2023-06-22 22:12:33 +00:00
|
|
|
package dynamicupstreamprovider
|
2020-11-03 20:06:07 +00:00
|
|
|
|
|
|
|
import (
|
2021-12-08 22:29:25 +00:00
|
|
|
"fmt"
|
2020-11-03 20:06:07 +00:00
|
|
|
"sync"
|
2020-11-18 21:38:13 +00:00
|
|
|
|
2023-06-22 22:12:33 +00:00
|
|
|
"go.pinniped.dev/internal/federationdomain/upstreamprovider"
|
2021-12-03 21:44:24 +00:00
|
|
|
)
|
|
|
|
|
2020-11-03 20:06:07 +00:00
|
|
|
type DynamicUpstreamIDPProvider interface {
|
2023-05-08 21:07:38 +00:00
|
|
|
SetOIDCIdentityProviders(oidcIDPs []upstreamprovider.UpstreamOIDCIdentityProviderI)
|
|
|
|
GetOIDCIdentityProviders() []upstreamprovider.UpstreamOIDCIdentityProviderI
|
|
|
|
SetLDAPIdentityProviders(ldapIDPs []upstreamprovider.UpstreamLDAPIdentityProviderI)
|
|
|
|
GetLDAPIdentityProviders() []upstreamprovider.UpstreamLDAPIdentityProviderI
|
|
|
|
SetActiveDirectoryIdentityProviders(adIDPs []upstreamprovider.UpstreamLDAPIdentityProviderI)
|
|
|
|
GetActiveDirectoryIdentityProviders() []upstreamprovider.UpstreamLDAPIdentityProviderI
|
2020-11-03 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type dynamicUpstreamIDPProvider struct {
|
2023-05-08 21:07:38 +00:00
|
|
|
oidcUpstreams []upstreamprovider.UpstreamOIDCIdentityProviderI
|
|
|
|
ldapUpstreams []upstreamprovider.UpstreamLDAPIdentityProviderI
|
|
|
|
activeDirectoryUpstreams []upstreamprovider.UpstreamLDAPIdentityProviderI
|
2021-07-02 22:30:27 +00:00
|
|
|
mutex sync.RWMutex
|
2020-11-03 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDynamicUpstreamIDPProvider() DynamicUpstreamIDPProvider {
|
|
|
|
return &dynamicUpstreamIDPProvider{
|
2023-05-08 21:07:38 +00:00
|
|
|
oidcUpstreams: []upstreamprovider.UpstreamOIDCIdentityProviderI{},
|
|
|
|
ldapUpstreams: []upstreamprovider.UpstreamLDAPIdentityProviderI{},
|
|
|
|
activeDirectoryUpstreams: []upstreamprovider.UpstreamLDAPIdentityProviderI{},
|
2020-11-03 20:06:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-08 21:07:38 +00:00
|
|
|
func (p *dynamicUpstreamIDPProvider) SetOIDCIdentityProviders(oidcIDPs []upstreamprovider.UpstreamOIDCIdentityProviderI) {
|
2021-04-07 23:12:13 +00:00
|
|
|
p.mutex.Lock() // acquire a write lock
|
|
|
|
defer p.mutex.Unlock()
|
|
|
|
p.oidcUpstreams = oidcIDPs
|
|
|
|
}
|
|
|
|
|
2023-05-08 21:07:38 +00:00
|
|
|
func (p *dynamicUpstreamIDPProvider) GetOIDCIdentityProviders() []upstreamprovider.UpstreamOIDCIdentityProviderI {
|
2021-04-07 23:12:13 +00:00
|
|
|
p.mutex.RLock() // acquire a read lock
|
|
|
|
defer p.mutex.RUnlock()
|
|
|
|
return p.oidcUpstreams
|
|
|
|
}
|
|
|
|
|
2023-05-08 21:07:38 +00:00
|
|
|
func (p *dynamicUpstreamIDPProvider) SetLDAPIdentityProviders(ldapIDPs []upstreamprovider.UpstreamLDAPIdentityProviderI) {
|
2020-11-03 20:06:07 +00:00
|
|
|
p.mutex.Lock() // acquire a write lock
|
|
|
|
defer p.mutex.Unlock()
|
2021-04-07 23:12:13 +00:00
|
|
|
p.ldapUpstreams = ldapIDPs
|
2020-11-03 20:06:07 +00:00
|
|
|
}
|
|
|
|
|
2023-05-08 21:07:38 +00:00
|
|
|
func (p *dynamicUpstreamIDPProvider) GetLDAPIdentityProviders() []upstreamprovider.UpstreamLDAPIdentityProviderI {
|
2020-11-03 20:06:07 +00:00
|
|
|
p.mutex.RLock() // acquire a read lock
|
|
|
|
defer p.mutex.RUnlock()
|
2021-04-07 23:12:13 +00:00
|
|
|
return p.ldapUpstreams
|
2020-11-03 20:06:07 +00:00
|
|
|
}
|
2021-07-02 22:30:27 +00:00
|
|
|
|
2023-05-08 21:07:38 +00:00
|
|
|
func (p *dynamicUpstreamIDPProvider) SetActiveDirectoryIdentityProviders(adIDPs []upstreamprovider.UpstreamLDAPIdentityProviderI) {
|
2021-07-02 22:30:27 +00:00
|
|
|
p.mutex.Lock() // acquire a write lock
|
|
|
|
defer p.mutex.Unlock()
|
|
|
|
p.activeDirectoryUpstreams = adIDPs
|
|
|
|
}
|
|
|
|
|
2023-05-08 21:07:38 +00:00
|
|
|
func (p *dynamicUpstreamIDPProvider) GetActiveDirectoryIdentityProviders() []upstreamprovider.UpstreamLDAPIdentityProviderI {
|
2021-07-02 22:30:27 +00:00
|
|
|
p.mutex.RLock() // acquire a read lock
|
|
|
|
defer p.mutex.RUnlock()
|
|
|
|
return p.activeDirectoryUpstreams
|
|
|
|
}
|
2021-12-08 22:29:25 +00:00
|
|
|
|
|
|
|
type RetryableRevocationError struct {
|
|
|
|
wrapped error
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRetryableRevocationError(wrapped error) RetryableRevocationError {
|
|
|
|
return RetryableRevocationError{wrapped: wrapped}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e RetryableRevocationError) Error() string {
|
|
|
|
return fmt.Sprintf("retryable revocation error: %v", e.wrapped)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e RetryableRevocationError) Unwrap() error {
|
|
|
|
return e.wrapped
|
|
|
|
}
|