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();
}
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);
}
}
}
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";
}
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;
}
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());
}
Aggregations