Search in sources :

Example 41 with CfClasscontent

use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.

the class ClownfishLoginServlet method processRequest.

protected void processRequest(HttpServletRequest request, HttpServletResponse response) {
    String inst_klasse;
    String inst_identifier;
    String inst_passwordField;
    String salt;
    String inst_clearTextPw;
    String inst_identifierField;
    boolean success = false;
    Map<String, String[]> parameters = request.getParameterMap();
    parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("class") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
        klasse = values[0];
    });
    parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("clearPw") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
        clearPw = values[0];
    });
    parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("idField") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
        id_field = values[0];
    });
    parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("id") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
        id = values[0];
    });
    parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("pwField") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
        pw_field = values[0];
    });
    inst_klasse = klasse;
    inst_identifier = id;
    inst_passwordField = pw_field;
    inst_identifierField = id_field;
    inst_clearTextPw = clearPw;
    CfClass cfclass = cfclassService.findByName(inst_klasse);
    List<CfClasscontent> classcontentList = cfclasscontentService.findByClassref(cfclass);
    CfAttribut attributField = cfattributService.findByNameAndClassref(inst_identifierField, cfclass);
    CfAttribut attributPassword = cfattributService.findByNameAndClassref(inst_passwordField, cfclass);
    for (CfClasscontent classcontent : classcontentList) {
        CfAttributcontent attributContent = cfattributcontentService.findByAttributrefAndClasscontentref(attributField, classcontent);
        if (attributContent.getContentString().equals(inst_identifier)) {
            long cref = attributContent.getClasscontentref().getId();
            for (CfClasscontent classcontent1 : classcontentList) {
                CfAttributcontent attributContent1 = cfattributcontentService.findByAttributrefAndClasscontentref(attributPassword, classcontent1);
                salt = attributContent1.getSalt();
                if (null != salt) {
                    String test = PasswordUtil.generateSecurePassword(inst_clearTextPw, salt);
                    if ((attributContent1.getContentString().compareTo(test) == 0) && (attributContent1.getClasscontentref().getId() == cref)) {
                        success = PasswordUtil.verifyUserPassword(inst_clearTextPw, PasswordUtil.generateSecurePassword(inst_clearTextPw, salt), salt);
                        if (success) {
                            break;
                        }
                    }
                }
            }
        }
    }
    try (PrintWriter out = response.getWriter()) {
        out.print(success);
    } catch (IOException ex) {
    // LOGGER.error(ex.getMessage());
    }
}
Also used : PrintWriter(java.io.PrintWriter) CfClasscontentService(io.clownfish.clownfish.serviceinterface.CfClasscontentService) CfAttribut(io.clownfish.clownfish.dbentities.CfAttribut) HttpServlet(javax.servlet.http.HttpServlet) ServletException(javax.servlet.ServletException) HttpServletResponse(javax.servlet.http.HttpServletResponse) PasswordUtil(io.clownfish.clownfish.utils.PasswordUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfClass(io.clownfish.clownfish.dbentities.CfClass) WebServlet(javax.servlet.annotation.WebServlet) List(java.util.List) HttpServletRequest(javax.servlet.http.HttpServletRequest) Component(org.springframework.stereotype.Component) CfClassService(io.clownfish.clownfish.serviceinterface.CfClassService) CfAttributcontentService(io.clownfish.clownfish.serviceinterface.CfAttributcontentService) Map(java.util.Map) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) CfAttributService(io.clownfish.clownfish.serviceinterface.CfAttributService) CfClass(io.clownfish.clownfish.dbentities.CfClass) CfAttribut(io.clownfish.clownfish.dbentities.CfAttribut) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) IOException(java.io.IOException) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) PrintWriter(java.io.PrintWriter)

Example 42 with CfClasscontent

use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.

the class Searcher method addClasscontentMap.

private void addClasscontentMap(long classcontentref, HashMap searchclasscontentmap) {
    // Search in classes and put it via template to the output
    try {
        CfClasscontent findclasscontent = cfclasscontentservice.findById(classcontentref);
        CfClass findclass = cfclassservice.findById(findclasscontent.getClassref().getId());
        if (findclass.isSearchrelevant()) {
            Map attributmap = classutil.getattributmap(findclasscontent);
            if (searchclasscontentmap.containsKey(findclass.getName())) {
                ArrayList searchclassarray = (ArrayList) searchclasscontentmap.get(findclass.getName());
                if (!searchclassarray.contains(attributmap)) {
                    searchclassarray.add(attributmap);
                    searchclasscontentmap.put(findclass.getName(), searchclassarray);
                }
            } else {
                ArrayList searchclassarray = new ArrayList<>();
                searchclassarray.add(attributmap);
                searchclasscontentmap.put(findclass.getName(), searchclassarray);
            }
        }
    } catch (Exception ex) {
        LOGGER.warn("LUCENE SEARCHER CONTENT NOT FOUND: " + classcontentref);
    }
}
Also used : CfClass(io.clownfish.clownfish.dbentities.CfClass) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException)

Example 43 with CfClasscontent

use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.

the class RestContent method updateContent.

