// Path: src/main/java/act/aaa/model/UserBase.java
// public static final String PROP_ID = "id";


import act.Act;
import act.app.event.SysEventId;
import act.db.Dao;
import act.util.LogSupport;
import org.osgl.$;
import org.osgl.Lang;
import org.osgl.aaa.*;
import org.osgl.aaa.impl.SimplePrincipal;
import org.osgl.cache.CacheService;
import org.osgl.util.C;
import org.osgl.util.E;
import org.osgl.util.Generics;
import org.osgl.util.S;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.persistence.Id;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Set;
import static act.aaa.model.UserBase.PROP_ID;
         * Get the {@link Principal} from the user entity.
         *
         * This method relies on the implementation of
         * - {@link #privilegeOf(Object)}
         * - {@link #rolesOf(Object)}
         * - {@link #permissionsOf(Object)}
         *
         * App developer can also overwrite this method though
         * not recommended to do that
         *
         * @param user the user entity instance
         * @return the principal corresponding to the user entity
         */
        private Principal buildPrincipalFrom(USER_TYPE user) {
            if (user instanceof Principal) {
                return (Principal) user;
            }
            SimplePrincipal.Builder pb = new SimplePrincipal.Builder(username(user));
            AAAPersistentService store = persistentServiceProvider.get();
            Integer I = privilegeOf(user);
            if (null != I) {
                pb.grantPrivilege(store.findPrivilege(I));
            }
            for (String role: rolesOf(user)) {
                pb.grantRole(store.findByName(role, Role.class));
            }
            for (String perm: permissionsOf(user)) {
                pb.grantPermission(store.findByName(perm, Permission.class));
            }
            Principal principal = pb.toPrincipal();
// Path: src/main/java/act/aaa/model/UserBase.java
// public static final String PROP_ID = "id";


// Path: src/main/java/act/aaa/ActAAAService.java
import act.Act;
import act.app.event.SysEventId;
import act.db.Dao;
import act.util.LogSupport;
import org.osgl.$;
import org.osgl.Lang;
import org.osgl.aaa.*;
import org.osgl.aaa.impl.SimplePrincipal;
import org.osgl.cache.CacheService;
import org.osgl.util.C;
import org.osgl.util.E;
import org.osgl.util.Generics;
import org.osgl.util.S;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.persistence.Id;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Set;
import static act.aaa.model.UserBase.PROP_ID;

         * Get the {@link Principal} from the user entity.
         *
         * This method relies on the implementation of
         * - {@link #privilegeOf(Object)}
         * - {@link #rolesOf(Object)}
         * - {@link #permissionsOf(Object)}
         *
         * App developer can also overwrite this method though
         * not recommended to do that
         *
         * @param user the user entity instance
         * @return the principal corresponding to the user entity
         */
        private Principal buildPrincipalFrom(USER_TYPE user) {
            if (user instanceof Principal) {
                return (Principal) user;
            }
            SimplePrincipal.Builder pb = new SimplePrincipal.Builder(username(user));
            AAAPersistentService store = persistentServiceProvider.get();
            Integer I = privilegeOf(user);
            if (null != I) {
                pb.grantPrivilege(store.findPrivilege(I));
            }
            for (String role: rolesOf(user)) {
                pb.grantRole(store.findByName(role, Role.class));
            }
            for (String perm: permissionsOf(user)) {
                pb.grantPermission(store.findByName(perm, Permission.class));
            }
            Principal principal = pb.toPrincipal();
            if (PROP_ID.equals(AAAConfig.user.key.get())) {