actframework / act-aaa-plugin

Use OSGL aaa library to mange Authentication/Authorization/Accounting for ActFramework Application
Apache License 2.0
6 stars 2 forks source link

AAA execute same query 3 time for one permission check #27

Open leeaee opened 6 years ago

leeaee commented 6 years ago

When adding AAA required permission checking logic, the query user's SQL will execute three times for every time call.

    @GetAction("{id}")
    public Admin read(@NotNull Long id, String fields) {
        AAA.requirePermission(Permissions.PERM_ADMIN_READ);
        PropertySpec.current.set(fields);
        Admin admin = dao.findById(id);
        notFoundIfNull(admin, context.i18n(Messages.ENTITY_ID_NOT_FOUND, Admin.KEY, id));
        logger.debug("Read admin by id -> {}", id);
        return admin;
    }

When call read admin method. the logs shows the query login user with execute 3 times.

16:07:41.670 [XNIO-1 task-3] DEBUG e.logging.sql - SELECT ID, create_time, EMAIL, last_update, login_name, MOBILE, NAME, PASSWORD, PHONE, ROLES, SALT, STATE, VERSION FROM bb_admin WHERE (login_name = ?)
    bind => [admin]
16:07:41.672 [XNIO-1 task-3] DEBUG e.logging.sql - SELECT ID, create_time, EMAIL, last_update, login_name, MOBILE, NAME, PASSWORD, PHONE, ROLES, SALT, STATE, VERSION FROM bb_admin WHERE (login_name = ?)
    bind => [admin]
16:07:41.673 [XNIO-1 task-3] DEBUG e.logging.sql - SELECT ID, create_time, EMAIL, last_update, login_name, MOBILE, NAME, PASSWORD, PHONE, ROLES, SALT, STATE, VERSION FROM bb_admin WHERE (login_name = ?)
    bind => [admin]
16:07:41.675 [XNIO-1 task-3] DEBUG e.logging.sql - SELECT ID, create_time, EMAIL, last_update, login_name, MOBILE, NAME, PASSWORD, PHONE, ROLES, SALT, STATE, VERSION FROM bb_admin WHERE (ID = ?)
    bind => [1]
16:07:41.676 [XNIO-1 task-3] DEBUG c.b.n.a.AdminEndpoint - Read admin by id -> 1

Is there any way to optimize this?

greenlaw110 commented 4 years ago

@leeaee the cache mechanism introduced with #32 should fixed the issue.