Extract the username and realm from full UPN
(upn)
| 4152 | |
| 4153 | |
| 4154 | def _parse_upn(upn): |
| 4155 | """ |
| 4156 | Extract the username and realm from full UPN |
| 4157 | """ |
| 4158 | m = re.match(r"^([^@\\/]+)(@|\\)([^@\\/]+)$", upn) |
| 4159 | if not m: |
| 4160 | err = "Invalid UPN: '%s'" % upn |
| 4161 | if "/" in upn: |
| 4162 | err += ". Did you mean '%s' ?" % upn.replace("/", "\\") |
| 4163 | elif "@" not in upn and "\\" not in upn: |
| 4164 | err += ". Provide domain as so: '%s@domain.local'" % upn |
| 4165 | raise ValueError(err) |
| 4166 | if m.group(2) == "@": |
| 4167 | user = m.group(1) |
| 4168 | domain = m.group(3) |
| 4169 | else: |
| 4170 | user = m.group(3) |
| 4171 | domain = m.group(1) |
| 4172 | return user, domain |
| 4173 | |
| 4174 | |
| 4175 | def _parse_spn(spn): |
no test coverage detected