UFN_APPUSER_GETFROMLOGIN
Returns appuser of supplied login. This is used for verifying the appuser for applications run outside of the web service like reports.
Return
| Return Type |
|---|
| uniqueidentifier |
Parameters
| Parameter | Parameter Type | Mode | Description |
|---|---|---|---|
| @USERNAME | nvarchar(128) | IN |
Definition
Copy
CREATE function dbo.UFN_APPUSER_GETFROMLOGIN(@USERNAME nvarchar(128))
returns uniqueidentifier
as
begin
declare @r uniqueidentifier;
if exists (select top 1 1 from dbo.CONDITIONSETTING where NAME = 'CustomAuthentication')
select top 1 @r = ID from dbo.APPUSER where CUSTOM_AUTHENTICATION_USERID = @USERNAME;
if @r is null
begin
declare @USERSID varbinary(85) = SUSER_SID(@USERNAME);
if @USERSID is not null
select top 1 @r = ID from dbo.APPUSER where USERSID = @USERSID;
--The DB Server might not be able to resolve the name so double check.
if @r is null
select top 1 @r = ID from dbo.APPUSER where WINDOWSUSERNAME = @USERNAME or EMAILADDRESS = @USERNAME;
end
if @r is null and exists (select top 1 1 from dbo.CONDITIONSETTING where NAME = 'WSFederation')
select top 1 @r = APPUSER.ID from dbo.APPUSER inner join dbo.APPUSERCLAIMS on APPUSER.ID = APPUSERCLAIMS.APPUSERID where APPUSER.USERNAME = @USERNAME;
return @r
end