Base solution for your next web application

Activities of "pnw"

The only other alternative to generic repositories is to create custom repositories that are still based on IRepository<TEntity, TPrimaryKey>.

Since I don't want ABP in my Windows Service, you are saying I'm out of luck trying to maintain centralized Core and EntityFramework projects and a shared Service project that holds a couple "Domain" services?

What did you mean initially by "If you want to use your regular classes in ABP, it will not be a problem"?

Thank you for replying.

Regarding your statement "If you want to use your regular classes in ABP, it will not be a problem.", I swapped out my website's Entities (the ones that inherit from Abp's Entity) with my POCO entities (basically the same classes but keeping their primary key IDs in the class and not inheriting from anything.)

Now Application services that inject the entities (wrapped in an IRepository) are complaining. For example:

private readonly IRepository<User, long> userRepository;

public UsersApplicationService
(
     IRepository<User, long> userRepo
)
{
     userRepository = userRepo;
}

The error is:

The type 'MyProject.Core.User' cannot be used as a type parameter 'TEntity' in the generic type or method 'IRepository<TEntity, TPrimaryKey>'. There is no implicit reference conversion from 'MyProject.Core.User' to 'Abp.Domain.Entities.IEntity<long>'.

My classes that use a int instead of a long (e.g. IRepository<Company>) give a similar error. I thought maybe since Entity automatically adds 'Id' to each descendent, that adding 'Id' to my POCO would help but the error persists.

With respect to Dependency Injection, I think I get the concept and don't expect that to be a problem.

What I ended up doing is to add a new ASPNET controller (I just added it to the existing HomeController) that takes a non # url and rewrites it and then calls the Angular url.

For example, in Angular I have routes that look like #/page1/10 #/page2/3 etc

My new ASPNET controller can take routes that look like /home/page/1/10 /home/page/2/3

Those routes call this controller

public ActionResult page()
{
    return Redirect(Request.Url.OriginalString.Replace("home", "#").Replace("page/", "page"));
}

It does the trick because I have only a specialized need for non-# urls in embedded email links. Users don't have to know or use these urls directly. And I don't have to have a raft of custom ASPNET controllers to make it happen since my Angular view names follow a strict pattern.

Note: I also added the non-# route structure to RouteConfig.cs

<cite>hikalkan: </cite> I assume that you are using ABP v1.0.

Can you try to add this into your module's PreInitialize:

Configuration.ReplaceService<IPermissionChecker, PermissionsChecker>(DependencyLifeStyle..Transient);

Be sure that the PermissionsChecker is your class (since abp.zero has same class name). To be sure, rename your class to CustomPermissionsChecker or something you more like.

I am using ABP 1.0. I renamed my checker to MyPermissionChecker.

When I try to add that line of code to my MyApplicationModule.PreInitialize()

using Abp.Authorization;
using Abp.Dependency;
...
Configuration.ReplaceService<IPermissionChecker, MyPermissionsChecker>(DependencyLifeStyle.Transient);

Visual Studio says "<span style="color:#FF0040">CS0308: This non-generic method 'IAbpStartupConfiguration.ReplaceService(Type,Action)' cannot be used with type arguments</span>."

I added [DisableAbpAntiForgeryTokenValidation] to the abstract base class

[DisableAbpAntiForgeryTokenValidation]
    public abstract class MyControllerBase : AbpController

Without doing anything else, I verify that the usual login page comes up and I can still log in as admin/123qwe

Now I uncomment the PostInitialize() filters to remove and add filters. The definition of MyMvcAuthorizeFilter is still the same as shown above.

public override void PostInitialize()
        {
            GlobalFilters.Filters.Remove(GlobalFilters.Filters.Single(f => f.Instance is AbpMvcAuthorizeFilter));
            GlobalFilters.Filters.Add(IocManager.Resolve<MyMvcAuthorizeFilter>());
            base.PostInitialize();
        }

