Ejemplo n.º 1
0
        public AbstractController()
        {
            string         connectionstring = WebConfigManipulation.GetConfig("ConnectionString");
            ConnectionEnum connectionType   = (ConnectionEnum)Convert.ToInt32(WebConfigManipulation.GetConfig("ConnectionType"));

            ConnectionString  = connectionstring;
            ConnectionType    = connectionType;
            ConnectionFactory = new ConnectionFactory(ConnectionString, ConnectionType);

            var identity  = User.Identity as System.Security.Claims.ClaimsIdentity;
            int usuarioId = 0;
            int?empresaId = null;

            if (identity.Claims.Count() > 0)
            {
                usuarioId = Convert.ToInt32(identity.Claims.Single(x => x.Type == "Id").Value);
                if (identity.Claims.Any(x => x.Type == "EmpresaId"))
                {
                    empresaId = Convert.ToInt32(identity.Claims.Single(x => x.Type == "EmpresaId").Value);
                }
            }

            UsuarioId = usuarioId;
            EmpresaId = empresaId;
        }
Ejemplo n.º 2
0
        public EsMount ChangeMountConnection(EsMount mount, ConnectionEnum newConnection)
        {
            EsMount result = null;

            switch (newConnection)
            {
            case ConnectionEnum.TCP:
                result = ConvertToTCPConnectedMount(mount);
                break;

            case ConnectionEnum.UDP:
                result = ConvertToUDPConnectedMount(mount);
                break;

            case ConnectionEnum.Serial:
                result = ConvertToSerialPConnectedMount(mount);
                break;

            case ConnectionEnum.NONE:
                break;

            default:
                break;
            }
            return(result);
        }
Ejemplo n.º 3
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            string         connectionstring = WebConfigManipulation.GetConfig("ConnectionString");
            ConnectionEnum connectionType   = (ConnectionEnum)Convert.ToInt32(WebConfigManipulation.GetConfig("ConnectionType"));

            var connectionFactory = new ConnectionFactory(connectionstring, connectionType);

            var userBO = new UsuarioBO(connectionFactory, 0, 0);

            int empresaId = Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["empresaId"]);

            var loginUser = userBO.Login(context.UserName, context.Password, empresaId);

            if (loginUser == null)
            {
                context.SetError("invalid_grant", "Usuário ou senha incorretos");
                return;
            }

            ClaimsIdentity identity = new ClaimsIdentity(OAuthDefaults.AuthenticationType);

            identity.AddClaim(new Claim("Id", loginUser.UsuarioId.ToString()));
            identity.AddClaim(new Claim("EmpresaId", loginUser.EmpresaId.ToString()));

            var ticket = new AuthenticationTicket(identity, null);

            context.Validated(ticket);
            await Task.FromResult <object>(ticket);
        }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            var actionName = actionContext.ActionDescriptor.ActionName;

            if (!string.IsNullOrEmpty(AuthMethod))
            {
                actionName = AuthMethod;
            }

            var controllerName           = actionContext.ControllerContext.ControllerDescriptor.ControllerName;
            var controllerActionsToCheck = actionContext.ControllerContext.ControllerDescriptor.GetCustomAttributes <AuthorizeControllerActionsAttribute>().FirstOrDefault();

            bool checkAction = true;

            string[] defaultActions = new string[] { "Insert", "IdentityInsert", "Find", "List", "Update", "Delete", "Activate", "Deactivate" };

            if (defaultActions.Contains(actionName) && (
                    (actionName == "Insert" && controllerActionsToCheck.CheckInsert) ||
                    (actionName == "IdentityInsert" && controllerActionsToCheck.CheckIdentityInsert) ||
                    (actionName == "Find" && controllerActionsToCheck.CheckFind) ||
                    (actionName == "List" && controllerActionsToCheck.CheckList) ||
                    (actionName == "Update" && controllerActionsToCheck.CheckUpdate) ||
                    (actionName == "Delete" && controllerActionsToCheck.CheckDelete) ||
                    (actionName == "Activate" && controllerActionsToCheck.CheckActivate) ||
                    (actionName == "Deactivate" && controllerActionsToCheck.CheckDeactivate)))
            {
                checkAction = true;
            }
            else if (defaultActions.Contains(actionName))
            {
                checkAction = false;
            }

            if (checkAction)
            {
                base.OnAuthorization(actionContext);
                if (!HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    return;
                }
                var identity  = HttpContext.Current.User.Identity as System.Security.Claims.ClaimsIdentity;
                int empresaId = Convert.ToInt32(identity.Claims.Single(x => x.Type == "EmpresaId").Value);
                int usuarioId = Convert.ToInt32(identity.Claims.Single(x => x.Type == "Id").Value);

                bool usuarioAutorizado = false;

                string         connectionString = WebConfigManipulation.GetConfig("ConnectionString");
                ConnectionEnum connectionType   = (ConnectionEnum)Convert.ToInt32(WebConfigManipulation.GetConfig("ConnectionType"));
                using (var connectionFactory = new ConnectionFactory(connectionString, connectionType))
                    usuarioAutorizado = new PermissaoUsuarioDAO(connectionFactory, empresaId).UsuarioPossuiPermissao(usuarioId, controllerName, actionName);

                if (!usuarioAutorizado)
                {
                    HandleUnauthorizedRequest(actionContext);
                }
            }
        }
