Open Closed

I would like to specify the IP address that can be used to log in for each tenant #6130


User avatar
0
portx-dev created

I would like to specify the IP address that can be used to log in for each tenant. Is this possible with ABP Commercial's functions?

ABP Framework version: Commercial 7.4 UI type: Angular DB provider: EF Core


5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Just an idea:

    First, custom the tenant entity:

    ObjectExtensionManager.Instance.Modules()
        .ConfigureSaas(saas =>
        {
            saas.ConfigureTenant(tenant =>
            {
                tenant.AddOrUpdateProperty<string>( //property type: string
                    "AllowedIpAddress", //property name
                    property =>
                    {
                    }
                );
            });
        });
    

    Then, you can create a middleware that checks the login IP address:

    app.Use(async (httpContext, next) =>
    {
        if(httpContext.Request.Path.ToString().Contains("account/login", StringComparison.InvariantCultureIgnoreCase))
        {
            var currentTenant = context.ServiceProvider.GetRequiredService<ICurrentTenant>();
            if (currentTenant.IsAvailable)
            {
                var tenant = await context.ServiceProvider.GetRequiredService<ITenantRepository>().FindAsync(currentTenant.GetId());
                var allowedIp = tenant.GetProperty<string>("AllowedIpAddress");
                if (!string.IsNullOrEmpty(allowedIp))
                {
                    var remoteIp = httpContext.Connection.RemoteIpAddress.ToString();
                    if (!remoteIp.Equals(allowedIp, StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new Exception("You are not allowed to login from this IP address.");
                    }
                }
            }
        }
        await next();
    });
    
  • User Avatar
    0
    portx-dev created

    thx

    Are there any plans to implement this kind of functionality in ABP Commercial?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    As I know we have no plan yet.

  • User Avatar
    0
    portx-dev created

    ok,thx

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    :)

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09