|
| 1 | +-------------------------------------------------------------------------------- |
| 2 | +-- SAML2 Middleware for WAI -- |
| 3 | +-------------------------------------------------------------------------------- |
| 4 | +-- This source code is licensed under the MIT license found in the LICENSE -- |
| 5 | +-- file in the root directory of this source tree. -- |
| 6 | +-------------------------------------------------------------------------------- |
| 7 | +{-# LANGUAGE DeriveGeneric #-} |
| 8 | +{-# LANGUAGE LambdaCase #-} |
| 9 | + |
| 10 | +-- | This modules defines 'NameIDFormat', the datatype specifying the format |
| 11 | +-- of the identifier in an assertion. |
| 12 | +module Network.Wai.SAML2.NameIDFormat ( |
| 13 | + NameIDFormat(..), |
| 14 | + parseNameIDFormat |
| 15 | +) where |
| 16 | + |
| 17 | +import Data.Text (Text, unpack) |
| 18 | +import GHC.Generics (Generic) |
| 19 | + |
| 20 | +-- | Format of the subject identifier. |
| 21 | +-- See 8.3 Name Identifier Format Identifiers in https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf |
| 22 | +data NameIDFormat |
| 23 | + -- | The interpretation is left to individual implementations |
| 24 | + = Unspecified |
| 25 | + -- | @addr-spec@ as defined in IETF RFC 2822 |
| 26 | + | EmailAddress |
| 27 | + -- | contents of the @<ds:X509SubjectName>@ element in the XML Signature Recommendation |
| 28 | + | X509SubjectName |
| 29 | + -- | String of the form @DomainName\UserName@ |
| 30 | + | WindowsDomainQualifiedName |
| 31 | + -- | Kerberos principal name using the format @name[/instance]@REALM@ |
| 32 | + | KerberosPrincipalName |
| 33 | + -- | identifier of an entity that provides SAML-based services |
| 34 | + -- (such as a SAML authority, requester, or responder) or is a participant in SAML profiles (such as a service |
| 35 | + -- provider supporting the browser SSO profile) |
| 36 | + | Entity |
| 37 | + -- | identifier of a provider of SAML-based services |
| 38 | + -- (such as a SAML authority) or a participant in SAML |
| 39 | + -- profiles (such as a service provider supporting the browser profiles) |
| 40 | + | Provider |
| 41 | + -- | persistent opaque identifier that corresponds to an identity |
| 42 | + -- federation between an identity provider and a service provider |
| 43 | + | Federated |
| 44 | + -- | an identifier with transient semantics and SHOULD be treated |
| 45 | + -- as an opaque and temporary value by the relying party |
| 46 | + | Transient |
| 47 | + -- | persistent opaque identifier for a principal that is specific to |
| 48 | + -- an identity provider and a service provider or affiliation of service providers |
| 49 | + | Persistent |
| 50 | + deriving (Eq, Ord, Show, Generic) |
| 51 | + |
| 52 | +-- | Parse a 'NameIDFormat' (prefixed by @urn:oasis:names:tc:SAML:*:nameid-format@). |
| 53 | +parseNameIDFormat :: MonadFail m => Text -> m NameIDFormat |
| 54 | +parseNameIDFormat = \case |
| 55 | + "urn:oasis:names:tc:SAML:1.1:nameid-format:Kerberos" -> pure KerberosPrincipalName |
| 56 | + "urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName" -> pure WindowsDomainQualifiedName |
| 57 | + "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName" -> pure X509SubjectName |
| 58 | + "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" -> pure EmailAddress |
| 59 | + "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" -> pure Unspecified |
| 60 | + "urn:oasis:names:tc:SAML:2.0:nameid-format:entity" -> pure Entity |
| 61 | + "urn:oasis:names:tc:SAML:2.0:nameid-format:federated" -> pure Federated |
| 62 | + "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" -> pure Persistent |
| 63 | + "urn:oasis:names:tc:SAML:2.0:nameid-format:provider" -> pure Provider |
| 64 | + "urn:oasis:names:tc:SAML:2.0:nameid-format:transient" -> pure Transient |
| 65 | + unknown -> fail $ "parseNameIDFormat: unknown format " <> unpack unknown |
0 commit comments