Example usage for javax.ejb TransactionAttributeType SUPPORTS

List of usage examples for javax.ejb TransactionAttributeType SUPPORTS

Introduction

In this page you can find the example usage for javax.ejb TransactionAttributeType SUPPORTS.

Prototype

TransactionAttributeType SUPPORTS

To view the source code for javax.ejb TransactionAttributeType SUPPORTS.

Click Source Link

Document

If the client calls with a transaction context, the container performs the same steps as described in the REQUIRED case.

Usage

From source file:org.cesecore.configuration.GlobalConfigurationSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override/*from  w  w w .  j  av a2 s .c o m*/
public Properties getAllProperties(AuthenticationToken admin, String configID)
        throws AuthorizationDeniedException {
    if (StringUtils.equals(AvailableExtendedKeyUsagesConfiguration.CONFIGURATION_ID, configID)
            && !accessSession.isAuthorized(admin, StandardRules.EKUCONFIGURATION_EDIT.resource())) {
        String msg = intres.getLocalizedMessage("authorization.notuathorizedtoresource",
                StandardRules.EKUCONFIGURATION_EDIT.resource(), null);
        Map<String, Object> details = new LinkedHashMap<String, Object>();
        details.put("msg", msg);
        auditSession.log(EventTypes.ACCESS_CONTROL, EventStatus.FAILURE, ModuleTypes.CA, ServiceTypes.CORE,
                admin.toString(), null, null, null, details);
        throw new AuthorizationDeniedException(msg);
    } else if (StringUtils.equals(AvailableCustomCertificateExtensionsConfiguration.CONFIGURATION_ID, configID)
            && !accessSession.isAuthorized(admin,
                    StandardRules.CUSTOMCERTEXTENSIONCONFIGURATION_EDIT.resource())) {
        String msg = intres.getLocalizedMessage("authorization.notuathorizedtoresource",
                StandardRules.CUSTOMCERTEXTENSIONCONFIGURATION_EDIT.resource(), null);
        Map<String, Object> details = new LinkedHashMap<String, Object>();
        details.put("msg", msg);
        auditSession.log(EventTypes.ACCESS_CONTROL, EventStatus.FAILURE, ModuleTypes.CA, ServiceTypes.CORE,
                admin.toString(), null, null, null, details);
        throw new AuthorizationDeniedException(msg);
    } else if (!accessSession.isAuthorized(admin, StandardRules.SYSTEMCONFIGURATION_EDIT.resource())) {
        String msg = intres.getLocalizedMessage("authorization.notuathorizedtoresource",
                StandardRules.SYSTEMCONFIGURATION_EDIT.resource(), null);
        Map<String, Object> details = new LinkedHashMap<String, Object>();
        details.put("msg", msg);
        auditSession.log(EventTypes.ACCESS_CONTROL, EventStatus.FAILURE, ModuleTypes.CA, ServiceTypes.CORE,
                admin.toString(), null, null, null, details);
        throw new AuthorizationDeniedException(msg);
    }

    return GlobalConfigurationCacheHolder.INSTANCE.getAllProperties(configID);
}

From source file:org.cesecore.configuration.GlobalConfigurationSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override
public Set<String> getIds() {
    return GlobalConfigurationCacheHolder.INSTANCE.getIds();
}

From source file:org.cesecore.configuration.GlobalConfigurationSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override//from ww  w .  j av a  2s .  c  om
public ConfigurationBase getCachedConfiguration(String configID) {
    ConfigurationBase result;
    try {
        if (log.isTraceEnabled()) {
            log.trace(">loadConfiguration()");
        }
        // Only do the actual SQL query if we might update the configuration
        // due to cache time anyhow
        if (!GlobalConfigurationCacheHolder.INSTANCE.needsUpdate(configID)) {
            result = GlobalConfigurationCacheHolder.INSTANCE.getConfiguration(configID);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Reading Configuration: " + configID);
            }
            GlobalConfigurationData gcdata = findByConfigurationId(configID);
            if (gcdata != null) {
                result = GlobalConfigurationCacheHolder.INSTANCE.getConfiguration(gcdata.getData(), configID);
                GlobalConfigurationCacheHolder.INSTANCE.updateConfiguration(result, configID);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("No default GlobalConfiguration exists. Trying to create a new one.");
                }
                result = GlobalConfigurationCacheHolder.INSTANCE.getNewConfiguration(configID);
                // Call self bean as external here in order to create a transaction if no transaction exists (this method only has SUPPORTS to be as fast as possible)
                globalConfigSession.saveConfigurationNoLog(result);
            }
        }
        return result;
    } finally {
        if (log.isTraceEnabled()) {
            log.trace("<loadGlobalConfiguration()");
        }
    }
}