Ejemplo n.º 5
0
        public static SqlConnection getInstancia(ConnectionEnum enConn)
        {
            if (poolInstancia[Convert.ToInt32(enConn)] == null)
            {
                new Conexao(enConn);
            }

            return(poolInstancia[Convert.ToInt32(enConn)]);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="connectionName"></param>
 /// <param name="type">在ConnectionEnum.CustomizeConnectionString条件下必填type</param>
 public DatabaseConnectionAttribute(ConnectionEnum connectionName, Type type = null)
 {
     if (connectionName == ConnectionEnum.CustomizeConnectionString)
     {
         if (type == null)
         {
             throw new ArgumentException($"DatabaseConnectionAttribute.{nameof(type)}不允许为空");
         }
         else if (!typeof(ICustomizeConnectionString).IsAssignableFrom(type))
         {
             throw new ArgumentException($"{type.Name}必须实现接口{nameof(ICustomizeConnectionString)}");
         }
     }
     ConnectionName = connectionName.ToString();
 }
Ejemplo n.º 7
0
        public override Task TokenEndpointResponse(OAuthTokenEndpointResponseContext context)
        {
            var            accessToken      = context.AccessToken;
            var            identidade       = context.Identity;
            string         connectionstring = WebConfigManipulation.GetConfig("ConnectionString");
            ConnectionEnum connectionType   = (ConnectionEnum)Convert.ToInt32(WebConfigManipulation.GetConfig("ConnectionType"));

            var connectionFactory = new ConnectionFactory(connectionstring, connectionType);

            int id        = Convert.ToInt32(identidade.Claims.Single(x => x.Type == "Id").Value);
            int empresaId = Convert.ToInt32(identidade.Claims.Single(x => x.Type == "EmpresaId").Value);
            var userBO    = new UsuarioBO(connectionFactory, id, empresaId);

            userBO.AtualizarToken(id, accessToken);
            return(Task.FromResult <object>(null));
        }
Ejemplo n.º 8
0
        public IDBConnection GetConnection(ConnectionEnum value)
        {
            IDBConnection result = null;

            switch (value)
            {
            case ConnectionEnum.MSSQL:
                result = new MSSQLConnection();
                break;

            case ConnectionEnum.Oracle:
                result = new OracleConnection();
                break;
            }

            return(result);
        }
Ejemplo n.º 9
0
        public ConnectionFactory(string connectionString, ConnectionEnum connectionType)
        {
            ConnectionType = connectionType;

            switch (connectionType)
            {
            case ConnectionEnum.MySql:
                DbConnection = new MySQLConnection(connectionString);
                break;

            case ConnectionEnum.SqlServer:
                break;

            default:
                break;
            }
        }
Ejemplo n.º 10
0
        public static Connection getConnection(ConnectionEnum connectionEnum, IConnectionMethod connectionMethod)
        {
            Connection _connection = new Connection();

            _connection.setConnectionMethod(connectionMethod);

            switch (connectionEnum.ToString())
            {
            case "POSTS":
                _connection.URI = POSTS_URI;
                break;

            case "USERS":
                _connection.URI = USERS_URI;
                break;

            default:
                break;
            }

            return(_connection);
        }
 public MountConnectionSettings()
 {
     IsConnected = ConnectionEnum.NONE;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Construtor, recebe um enum que determina o tipo de operacao no campo da classe
 /// </summary>
 /// <param name="tipo">Tipo.</param>
 public ORMAttribute(ConnectionEnum tipo)
 {
     Tipo = tipo;
 }