Now when I run, the login page still comes up and I can log in as admin\123qwe. The home page starts to render, but an Abp error dialog "An error has occurred!" pops up. Then I notice that the upper right user badge shows {{vm.getShownUserName()}} instead of '.\admin' and view isn't getting rendered.

This is really frustrating. All I want to do is programmatically log in so that the Log in page doesn't appear. Should I just rip AbpZero out of my solution and just do plain old claims based authentication and authorization?

By userIddo you mean the PK of AbpUsers (ID)? Before I change the schema, I tried to test it first. I created a new user by logging in as Admin and going to the Users tab of the UI.

I then looked in AbpUsers and see that this new user has ID = 3.

I tried "3" in

new Claim(ClaimTypes.NameIdentifier, "3")

but the Login page still displays and while the MyMvcAuthorizeFilter is in place, I cannot login with Admin or the new account via the Login page. It throws "Empty or invalid anti forgery header token".

I've tried three claims

new Claim(ClaimTypes.Name, "3"),
new Claim(ClaimTypes.NameIdentifier, "3"),
new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "3")

I hope I interpreted your suggestion correctly!

It is still a mystery.

I don't know how to get AbpZero to realize that I'm already authenticated and look for my employee id in the Headers (every single web server in my intranet is behind WSSO so it is not possible to be unauthenticated prior to AbpZero taking over.)

var empid = filterContext.HttpContext.Request.Headers["employeeid"];

Then, how to bypass the Login page and tie my empid to whatever necessary records in the Abp tables. (e.g. Does my empid need to be in AbpUsers? If so, does it go in UserName field? What about the password field, which is superfluous in my case.)

Since I don't need AbpZero for Authentication, it still would be nice to take advantage Authorization features. But maybe that too much to hope for.

<cite>ismcagdas: </cite> Hi,

You can create a custom AuthorizeFilter for MVC or WebAPI and check the request here in that. Please see this issue <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1256">https://github.com/aspnetboilerplate/as ... ssues/1256</a>

I think I followed the instructions but the Log In page still displays. This is what I did:

I implemented a class called MyAuthorizeFilter and derived it from AbpMvcAuthorizeFilter. Then I overrode OnAuthorization to create the ClaimsPrincipal and attach it to the HttpContext.User.

public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var empid = filterContext.HttpContext.Request.Headers["employeeid"];
            if (empid == null) empid = "123456"; // for local testing

            ClaimsPrincipal currentPrincipal = new ClaimsPrincipal(
                new ClaimsIdentity(
                    new List<Claim>
                    {
                        new Claim(ClaimTypes.NameIdentifier, empid),
                        new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", empid)
                    }, "wsso"
                )
            );

            Thread.CurrentPrincipal = currentPrincipal;
            filterContext.HttpContext.User = currentPrincipal;

            base.OnAuthorization(filterContext);
        }

Then I added my class to the GlobalFilters by overriding the PostInitialize of MyProjectWebModule, per instructions.

public override void PostInitialize()
        {
            GlobalFilters.Filters.Remove(GlobalFilters.Filters.Single(f => f.Instance is AbpMvcAuthorizeFilter));
            GlobalFilters.Filters.Add(IocManager.Resolve<MyAuthorizeFilter>());
            base.PostInitialize();
        }

In the debugger, I see all the code get executed. Why isn't this enough to prevent the Log in page from appearing?

Oh yes, I do have the same employeeid in the Abp Users. The user properties User name: 123456 Full name: pnw Email address: <a href="mailto:[email protected]">[email protected]</a> IsActive: Yes Password: "1"

Then, when I try to log in, using Log in page and 123456/1 an error dialog appears "Empty or invalid anti forgery header token". What's that??

Answer

Not using module-zero. It doesn't support my company org structure.

Answer

Somehow I was inheriting from DbContext. Once I switched to AbpDbContext my repositories were happy.

Showing 1 to 10 of 13 entries