Ejemplo n.º 1
0
        private IdentityContainer GetIdentityContainer(string userName, string domainName, string environmentName, string applicationName)
        {
            if (!MarkelConfiguration.EnvironmentName.Equals(environmentName))
            {
                throw new NotAllowedAPIException($"Invalid Request! User '{userName}' is attempting to log into '{environmentName}'. Server is configured for '{MarkelConfiguration.EnvironmentName}' only!");
            }

            string            cacheKey = _cacheStoreManager.BuildKey("UserIdentity", userName);
            IdentityContainer cachedIdentityContainer = _cacheStoreManager.GetItem <IdentityContainer>(cacheKey, (action) =>
            {
                try
                {
                    IAuthorizationManager authorizationManager = new ERMSAuthorizationManager();
                    UserIdentity userIdentity = authorizationManager.GetUserIdentity(userName, domainName, environmentName, applicationName);
                    if (userIdentity != null)
                    {
                        // Auth Token expires in one year, or when API is restarted
                        return(new CacheItem(MarkelConfiguration.AccessTokenLifetime, null, new IdentityContainer(userIdentity)));
                    }

                    return(new CacheItem());
                }
                catch (Exception)
                {
                    string message = string.Format("Authentication failed for: Application: {0}, User: {1}, Domain: {2}, Environment: {3}", applicationName, userName, domainName, environmentName);
                    throw new UnauthorizedAPIException(message);
                }
            }, false);

            return(cachedIdentityContainer);
        }
Ejemplo n.º 2
0
    //This simply instantiates a network prefab.
    //The objct should already exist on the database.
    public GameObject SpawnObject(ushort objectID)
    {
        if (meshnet == null)
        {
            Debug.LogError("Trying to spawn object when underlying mesh network not intialized.");
            return(null);
        }
        if (meshnet.database.LookupObject(objectID) == null)
        {
            Debug.LogError("Trying to spawn network object without presence on the database");
            return(null);
        }
        MeshNetworkIdentity localIdentity = meshnet.database.LookupObject(objectID);

        localIdentity.SetMeshnetReference(meshnet); //set a reference to the mesh network
        if (networkPrefabs.ContainsKey(localIdentity.GetPrefabID()) == false)
        {
            Debug.LogError("NetworkPrefab registry error: Requested prefab ID does not exist.");
            return(null);
        }
        GameObject        g = Instantiate(networkPrefabs[localIdentity.GetPrefabID()]);
        IdentityContainer c = g.GetComponent <IdentityContainer>();

        if (c == null)
        {
            Debug.LogError("NetworkPrefab error: spawned prefab does not contain IdentityContainer");
            return(null);
        }
        c.SetIdentity(localIdentity);
        activeObjects.Add(objectID, g);
        return(g);
    }
Ejemplo n.º 3
0
        private IdentityContainer GetUserIdentityFromHttpContext()
        {
            // Get User Identity From Http Context
            var currentContext = System.Web.HttpContext.Current;

            if (currentContext?.User?.UserName() != null)
            {
                // User Info from OAuth Claims
                var    currentUser     = currentContext.User.Validate();
                string userName        = currentUser.UserName();
                string environmentName = currentUser.EnvironmentName();

                if (!MarkelConfiguration.EnvironmentName.Equals(environmentName))
                {
                    throw new NotAllowedAPIException($"Invalid Auth Token for User '{userName}' in '{environmentName}'! Expected '{MarkelConfiguration.EnvironmentName}'");
                }

                if (_identityContainer == null)
                {
                    string domainName      = currentUser.DomainName();
                    string applicationName = currentUser.ApplicationName();

                    _identityContainer = GetIdentityContainer(userName, domainName, environmentName, applicationName);
                }

                if (!userName.Equals(_identityContainer?.UserIdentity?.UserName))
                {
                    throw new Exception($"UserManager: User Name in HttpContext ({userName}) does not match current User Identity ({_identityContainer?.UserIdentity?.UserName})!");
                }

                return(_identityContainer);
            }

            return(null);
        }
