gov.va.medora.mdws.MdwsUtils.isValidCredentials C# (CSharp) Method

isValidCredentials() public static method

public static isValidCredentials ( string authenticationMethod, AbstractCredentials credentials, AbstractPermission permission ) : bool
authenticationMethod string
credentials gov.va.medora.mdo.dao.AbstractCredentials
permission gov.va.medora.mdo.dao.AbstractPermission
return bool
        public static bool isValidCredentials(string authenticationMethod, AbstractCredentials credentials, AbstractPermission permission)
        {
            if (credentials == null)
            {
                return false;
            }
            if (authenticationMethod == MdwsConstants.LOGIN_CREDENTIALS)
            {
                if (String.IsNullOrEmpty(credentials.AccountName) ||
                    String.IsNullOrEmpty(credentials.AccountPassword))
                {
                    return false;
                }
            }
            else if (authenticationMethod == MdwsConstants.NON_BSE_CREDENTIALS)
            {
                if (String.IsNullOrEmpty(credentials.LocalUid) ||
                    String.IsNullOrEmpty(credentials.FederatedUid) ||
                    String.IsNullOrEmpty(credentials.SubjectName) ||
                    credentials.AuthenticationSource == null ||
                    credentials.AuthenticationSource.SiteId == null ||
                    String.IsNullOrEmpty(credentials.AuthenticationSource.SiteId.Id) ||
                    String.IsNullOrEmpty(credentials.AuthenticationSource.SiteId.Name) ||
                    String.IsNullOrEmpty(credentials.AuthenticationToken))
                {
                    return false;
                }
            }
            else if (authenticationMethod == MdwsConstants.BSE_CREDENTIALS_V2WEB)
            {
                if (String.IsNullOrEmpty(credentials.LocalUid) ||
                    String.IsNullOrEmpty(credentials.FederatedUid) ||
                    String.IsNullOrEmpty(credentials.SubjectName) ||
                    credentials.AuthenticationSource == null ||
                    credentials.AuthenticationSource.SiteId == null ||
                    String.IsNullOrEmpty(credentials.AuthenticationSource.SiteId.Id) ||
                    String.IsNullOrEmpty(credentials.AuthenticationSource.SiteId.Name) ||
                    String.IsNullOrEmpty(credentials.AuthenticationToken) ||
                    String.IsNullOrEmpty(credentials.SecurityPhrase))
                {
                    return false;
                }
            }
            else
            {
                throw new ArgumentException("Invalid credential type");
            }
            if (permission == null || String.IsNullOrEmpty(permission.Name))
            {
                return false;
            }
            return true;
        }

Usage Example

コード例 #1
0
ファイル: AccountLib.cs プロジェクト: monkeyglasses/mdws
        // This is the core visit method the others are using. The permission must have been set before
        // getting here.
        internal User doTheVisit(string sitecode, AbstractCredentials credentials, AbstractPermission permission)
        {
            Site       site = mySession.SiteTable.getSite(sitecode);
            DataSource src  = site.getDataSourceByModality("HIS");

            if (src == null)
            {
                throw new Exception("No HIS data source at site " + sitecode);
            }

            AbstractDaoFactory factory = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));

            myCxn = factory.getConnection(src);
            myCxn.Account.AuthenticationMethod = mySession.DefaultVisitMethod;

            if (!MdwsUtils.isValidCredentials(myCxn.Account.AuthenticationMethod, credentials, permission))
            {
                throw new Exception("Invalid credentials");
            }

            object result = null;

            if (myCxn.Account.AuthenticationMethod == VistaConstants.BSE_CREDENTIALS_V2WEB)
            {
                result = myCxn.authorizedConnect(credentials, permission,
                                                 new DataSource()
                {
                    ConnectionString = mySession.MdwsConfiguration.BseValidatorConnectionString
                });
            }
            else
            {
                result = myCxn.authorizedConnect(credentials, permission, null);
            }
            if (result.GetType().Name.EndsWith("Exception"))
            {
                throw (Exception)result;
            }
            else
            {
                return((User)result);
            }
        }