NewIdentityProvider initializes a new LDAP Identity Provider with the given configuration.
(config IdentityProviderConfig)
| 50 | // NewIdentityProvider initializes a new LDAP Identity Provider with the given |
| 51 | // configuration. |
| 52 | func NewIdentityProvider(config IdentityProviderConfig) (*IdentityProvider, error) { |
| 53 | for v, field := range map[string]string{ |
| 54 | config.Host: "host", |
| 55 | config.BindDN: "bindDn", |
| 56 | config.BindPassword: "bindPassword", |
| 57 | config.BaseDN: "baseDn", |
| 58 | config.UserFilter: "userFilter", |
| 59 | config.FieldMapping.Identifier: "fieldMapping.identifier", |
| 60 | } { |
| 61 | if v == "" { |
| 62 | return nil, errors.Errorf("the field %q is empty but required", field) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if config.Port <= 0 { |
| 67 | if config.SecurityProtocol == storepb.LDAPIdentityProviderConfig_LDAPS { |
| 68 | config.Port = 636 |
| 69 | } else { |
| 70 | config.Port = 389 |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return &IdentityProvider{ |
| 75 | config: config, |
| 76 | }, nil |
| 77 | } |
| 78 | |
| 79 | func (p *IdentityProvider) dial() (*ldap.Conn, error) { |
| 80 | tlsConfig := &tls.Config{ |