Ejemplo n.º 4
0
    public GameObject SpawnDatabase(MeshNetworkIdentity i)
    {
        if (meshnet == null)
        {
            Debug.LogError("Trying to spawn object when underlying mesh network not intialized.");
            return(null);
        }
        if (i.GetObjectID() != (ushort)ReservedObjectIDs.DatabaseObject)
        {
            Debug.LogError("Trying to use database spawning method for non-database object");
            return(null);
        }
        i.SetMeshnetReference(meshnet); //set a reference to the mesh network
        if (networkPrefabs.ContainsKey(i.GetPrefabID()) == false)
        {
            Debug.LogError("NetworkPrefab registry error: Requested prefab ID does not exist.");
            return(null);
        }
        GameObject        g = Instantiate(networkPrefabs[i.GetPrefabID()]);
        IdentityContainer c = g.GetComponent <IdentityContainer>();

        if (c == null)
        {
            Debug.LogError("NetworkPrefab error: spawned prefab does not contain IdentityContainer");
            return(null);
        }
        c.SetIdentity(i);
        activeObjects.Add(i.GetObjectID(), g);
        return(g);
    }
Ejemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        thisTransform = transform;
        manager       = FindObjectOfType <PhysicsGridManager>();
        if (manager == null)
        {
            Debug.LogError("No grid manager found in scene");
        }
        if (transform.parent != null)
        {
            SetGrid(transform.parent.GetComponent <PhysicsGrid>(), true);
        }
        else
        {
            SetGrid(manager.GetGridByID((ushort)ReservedObjectIDs.RootGrid), true);
        }
        if (parentGrid == null)
        {
            Debug.Log("ZonedTransform does not have a parent grid, this should happen rarely");
        }
        debugRigidbody = GetComponent <Rigidbody>();

        IdentityContainer c = GetComponent <IdentityContainer>();

        if (c != null)
        {
            thisMNI = c.GetIdentity();
            hasIdentityContainer = true;
        }

        manager.TriggerRootScan();
    }
Ejemplo n.º 6
0
    void Update()
    {
        if (originTest)
        {
            originTest = false;
            Vector3 delta = new Vector3(1, 0, 1);
            currentWorldOrigin = currentWorldOrigin + delta;
            for (int i = 0; i < gridTransform.childCount; i++)
            {
                gridTransform.GetChild(i).localPosition -= delta;
            }
        }
        if (offsetSensor != null && (offsetSensor.position - gridTransform.position).magnitude > 1000)
        {
            Vector3 localDelta = gridTransform.worldToLocalMatrix * (offsetSensor.position - gridTransform.position);
            currentWorldOrigin = currentWorldOrigin + localDelta;
            for (int i = 0; i < gridTransform.childCount; i++)
            {
                gridTransform.GetChild(i).localPosition -= localDelta;
            }
        }

        if (thisMNI == null && hasGridID)
        {
            IdentityContainer c = gameObject.GetComponent <IdentityContainer>();
            if (c == null && proxy != null)
            {
                c = proxy.GetComponent <IdentityContainer>();
            }
            if (c == null)
            {
                thisMNI = null;
            }
            else
            {
                thisMNI = c.GetIdentity();
            }
        }
        if (proxy != null && proxyZT != null)   //if we have a proxy, and that proxy has a zone transform
        {
            gridZonedTransform.SetGrid(proxyZT.parentGrid, true);
            gridTransform.localPosition = proxyOffset + proxyZT.transform.localPosition;
            //gridTransform.localRotation = proxyZT.transform.localRotation;
        }
        else if (proxy != null)
        {
            gridTransform.position = proxyOffset + proxy.transform.position;
            //gridTransform.rotation = proxy.transform.rotation;
        }
    }
        /// <summary>
        /// Update identity
        /// <param name="body"></param>
        /// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
        /// </summary>
        public RequestInformation CreatePatchRequestInformation(IdentityContainer body, Action <IdentityRequestBuilderPatchRequestConfiguration> requestConfiguration = default)
        {
            _ = body ?? throw new ArgumentNullException(nameof(body));
            var requestInfo = new RequestInformation {
                HttpMethod     = Method.PATCH,
                UrlTemplate    = UrlTemplate,
                PathParameters = PathParameters,
            };

            requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
            if (requestConfiguration != null)
            {
                var requestConfig = new IdentityRequestBuilderPatchRequestConfiguration();
                requestConfiguration.Invoke(requestConfig);
                requestInfo.AddRequestOptions(requestConfig.Options);
                requestInfo.AddHeaders(requestConfig.Headers);
            }
            return(requestInfo);
        }
Ejemplo n.º 8
0
        private void UpdateIdentityContainer(IdentityContainer identityContainer)
        {
            string cacheKey = _cacheStoreManager.BuildKey("UserIdentity", identityContainer.UserIdentity.UserName);

            _cacheStoreManager.Update(cacheKey, identityContainer, false);
        }
Ejemplo n.º 9
0
 public static void InitializeIdentityContainer(Container container)
 {
     IdentityContainer.RegisterServices(container);
 }