From source file:org.cesecore.configuration.GlobalConfigurationSessionBean.java

/** @return the found entity instance or null if the entity does not exist */
@Override//w  w w  .j av  a  2s  . co m
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public GlobalConfigurationData findByConfigurationId(String configurationId) {
    return entityManager.find(GlobalConfigurationData.class, configurationId);
}

From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override/*  w w  w. j a va  2s  .  c  o  m*/
public List<Integer> getCryptoTokenIds(final AuthenticationToken authenticationToken) {
    final List<Integer> allCryptoTokenIds = cryptoTokenSession.getCryptoTokenIds();
    final List<Integer> auhtorizedCryptoTokenIds = new ArrayList<Integer>();
    for (final Integer current : allCryptoTokenIds) {
        if (accessControlSessionSession.isAuthorizedNoLogging(authenticationToken,
                CryptoTokenRules.VIEW.resource() + "/" + current.toString())) {
            auhtorizedCryptoTokenIds.add(current);
        }
    }
    return auhtorizedCryptoTokenIds;
}

From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override//w  w  w  .j a  v a 2  s . c o  m
public CryptoToken getCryptoToken(final int cryptoTokenId) {
    return cryptoTokenSession.getCryptoToken(cryptoTokenId);
}

From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override/*from w  ww  .  j av a 2 s . c o  m*/
public CryptoTokenInfo getCryptoTokenInfo(final AuthenticationToken authenticationToken,
        final int cryptoTokenId) throws AuthorizationDeniedException {
    if (!accessControlSessionSession.isAuthorized(authenticationToken,
            CryptoTokenRules.VIEW.resource() + "/" + cryptoTokenId)) {
        final String msg = INTRES.getLocalizedMessage("authorization.notuathorizedtoresource",
                CryptoTokenRules.VIEW.resource(), authenticationToken.toString());
        throw new AuthorizationDeniedException(msg);
    }
    return getCryptoTokenInfo(cryptoTokenId);
}

From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override//from  w  w  w.  ja  va2s  .  c om
public List<CryptoTokenInfo> getCryptoTokenInfos(final AuthenticationToken authenticationToken) {
    final List<CryptoTokenInfo> cryptoTokenInfos = new ArrayList<CryptoTokenInfo>();
    for (final Integer cryptoTokenId : getCryptoTokenIds(authenticationToken)) {
        cryptoTokenInfos.add(getCryptoTokenInfo(cryptoTokenId));
    }
    return cryptoTokenInfos;
}

From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override/* w ww.  j a  va2  s.c om*/
public CryptoTokenInfo getCryptoTokenInfo(final int cryptoTokenId) {
    final CryptoToken cryptoToken = cryptoTokenSession.getCryptoToken(cryptoTokenId);
    if (cryptoToken == null) {
        return null;
    }
    final boolean isActive = cryptoToken.getTokenStatus() == CryptoToken.STATUS_ACTIVE;
    final Properties cryptoTokenProperties = cryptoToken.getProperties();
    final boolean autoActivation = BaseCryptoToken.getAutoActivatePin(cryptoTokenProperties) != null;
    return new CryptoTokenInfo(cryptoTokenId, cryptoToken.getTokenName(), isActive, autoActivation,
            cryptoToken.getClass(), cryptoTokenProperties);
}

From source file:org.cesecore.keys.token.CryptoTokenManagementSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override//from w w w . j a  v  a  2  s  . co m
public void activate(final AuthenticationToken authenticationToken, final int cryptoTokenId,
        final char[] authenticationCode) throws AuthorizationDeniedException, CryptoTokenOfflineException,
        CryptoTokenAuthenticationFailedException {
    assertAuthorization(authenticationToken, cryptoTokenId,
            CryptoTokenRules.ACTIVATE.resource() + "/" + cryptoTokenId);
    final CryptoToken cryptoToken = getCryptoTokenAndAssertExistence(cryptoTokenId);
    cryptoToken.activate(authenticationCode);
    securityEventsLoggerSession.log(EventTypes.CRYPTOTOKEN_ACTIVATION, EventStatus.SUCCESS,
            ModuleTypes.CRYPTOTOKEN, ServiceTypes.CORE, authenticationToken.toString(),
            String.valueOf(cryptoTokenId), null, null,
            "Activated CryptoToken '" + cryptoToken.getTokenName() + "' with id " + cryptoTokenId);
}