Java Code Examples for javax.ejb.SessionContext#setRollbackOnly()

The following examples show how to use javax.ejb.SessionContext#setRollbackOnly() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PermissionCheck.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the provided {@link Organization} is the owner of the provided
 * {@link UdaDefinition} and throws an
 * {@link OperationNotPermittedException} if this is not the case.
 * 
 * @param def
 *            the {@link UdaDefinition} to check the ownership for
 * @param org
 *            the {@link Organization} to check if it is the owner
 * @param logger
 *            the optional logger - if not <code>null</code> it logs the
 *            created exception as warning to the system log
 * @param context
 *            if not <code>null</code>,
 *            {@link SessionContext#setRollbackOnly()} will called.
 * @throws OperationNotPermittedException
 */
public static void owns(UdaDefinition def, Organization org,
        Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {
    if (def.getOrganization() != org) {
        String message = String
                .format("Organization '%s' tried to access uda definition '%s' that is owned by a different organization",
                        org.getOrganizationId(), Long.valueOf(def.getKey()));
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(
                    Log4jLogger.SYSTEM_LOG,
                    e,
                    LogMessageIdentifier.WARN_INSUFFICIENT_AUTH_BY_UDA_DEFINITION_ACCESS,
                    org.getOrganizationId(), String.valueOf(def.getKey()));
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 2
Source File: PermissionCheck.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the provided supplier {@link Organization} is supplier of the
 * provided customer {@link Organization} and throws an
 * {@link OperationNotPermittedException} if this is not the case.
 * 
 * @param sup
 *            the {@link Organization} to check if it is supplier of the
 *            passed customer {@link Organization}
 * @param cust
 *            the {@link Organization} to check if it is customer of the
 *            passed supplier {@link Organization}
 * @param logger
 *            the optional logger - if not <code>null</code> it logs the
 *            created exception as warning to the system log
 * @param context
 *            if not <code>null</code>,
 *            {@link SessionContext#setRollbackOnly()} will called.
 * @throws OperationNotPermittedException
 */
public static void supplierOfCustomer(Organization sup, Organization cust,
        Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {
    List<Organization> customers = sup.getCustomersOfSupplier();
    if (!customers.contains(cust)) {
        String message = String.format(
                "Organization '%s' is not supplier of customer '%s'",
                sup.getOrganizationId(), cust.getOrganizationId());
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(Log4jLogger.SYSTEM_LOG, e,
                    LogMessageIdentifier.WARN_NO_SUPPLIER_OF_CUSTOMER,
                    sup.getOrganizationId(), cust.getOrganizationId());
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 3
Source File: PermissionCheck.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the provided reseller {@link Organization} is a broker of the
 * provided customer {@link Organization} and throws an
 * {@link OperationNotPermittedException} if this is not the case.
 * 
 * @param broker
 *            the {@link Organization} to check if it is a broker of the
 *            passed customer {@link Organization}
 * @param cust
 *            the {@link Organization} to check if it is customer of the
 *            passed broker {@link Organization}
 * @param logger
 *            the optional logger - if not <code>null</code> it logs the
 *            created exception as warning to the system log
 * @param context
 *            if not <code>null</code>,
 *            {@link SessionContext#setRollbackOnly()} will called.
 * @throws OperationNotPermittedException
 */
public static void brokerOfCustomer(Organization broker, Organization cust,
        Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {
    List<Organization> customers = broker.getCustomersOfBroker();
    if (!customers.contains(cust)) {
        String message = String.format(
                "Organization '%s' is not broker of customer '%s'",
                broker.getOrganizationId(), cust.getOrganizationId());
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(Log4jLogger.SYSTEM_LOG, e,
                    LogMessageIdentifier.WARN_NO_BROKER_OF_CUSTOMER,
                    broker.getOrganizationId(), cust.getOrganizationId());
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 4
Source File: PermissionCheck.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the provided reseller {@link Organization} is reseller of the
 * provided customer {@link Organization} and throws an
 * {@link OperationNotPermittedException} if this is not the case.
 * 
 * @param reseller
 *            the {@link Organization} to check if it is reseller of the
 *            passed customer {@link Organization}
 * @param cust
 *            the {@link Organization} to check if it is customer of the
 *            passed reseller {@link Organization}
 * @param logger
 *            the optional logger - if not <code>null</code> it logs the
 *            created exception as warning to the system log
 * @param context
 *            if not <code>null</code>,
 *            {@link SessionContext#setRollbackOnly()} will called.
 * @throws OperationNotPermittedException
 */
public static void resellerOfCustomer(Organization reseller,
        Organization cust, Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {
    List<Organization> customers = reseller.getCustomersOfReseller();
    if (!customers.contains(cust)) {
        String message = String.format(
                "Organization '%s' is not reseller of customer '%s'",
                reseller.getOrganizationId(), cust.getOrganizationId());
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(Log4jLogger.SYSTEM_LOG, e,
                    LogMessageIdentifier.WARN_NO_RESELLER_OF_CUSTOMER,
                    reseller.getOrganizationId(), cust.getOrganizationId());
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 5
Source File: PermissionCheck.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the provided {@link Organization} is the owner of the provided
 * {@link Marketplace} and throws an {@link OperationNotPermittedException}
 * if this is not the case.
 * 
 * @param mp
 *            the {@link Marketplace} to check the ownership for
 * @param org
 *            the {@link Organization} to check if it is the owner
 * @param logger
 *            the optional logger - if not <code>null</code> it logs the
 *            created exception as warning to the system log
 * @param context
 *            if not <code>null</code>,
 *            {@link SessionContext#setRollbackOnly()} will called.
 * @throws OperationNotPermittedException
 */
public static void owns(Marketplace mp, Organization org,
        Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {
    if (mp.getOrganization() != org) {
        String message = String
                .format("Organization '%s' tried to access marketplace '%s' that is owned by a different organization",
                        org.getOrganizationId(), Long.valueOf(mp.getKey()));
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(
                    Log4jLogger.SYSTEM_LOG,
                    e,
                    LogMessageIdentifier.WARN_INSUFFICIENT_AUTH_BY_MARKETPLACE_ACCESS,
                    org.getOrganizationId(), String.valueOf(mp.getKey()));
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 6
Source File: PermissionCheck.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the provided {@link Organization} is the owner of the provided
 * {@link Product} and throws an {@link OperationNotPermittedException} if
 * this is not the case.
 * 
 * @param prod
 *            the {@link Product} to check the ownership for
 * @param org
 *            the {@link Organization} to check if it is the owner
 * @param logger
 *            the optional logger - if not <code>null</code> it logs the
 *            created exception as warning to the system log
 * @param context
 *            if not <code>null</code>,
 *            {@link SessionContext#setRollbackOnly()} will called.
 * @throws OperationNotPermittedException
 */
public static void owns(Product prod, Organization org, Log4jLogger logger,
        SessionContext context) throws OperationNotPermittedException {
    if (prod.getVendor() != org) {
        String message = String
                .format("Organization '%s' tried to access service '%s' that is owned by a different organization",
                        org.getOrganizationId(),
                        Long.valueOf(prod.getKey()));
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(
                    Log4jLogger.SYSTEM_LOG,
                    e,
                    LogMessageIdentifier.WARN_INSUFFICIENT_AUTH_BY_SERVICE_ACCESS,
                    org.getOrganizationId(), String.valueOf(prod.getKey()));
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 7
Source File: PermissionCheck.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the provided {@link Organization} is the owner of the provided
 * {@link TechnicalProduct} and throws an
 * {@link OperationNotPermittedException} if this is not the case.
 * 
 * @param tp
 *            the {@link TechnicalProduct} to check the ownership for
 * @param org
 *            the {@link Organization} to check if it is the owner
 * @param logger
 *            the optional logger - if not <code>null</code> it logs the
 *            created exception as warning to the system log
 * @param context
 *            if not <code>null</code>,
 *            {@link SessionContext#setRollbackOnly()} will called.
 * @throws OperationNotPermittedException
 */
public static void owns(TechnicalProduct tp, Organization org,
        Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {
    if (tp.getOrganization() != org) {
        String message = String
                .format("Organization '%s' tried to access technical service '%s' that is owned by a different organization",
                        org.getOrganizationId(), Long.valueOf(tp.getKey()));
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(
                    Log4jLogger.SYSTEM_LOG,
                    e,
                    LogMessageIdentifier.WARN_INSUFFICIENT_AUTH_BY_TECH_SERVICE_ACCESS,
                    org.getOrganizationId(), String.valueOf(tp.getKey()));
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 8
Source File: PermissionCheck.java    From development with Apache License 2.0 6 votes vote down vote up
public static void same(Organization org1, Organization org2,
        Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {
    if (org1 != org2) {
        String message = String
                .format("Organization '%s' tried to access organization '%s' but is not allowed to.",
                        org1.getOrganizationId(), org2.getOrganizationId());
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(
                    Log4jLogger.SYSTEM_LOG,
                    e,
                    LogMessageIdentifier.WARN_INSUFFICIENT_AUTH_BY_ORGANIZATION_ACCESS,
                    org1.getOrganizationId(), org2.getOrganizationId());
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 9
Source File: PermissionCheck.java    From development with Apache License 2.0 5 votes vote down vote up
public static void sameUdaTarget(Organization caller, Uda uda,
        long targetKey, Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {
    if (uda.getTargetObjectKey() != targetKey) {
        String message = String
                .format("Organization '%s' tried to change uda '%s' from target '%s' to target '%s'.",
                        caller.getOrganizationId(),
                        Long.toString(uda.getKey()),
                        Long.toString(uda.getTargetObjectKey()),
                        Long.toString(targetKey));
        OperationNotPermittedException e = new OperationNotPermittedException(
                message);
        if (logger != null) {
            logger.logWarn(
                    Log4jLogger.SYSTEM_LOG,
                    e,
                    LogMessageIdentifier.WARN_UNPERMITTED_UDA_TARGET_SWITCH,
                    caller.getOrganizationId(),
                    Long.toString(uda.getKey()),
                    Long.toString(uda.getTargetObjectKey()),
                    Long.toString(targetKey));
        }
        if (context != null) {
            context.setRollbackOnly();
        }
        throw e;
    }
}
 
Example 10
Source File: PermissionCheck.java    From development with Apache License 2.0 4 votes vote down vote up
/**
 * Checks if the provided supplier {@link Organization} is allowed to
 * publish services on the provided {@link Marketplace} For non-opened
 * marketplaces a {@link MarketplaceToOrganization} connecting both with
 * publishing access granted must exist. If not, a
 * {@link OperationNotPermittedException} will be thrown. For open
 * marketplaces it is allowed to publish if a
 * {@link MarketplaceToOrganization} with publish access denied does not
 * exist. If it exists, a {@link OperationNotPermittedException} will be
 * thrown.
 * 
 * @param mp
 *            the {@link Marketplace} to publish on
 * @param sup
 *            the supplier {@link Organization} that wants to publish
 * @param logger
 *            the optional logger - if not <code>null</code> it logs the
 *            created exception as warning to the system log
 * @param context
 *            if not <code>null</code>,
 *            {@link SessionContext#setRollbackOnly()} will called.
 * @throws OperationNotPermittedException
 *             in case the supplier is not allowed to publish services on
 *             the provided marketplace
 */
public static void canPublish(Marketplace mp, Organization sup,
        Log4jLogger logger, SessionContext context)
        throws OperationNotPermittedException {

    List<MarketplaceToOrganization> list = mp
            .getMarketplaceToOrganizations();
    boolean denied = false;
    for (MarketplaceToOrganization mto : list) {
        if (sup == mto.getOrganization()
                && PublishingAccess.PUBLISHING_ACCESS_GRANTED.equals(mto
                        .getPublishingAccess())) {
            return;
        }
        if (sup == mto.getOrganization()
                && PublishingAccess.PUBLISHING_ACCESS_DENIED.equals(mto
                        .getPublishingAccess())) {
            denied = true;
            break;
        }
    }
    if (!denied && mp.isOpen()) {
        return;
    }
    String message = String
            .format("Organization '%s' tried to publish on marketplace '%s' but is not allowed.",
                    sup.getOrganizationId(), mp.getMarketplaceId());
    PublishingToMarketplaceNotPermittedException e = new PublishingToMarketplaceNotPermittedException(
            message);
    if (logger != null) {
        logger.logWarn(
                Log4jLogger.SYSTEM_LOG,
                e,
                LogMessageIdentifier.WARN_INSUFFICIENT_AUTH_BY_PUBLISH_ON_MARKETPLACE,
                sup.getOrganizationId(), mp.getMarketplaceId());
    }
    if (context != null) {
        context.setRollbackOnly();
    }
    throw e;
}