private RestContentParameter updateContent(RestContentParameter ucp) {
    try {
        String token = ucp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = ucp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                CfClass clazz = cfclassService.findByName(ucp.getClassname());
                try {
                    CfClasscontent classcontent = cfclasscontentService.findByName(ucp.getContentname());
                    List<CfAttributcontent> attributcontentlist = cfattributcontentService.findByClasscontentref(classcontent);
                    for (CfAttributcontent attributcontent : attributcontentlist) {
                        CfAttribut attribut = attributcontent.getAttributref();
                        // Check, if attribut exists in attributmap
                        if (ucp.getAttributmap().containsKey(attribut.getName())) {
                            contentUtil.setAttributValue(attributcontent, ucp.getAttributmap().get(attribut.getName()));
                            cfattributcontentService.edit(attributcontent);
                            if (ucp.isIndexing()) {
                                contentUtil.indexContent();
                            }
                            ucp.setReturncode("OK");
                        }
                    }
                    hibernateUtil.updateContent(classcontent);
                } catch (javax.persistence.NoResultException ex) {
                    ucp.setReturncode("Classcontent not found");
                }
            } else {
                ucp.setReturncode("Wrong API KEY");
            }
        } else {
            ucp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        ucp.setReturncode("NoResultException");
    }
    return ucp;
}
Also used : CfClass(io.clownfish.clownfish.dbentities.CfClass) CfAttributcontent(io.clownfish.clownfish.dbentities.CfAttributcontent) CfAttribut(io.clownfish.clownfish.dbentities.CfAttribut) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent)

Example 44 with CfClasscontent

use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.

the class RestListcontent method insertListcontent.

private RestListcontentParameter insertListcontent(RestListcontentParameter ilcp) {
    try {
        String token = ilcp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = ilcp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                try {
                    CfList list = cflistService.findByName(ilcp.getListname());
                    CfClasscontent classcontent = cfclasscontentService.findByName(ilcp.getClasscontentname());
                    CfListcontent listcontent = new CfListcontent();
                    CfListcontentPK cfListcontentPK = new CfListcontentPK();
                    cfListcontentPK.setListref(list.getId());
                    cfListcontentPK.setClasscontentref(classcontent.getId());
                    listcontent.setCfListcontentPK(cfListcontentPK);
                    cflistcontentService.create(listcontent);
                    hibernateutil.updateRelation(list);
                    ilcp.setReturncode("OK");
                } catch (Exception ex) {
                    ilcp.setReturncode("Exception");
                }
            } else {
                ilcp.setReturncode("Wrong API KEY");
            }
        } else {
            ilcp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        ilcp.setReturncode("NoResultException");
    }
    return ilcp;
}
Also used : CfList(io.clownfish.clownfish.dbentities.CfList) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfListcontentPK(io.clownfish.clownfish.dbentities.CfListcontentPK)

Example 45 with CfClasscontent

use of io.clownfish.clownfish.dbentities.CfClasscontent in project Clownfish by rawdog71.

the class RestListcontent method deleteListcontent.

private RestListcontentParameter deleteListcontent(RestListcontentParameter ilcp) {
    try {
        String token = ilcp.getToken();
        if (authtokenlist.checkValidToken(token)) {
            String apikey = ilcp.getApikey();
            if (apikeyutil.checkApiKey(apikey, "RestService")) {
                try {
                    ilcp.setReturncode("");
                    CfList list = cflistService.findByName(ilcp.getListname());
                    CfClasscontent classcontent = cfclasscontentService.findByName(ilcp.getClasscontentname());
                    List<CfListcontent> listcontentList = cflistcontentService.findByListref(list.getId());
                    for (CfListcontent listcontent : listcontentList) {
                        if (listcontent.getCfListcontentPK().getClasscontentref() == classcontent.getId()) {
                            cflistcontentService.delete(listcontent);
                            ilcp.setReturncode("OK");
                        }
                    }
                } catch (javax.persistence.EntityExistsException ex) {
                    ilcp.setReturncode("EntityExistsException");
                }
            } else {
                ilcp.setReturncode("Wrong API KEY");
            }
        } else {
            ilcp.setReturncode("Invalid token");
        }
    } catch (javax.persistence.NoResultException ex) {
        ilcp.setReturncode("NoResultException");
    }
    return ilcp;
}
Also used : CfList(io.clownfish.clownfish.dbentities.CfList) CfListcontent(io.clownfish.clownfish.dbentities.CfListcontent) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent)

Aggregations

CfClasscontent (io.clownfish.clownfish.dbentities.CfClasscontent)45 CfAttributcontent (io.clownfish.clownfish.dbentities.CfAttributcontent)24 CfListcontent (io.clownfish.clownfish.dbentities.CfListcontent)22 CfList (io.clownfish.clownfish.dbentities.CfList)21 Map (java.util.Map)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 Gson (com.google.gson.Gson)13 CfClass (io.clownfish.clownfish.dbentities.CfClass)13 IOException (java.io.IOException)13 List (java.util.List)12 CfAttributService (io.clownfish.clownfish.serviceinterface.CfAttributService)9 CfAttributcontentService (io.clownfish.clownfish.serviceinterface.CfAttributcontentService)9 CfClassService (io.clownfish.clownfish.serviceinterface.CfClassService)9 CfClasscontentService (io.clownfish.clownfish.serviceinterface.CfClasscontentService)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 CfAttributetypeService (io.clownfish.clownfish.serviceinterface.CfAttributetypeService)8 CfListService (io.clownfish.clownfish.serviceinterface.CfListService)8 Session (org.hibernate.Session)8 Logger (org.slf4j.Logger)8