mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
feat(saml): implementation of saml for ZITADEL v2 (#3618)
This commit is contained in:
61
internal/repository/keypair/certificate.go
Normal file
61
internal/repository/keypair/certificate.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package keypair
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
AddedCertificateEventType = eventTypePrefix + "certificate.added"
|
||||
)
|
||||
|
||||
type AddedCertificateEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Certificate *Key `json:"certificate"`
|
||||
}
|
||||
|
||||
func (e *AddedCertificateEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *AddedCertificateEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewAddedCertificateEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
certificateCrypto *crypto.CryptoValue,
|
||||
certificateExpiration time.Time) *AddedCertificateEvent {
|
||||
return &AddedCertificateEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
AddedCertificateEventType,
|
||||
),
|
||||
Certificate: &Key{
|
||||
Key: certificateCrypto,
|
||||
Expiry: certificateExpiration,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func AddedCertificateEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
e := &AddedCertificateEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "KEY-4n9vs", "unable to unmarshal certificate added")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
@@ -6,4 +6,5 @@ import (
|
||||
|
||||
func RegisterEventMappers(es *eventstore.Eventstore) {
|
||||
es.RegisterFilterEventMapper(AddedEventType, AddedEventMapper)
|
||||
es.RegisterFilterEventMapper(AddedCertificateEventType, AddedCertificateEventMapper)
|
||||
}
|
||||
|
Reference in New Issue
Block a user