Search in sources :

Example 61 with Delegator

use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.

the class CertificateServices method importIssuerCertificate.

public static Map<String, Object> importIssuerCertificate(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    String certString = (String) context.get("certString");
    String componentName = (String) context.get("componentName");
    String keystoreName = (String) context.get("keystoreName");
    String alias = (String) context.get("alias");
    String importIssuer = (String) context.get("importIssuer");
    // load the keystore
    KeyStore ks;
    try {
        ks = KeyStoreUtil.getComponentKeyStore(componentName, keystoreName);
    } catch (Exception e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // read the certificate
    X509Certificate cert;
    try {
        cert = (X509Certificate) KeyStoreUtil.pemToCert(certString);
    } catch (CertificateException e) {
        return ServiceUtil.returnError(e.getMessage());
    } catch (IOException e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // store the cert
    try {
        ks.setCertificateEntry(alias, cert);
    } catch (Exception e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // save the keystore
    try {
        KeyStoreUtil.storeComponentKeyStore(componentName, keystoreName, ks);
    } catch (Exception e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // set the issuer provision
    Map<String, String> x500Map = KeyStoreUtil.getCertX500Map(cert);
    if (importIssuer != null && "Y".equalsIgnoreCase(importIssuer)) {
        GenericValue provision = delegator.makeValue("X509IssuerProvision");
        provision.set("commonName", x500Map.get("CN"));
        provision.set("organizationalUnit", x500Map.get("OU"));
        provision.set("organizationName", x500Map.get("O"));
        provision.set("cityLocality", x500Map.get("L"));
        provision.set("stateProvince", x500Map.get("ST"));
        provision.set("country", x500Map.get("C"));
        provision.set("serialNumber", cert.getSerialNumber().toString(16));
        try {
            delegator.createSetNextSeqId(provision);
        } catch (GenericEntityException e) {
            return ServiceUtil.returnError(e.getMessage());
        }
    }
    return ServiceUtil.returnSuccess();
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate)

Example 62 with Delegator

use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.

the class LoginEvents method setUsername.

public static void setUsername(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
    HttpSession session = request.getSession();
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    String domain = EntityUtilProperties.getPropertyValue("url", "cookie.domain", delegator);
    // first try to get the username from the cookie
    synchronized (session) {
        if (UtilValidate.isEmpty(getUsername(request))) {
            // create the cookie and send it back
            String usernameParam = URLEncoder.encode(request.getParameter("USERNAME"), "UTF-8");
            Cookie cookie = new Cookie(usernameCookieName, usernameParam);
            cookie.setMaxAge(60 * 60 * 24 * 365);
            cookie.setPath("/");
            cookie.setDomain(domain);
            cookie.setSecure(true);
            cookie.setHttpOnly(true);
            response.addCookie(cookie);
        }
    }
}
Also used : Cookie(javax.servlet.http.Cookie) Delegator(org.apache.ofbiz.entity.Delegator) GenericDelegator(org.apache.ofbiz.entity.GenericDelegator) HttpSession(javax.servlet.http.HttpSession)

Example 63 with Delegator

use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.

the class LoginEvents method saveEntryParams.

/**
 * Save USERNAME and PASSWORD for use by auth pages even if we start in non-auth pages.
 *
 * @param request The HTTP request object for the current JSP or Servlet request.
 * @param response The HTTP response object for the current JSP or Servlet request.
 * @return String
 */
public static String saveEntryParams(HttpServletRequest request, HttpServletResponse response) {
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
    HttpSession session = request.getSession();
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    // save entry login parameters if we don't have a valid login object
    if (userLogin == null) {
        String username = request.getParameter("USERNAME");
        String password = request.getParameter("PASSWORD");
        if ((username != null) && ("true".equalsIgnoreCase(EntityUtilProperties.getPropertyValue("security", "username.lowercase", delegator)))) {
            username = username.toLowerCase(Locale.getDefault());
        }
        if ((password != null) && ("true".equalsIgnoreCase(EntityUtilProperties.getPropertyValue("security", "password.lowercase", delegator)))) {
            password = password.toLowerCase(Locale.getDefault());
        }
        // save parameters into the session - so they can be used later, if needed
        if (username != null) {
            session.setAttribute("USERNAME", username);
        }
        if (password != null) {
            session.setAttribute("PASSWORD", password);
        }
    } else {
        // if the login object is valid, remove attributes
        session.removeAttribute("USERNAME");
        session.removeAttribute("PASSWORD");
    }
    return "success";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericDelegator(org.apache.ofbiz.entity.GenericDelegator) HttpSession(javax.servlet.http.HttpSession)

Example 64 with Delegator

use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.

the class ICalConverter method storePartyAssignments.

protected static ResponseProperties storePartyAssignments(String workEffortId, Component component, Map<String, Object> context) {
    ResponseProperties responseProps = null;
    Map<String, Object> serviceMap = new HashMap<>();
    List<Property> partyList = new LinkedList<>();
    partyList.addAll(UtilGenerics.checkList(component.getProperties("ATTENDEE"), Property.class));
    partyList.addAll(UtilGenerics.checkList(component.getProperties("CONTACT"), Property.class));
    partyList.addAll(UtilGenerics.checkList(component.getProperties("ORGANIZER"), Property.class));
    for (Property property : partyList) {
        String partyId = fromXParameter(property.getParameters(), partyIdXParamName);
        if (partyId == null) {
            serviceMap.clear();
            String address = property.getValue();
            if (address.toUpperCase(Locale.getDefault()).startsWith("MAILTO:")) {
                address = address.substring(7);
            }
            serviceMap.put("address", address);
            Map<String, Object> result = invokeService("findPartyFromEmailAddress", serviceMap, context);
            partyId = (String) result.get("partyId");
            if (partyId == null) {
                continue;
            }
            replaceParameter(property.getParameters(), toXParameter(partyIdXParamName, partyId));
        }
        serviceMap.clear();
        serviceMap.put("workEffortId", workEffortId);
        serviceMap.put("partyId", partyId);
        serviceMap.put("roleTypeId", fromRoleMap.get(property.getName()));
        Delegator delegator = (Delegator) context.get("delegator");
        List<GenericValue> assignments = null;
        try {
            assignments = EntityQuery.use(delegator).from("WorkEffortPartyAssignment").where(serviceMap).filterByDate().queryList();
            if (assignments.size() == 0) {
                serviceMap.put("statusId", "PRTYASGN_OFFERED");
                serviceMap.put("fromDate", new Timestamp(System.currentTimeMillis()));
                invokeService("assignPartyToWorkEffort", serviceMap, context);
            }
        } catch (GenericEntityException e) {
            responseProps = ICalWorker.createPartialContentResponse(e.getMessage());
            break;
        }
    }
    return responseProps;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) HashMap(java.util.HashMap) Timestamp(java.sql.Timestamp) LinkedList(java.util.LinkedList) Delegator(org.apache.ofbiz.entity.Delegator) ResponseProperties(org.apache.ofbiz.workeffort.workeffort.ICalWorker.ResponseProperties) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property)

Example 65 with Delegator

use of org.apache.ofbiz.entity.Delegator in project ofbiz-framework by apache.

the class ICalConverter method getICalendar.

/**
 * Returns a calendar derived from a Work Effort calendar publish point.
 * @param workEffortId ID of a work effort with <code>workEffortTypeId</code> equal to
 * <code>PUBLISH_PROPS</code>.
 * @param context The conversion context
 * @return An iCalendar as a <code>String</code>, or <code>null</code>
 * if <code>workEffortId</code> is invalid.
 * @throws GenericEntityException
 */
public static ResponseProperties getICalendar(String workEffortId, Map<String, Object> context) throws GenericEntityException {
    Delegator delegator = (Delegator) context.get("delegator");
    GenericValue publishProperties = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne();
    if (!isCalendarPublished(publishProperties)) {
        Debug.logInfo("WorkEffort calendar is not published: " + workEffortId, module);
        return ICalWorker.createNotFoundResponse(null);
    }
    if (!"WES_PUBLIC".equals(publishProperties.get("scopeEnumId"))) {
        if (context.get("userLogin") == null) {
            return ICalWorker.createNotAuthorizedResponse(null);
        }
        if (!hasPermission(workEffortId, "VIEW", context)) {
            return ICalWorker.createForbiddenResponse(null);
        }
    }
    Calendar calendar = makeCalendar(publishProperties, context);
    ComponentList components = calendar.getComponents();
    List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
    if (workEfforts != null) {
        for (GenericValue workEffort : workEfforts) {
            ResponseProperties responseProps = toCalendarComponent(components, workEffort, context);
            if (responseProps != null) {
                return responseProps;
            }
        }
    }
    if (Debug.verboseOn()) {
        try {
            calendar.validate(true);
            Debug.logVerbose("iCalendar passes validation", module);
        } catch (ValidationException e) {
            if (Debug.verboseOn())
                Debug.logVerbose("iCalendar fails validation: " + e, module);
        }
    }
    return ICalWorker.createOkResponse(calendar.toString());
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) ValidationException(net.fortuna.ical4j.model.ValidationException) Delegator(org.apache.ofbiz.entity.Delegator) ResponseProperties(org.apache.ofbiz.workeffort.workeffort.ICalWorker.ResponseProperties) Calendar(net.fortuna.ical4j.model.Calendar) ComponentList(net.fortuna.ical4j.model.ComponentList)

Aggregations

Delegator (org.apache.ofbiz.entity.Delegator)869 GenericValue (org.apache.ofbiz.entity.GenericValue)721 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)611 Locale (java.util.Locale)485 HashMap (java.util.HashMap)328 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)324 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)278 BigDecimal (java.math.BigDecimal)205 LinkedList (java.util.LinkedList)166 Timestamp (java.sql.Timestamp)163 GeneralException (org.apache.ofbiz.base.util.GeneralException)130 IOException (java.io.IOException)117 Map (java.util.Map)113 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)61 Security (org.apache.ofbiz.security.Security)60 HttpSession (javax.servlet.http.HttpSession)59 Properties (java.util.Properties)37 UtilProperties (org.apache.ofbiz.base.util.UtilProperties)37 EntityUtilProperties (org.apache.ofbiz.entity.util.EntityUtilProperties)35 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)33