Search in sources :

Example 1 with User

use of life.genny.qwanda.entity.User in project rulesservice by genny-project.

the class EBCHandlers method initMsg.

public static void initMsg(final String msgType, String ruleGroup, final Object msg, final EventBus eventBus) {
    Vertx.currentContext().owner().executeBlocking(future -> {
        Map<String, Object> adecodedTokenMap = new HashMap<String, Object>();
        Set<String> auserRoles = new HashSet<String>();
        auserRoles.add("admin");
        auserRoles.add("user");
        QRules qRules = new QRules(eventBus, token, adecodedTokenMap);
        qRules.set("realm", ruleGroup);
        List<Tuple2<String, Object>> globals = RulesLoader.getStandardGlobals();
        List<Object> facts = new ArrayList<Object>();
        facts.add(qRules);
        facts.add(msg);
        facts.add(adecodedTokenMap);
        facts.add(auserRoles);
        User currentUser = new User("user1", "User1", ruleGroup, "admin");
        usersSession.put("user", currentUser);
        facts.add(currentUser);
        Map<String, String> keyvalue = new HashMap<String, String>();
        keyvalue.put("token", token);
        if (!"GPS".equals(msgType)) {
            System.out.println("FIRE RULES (" + ruleGroup + ") " + msgType);
        }
        // String ruleGroupRealm = realm + (StringUtils.isBlank(ruleGroup)?"":(":"+ruleGroup));
        try {
            RulesLoader.executeStatefull(ruleGroup, eventBus, globals, facts, keyvalue);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        future.complete();
    }, res -> {
        if (res.succeeded()) {
        // System.out.println("Processed "+msgType+" Msg");
        }
    });
}
Also used : User(life.genny.qwanda.entity.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QRules(life.genny.rules.QRules) Tuple2(io.vavr.Tuple2) JsonObject(io.vertx.core.json.JsonObject) HashSet(java.util.HashSet)

Example 2 with User

use of life.genny.qwanda.entity.User in project rulesservice by genny-project.

the class EBCHandlers method processMsg.

public static void processMsg(final String msgType, String ruleGroup, final Object msg, final EventBus eventBus, final String token) {
    Vertx.currentContext().owner().executeBlocking(future -> {
        Map<String, Object> adecodedTokenMap = RulesLoader.getDecodedTokenMap(token);
        Set<String> auserRoles = KeycloakUtils.getRoleSet(adecodedTokenMap.get("realm_access").toString());
        User userInSession = usersSession.get(adecodedTokenMap.get("preferred_username").toString());
        String preferredUName = adecodedTokenMap.get("preferred_username").toString();
        String fullName = adecodedTokenMap.get("name").toString();
        String realm = adecodedTokenMap.get("realm").toString();
        String accessRoles = adecodedTokenMap.get("realm_access").toString();
        QRules qRules = new QRules(eventBus, token, adecodedTokenMap);
        qRules.set("realm", realm);
        List<Tuple2<String, Object>> globals = RulesLoader.getStandardGlobals();
        List<Object> facts = new ArrayList<Object>();
        facts.add(qRules);
        facts.add(msg);
        facts.add(adecodedTokenMap);
        facts.add(auserRoles);
        if (userInSession != null)
            facts.add(usersSession.get(preferredUName));
        else {
            User currentUser = new User(preferredUName, fullName, realm, accessRoles);
            usersSession.put(adecodedTokenMap.get("preferred_username").toString(), currentUser);
            facts.add(currentUser);
        }
        Map<String, String> keyvalue = new HashMap<String, String>();
        keyvalue.put("token", token);
        if (!"GPS".equals(msgType)) {
            System.out.println("FIRE RULES (" + realm + ") " + msgType);
        }
        // String ruleGroupRealm = realm + (StringUtils.isBlank(ruleGroup)?"":(":"+ruleGroup));
        try {
            RulesLoader.executeStatefull(realm, eventBus, globals, facts, keyvalue);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        future.complete();
    }, res -> {
        if (res.succeeded()) {
        // System.out.println("Processed "+msgType+" Msg");
        }
    });
}
Also used : User(life.genny.qwanda.entity.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QRules(life.genny.rules.QRules) Tuple2(io.vavr.Tuple2) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

Tuple2 (io.vavr.Tuple2)2 JsonObject (io.vertx.core.json.JsonObject)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 User (life.genny.qwanda.entity.User)2 QRules (life.genny.rules.QRules)2 HashSet (java.util.HashSet)1