Example usage for javax.ejb LockType READ

List of usage examples for javax.ejb LockType READ

Introduction

In this page you can find the example usage for javax.ejb LockType READ.

Prototype

LockType READ

To view the source code for javax.ejb LockType READ.

Click Source Link

Document

For read-only operations.

Usage

From source file:be.fedict.hsm.model.KeyStoreSingletonBean.java

/**
 * Sign the given digest value./*from  ww  w  .  j  a  v a2  s . c  o m*/
 * 
 * @param keyStoreId
 * @param keyStoreAlias
 * @param digestAlgo
 * @param digestValue
 * @return the signature, or <code>null</code> in case something went wrong.
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeyException
 * @throws IOException
 * @throws SignatureException
 */
@Lock(LockType.READ)
public byte[] sign(long keyStoreId, String keyStoreAlias, String digestAlgo, byte[] digestValue)
        throws NoSuchAlgorithmException, InvalidKeyException, IOException, SignatureException {
    Map<String, PrivateKeyEntry> keyStoreKeys = this.privateKeyEntries.get(keyStoreId);
    if (null == keyStoreKeys) {
        LOG.error("unknown key store: " + keyStoreId);
        return null;
    }
    PrivateKeyEntry privateKeyEntry = keyStoreKeys.get(keyStoreAlias);
    if (null == privateKeyEntry) {
        LOG.error("private key for alias not available: " + keyStoreAlias);
        return null;
    }
    PrivateKey privateKey = privateKeyEntry.getPrivateKey();
    Signature signature = Signature.getInstance("NONEwithRSA");
    signature.initSign(privateKey);

    ByteArrayOutputStream digestInfo = new ByteArrayOutputStream();
    byte[] digestInfoPrefix = digestInfoPrefixes.get(digestAlgo);
    if (null == digestInfoPrefix) {
        throw new NoSuchAlgorithmException(digestAlgo);
    }
    digestInfo.write(digestInfoPrefix);
    digestInfo.write(digestValue);

    signature.update(digestInfo.toByteArray());

    return signature.sign();
}

From source file:io.hops.hopsworks.common.security.CertificatesMgmService.java

@Lock(LockType.READ)
@AccessTimeout(value = 3, unit = TimeUnit.SECONDS)
public String getMasterEncryptionPassword() throws IOException {
    return FileUtils.readFileToString(masterPasswordFile).trim();
}

From source file:io.hops.hopsworks.common.security.CertificatesMgmService.java

/**
 * Validates the provided password against the configured one
 * @param providedPassword Password to validate
 * @param userRequestedEmail User requested the password check
 * @throws IOException/*w  w w  .ja  v a2 s  . com*/
 * @throws EncryptionMasterPasswordException
 */
@Lock(LockType.READ)
@AccessTimeout(value = 3, unit = TimeUnit.SECONDS)
public void checkPassword(String providedPassword, String userRequestedEmail)
        throws IOException, EncryptionMasterPasswordException {
    String sha = DigestUtils.sha256Hex(providedPassword);
    if (!getMasterEncryptionPassword().equals(sha)) {
        Users user = userFacade.findByEmail(userRequestedEmail);
        String logMsg = "*** Attempt to change master encryption password with wrong credentials";
        if (user != null) {
            LOG.log(Level.INFO, logMsg + " by user <" + user.getUsername() + ">");
        } else {
            LOG.log(Level.INFO, logMsg);
        }
        throw new EncryptionMasterPasswordException("Provided password is incorrect");
    }
}

From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.RulesMessageServiceBean.java

@Override
@Interceptors(RulesPreValidationInterceptor.class)
@Lock(LockType.READ)
public void evaluateFLUXFAReportRequest(SetFLUXFAReportMessageRequest request) {
    final String requestStr = request.getRequest();
    final String logGuid = request.getLogGuid();
    log.info("[INFO] Going to evaluate FLUXFAReportMessage with GUID [[ " + logGuid + " ]].");
    FLUXFAReportMessage fluxfaReportMessage = null;
    try {//from  www.j  a va  2s . com
        // Validate xsd schema
        fluxfaReportMessage = extractFluxFaReportMessage(requestStr);
        if (fluxfaReportMessage != null) {
            FLUXResponseMessage fluxResponseMessageType;
            Map<Boolean, ValidationResultDto> validationMap = rulesPreProcessBean
                    .checkDuplicateIdInRequest(fluxfaReportMessage);
            boolean needToValidate = validationIsToContinue(validationMap);
            log.info("[INFO] Validation needs to continue : [[ " + needToValidate + " ]].");
            if (needToValidate) {
                log.info("[INFO] Triggering drools validation on message...");
                Map<ExtraValueType, Object> extraValueTypeObjectMap = rulesEngine
                        .generateExtraValueMap(FLUX_ACTIVITY_REQUEST_MSG, fluxfaReportMessage);
                extraValueTypeObjectMap.put(SENDER_RECEIVER, request.getSenderOrReceiver());
                List<AbstractFact> faReportFacts = rulesEngine.evaluate(FLUX_ACTIVITY_REQUEST_MSG,
                        fluxfaReportMessage, extraValueTypeObjectMap);
                ValidationResultDto faReportValidationResult = rulePostProcessBean
                        .checkAndUpdateValidationResult(faReportFacts, requestStr, logGuid,
                                RawMsgType.FA_REPORT);
                updateValidationResultWithExisting(faReportValidationResult, validationMap.get(needToValidate));
                updateRequestMessageStatus(logGuid, faReportValidationResult);
                if (faReportValidationResult != null && !faReportValidationResult.isError()) {
                    log.info("[INFO] The Validation of Report is successful, forwarding message to Activity.");
                    boolean hasPermissions = activityServiceBean.checkSubscriptionPermissions(requestStr,
                            MessageType.FLUX_FA_REPORT_MESSAGE);
                    if (hasPermissions) {
                        log.info(
                                "[INFO] Request has permissions. Going to send FaReportMessage to Activity Module...");
                        sendRequestToActivity(requestStr, request.getUsername(), request.getType(),
                                MessageType.FLUX_FA_REPORT_MESSAGE);
                    } else {
                        log.info("[WARN] Request doesn't have permissions!");
                    }
                } else {
                    log.info(
                            "[WARN] Validation resulted in errors. Not going to send msg to Activity module..");
                }
                fluxResponseMessageType = generateFluxResponseMessageForFaReport(faReportValidationResult,
                        fluxfaReportMessage);
                XPathRepository.INSTANCE.clear(faReportFacts);
            } else {
                log.info("[WARNING] Found already existing Validation(s) for message with GUID [" + logGuid
                        + "]. \nNot going to process or send it to Business module!");
                updateRequestMessageStatus(logGuid, validationMap.get(needToValidate));
                fluxResponseMessageType = generateFluxResponseMessageForFaReport(
                        validationMap.get(needToValidate), fluxfaReportMessage);
                log.info("[INFO] The Validation of FLUXFAReport is complete and FluxResponse is generated");
            }
            validateAndSendResponseToExchange(fluxResponseMessageType, request, request.getType());
        }
    } catch (SAXException | RulesModelMarshallException e) {
        log.error("[ERROR] Error while trying to parse FLUXFAReportMessage received message! It is malformed!",
                e);
        updateRequestMessageStatus(logGuid, generateValidationResultDtoForFailure());
        sendFLUXResponseMessageOnException(e.getMessage(), requestStr, request, fluxfaReportMessage);
        throw new RulesServiceException(e.getMessage(), e);
    } catch (RulesValidationException e) {
        log.error("[ERROR] Error during validation of the received FLUXFAReportMessage!", e);
        updateRequestMessageStatus(logGuid, generateValidationResultDtoForFailure());
        sendFLUXResponseMessageOnException(e.getMessage(), requestStr, request, fluxfaReportMessage);
    }
}

From source file:org.rhq.enterprise.server.auth.prefs.SubjectPreferencesCacheBean.java

@Override
@Lock(LockType.READ)
public PropertySimple getUserProperty(int subjectId, String propertyName) {
    load(subjectId);/*from  w ww. ja va 2 s.  c  o m*/

    Configuration config = subjectPreferences.get(subjectId);
    if (config == null) {
        return null;
    }

    PropertySimple prop = config.getSimple(propertyName);
    if (prop == null) {
        return null;
    }

    return new PropertySimple(propertyName, prop.getStringValue());
}

From source file:org.rhq.enterprise.server.auth.prefs.SubjectPreferencesCacheBean.java

/**
 * @param subjectId the subject to get preferences of
 * @return the <b>COPY</b> of the configuration object - changes done to that instance will not be reflected in the persisted
 * preferences//from w  w w  .ja va  2  s . c  om
 */
@Override
@Lock(LockType.READ)
public Configuration getPreferences(int subjectId) {
    load(subjectId);

    Configuration config = subjectPreferences.get(subjectId);
    if (config == null) {
        return new Configuration();
    } else {
        return config.deepCopy();
    }
}

From source file:org.sofun.core.kup.points.KupPointsTimer.java

@Timeout
@Schedule(minute = "*/5", hour = "*", persistent = false)
@Lock(LockType.READ)
public void check() throws Exception {

    if (!available) {
        return;/*from   w  w  w  . j  ava 2  s.c om*/
    } else {
        available = false;
    }

    try {

        List<Prediction> toCompute = predictions.getPredictionsGameToCompute();
        toCompute.addAll(predictions.getPredictionsRoundToCompute());
        toCompute.addAll(predictions.getPredictionsStageToCompute());
        toCompute.addAll(predictions.getPredictionsSeasonToCompute());

        final int totalPredictions = toCompute.size();
        if (totalPredictions > 0) {

            log.info("Found " + String.valueOf(toCompute.size())
                    + " predictions for which we need to compute points.");

            int current = 1;
            ListIterator<Prediction> predictionIter = toCompute.listIterator();
            List<Long> moderatedKups = new ArrayList<Long>();
            while (predictionIter.hasNext()) {

                Prediction prediction = predictionIter.next();

                if (prediction == null || prediction.isPointsComputed()) {
                    continue;
                }

                // Verify the Kup has been moderated.
                if (!prediction.getKup().isModerated() || (!prediction.getKup().isTemplate()
                        && (kups.getTemplateFor(prediction.getKup()) != null
                                && !kups.getTemplateFor(prediction.getKup()).isModerated()))) {
                    if (!moderatedKups.contains(prediction.getKup().getId())) {
                        log.warn("Kup with uuid=" + prediction.getKup().getId()
                                + " has not been moderated yet...");
                        moderatedKups.add(prediction.getKup().getId());
                    }
                    continue;
                }

                // Reload member from context.
                Member member = members.getMember(prediction.getMember().getEmail());

                // Get corresponding Kup.
                Kup kup = prediction.getKup();

                KupRankingTable kupRanking = kup.getRankingTable();
                MemberRankingTableEntry kupRankingEntry = kupRanking.getEntryForMember(member);

                if (kupRankingEntry == null) {
                    if (KupType.GAMBLING_FR.equals(kup.getType())) {
                        log.debug("member=" + member.getEmail() + " in kup w/ uuid=" + kup.getId()
                                + " is not a participant." + " (predictions but no bet probably)");
                        prediction.setPointsComputed(true);
                    } else if (KupType.FREE.equals(kup.getType())) {
                        log.error("member=" + member.getEmail() + " in kup w/ uuid=" + kup.getId()
                                + " Cannot be found within ranking table.");
                    }
                    continue;
                }

                final int predictionPoints = kups.getPointsPredictionFor(kup, prediction);
                log.info(String.format(
                        "Points for prediction w/ uuid=%d in kup" + " w/ uuid=%d for member with email=%s =>"
                                + " %d points (prediction %d/%d)",
                        prediction.getId(), kup.getId(), member.getEmail(), predictionPoints, current,
                        totalPredictions));

                // Update points and settle prediction
                prediction.setPoints(predictionPoints);
                kupRankingEntry.setValue(kupRankingEntry.getValue() + predictionPoints);
                prediction.setPointsComputed(true);

                // Update correct number of predictions.
                if (predictionPoints > 0) {
                    Integer correct = kupRankingEntry.getCorrectPredictions();
                    if (correct == null) {
                        correct = kups.countCorrectPredictionsFor(kup, member);
                    } else {
                        correct = correct + 1;
                    }
                    kupRankingEntry.setCorrectPredictions(correct);
                }
                if (kupRankingEntry.getFirstPredictions() == null) {
                    kupRankingEntry.setFirstPredictions(kups.getFirstPredictionDateFor(member, kup));
                }

                // Update last modified.
                final Date modified = Calendar.getInstance().getTime();
                kupRanking.setLastModified(modified);

                current++;

            }

        }

    } catch (Throwable t) {
        t.printStackTrace();
        log.error(t.getMessage());
    } finally {
        available = true;
    }

}

From source file:org.sofun.core.kup.stat.KupStatsTimer.java

@Timeout
@Schedule(minute = "15", hour = "2", persistent = false)
@Lock(LockType.READ)
public void check() throws Exception {
    if (!available) {
        return;/* w  w w  .j a  v  a2 s.  c  o m*/
    } else {
        available = false;
    }
    try {
        kups.updateKupsStats();
    } catch (Throwable t) {
        t.printStackTrace();
        log.error(t.getMessage());
    } finally {
        available = true;
    }
}

From source file:org.sofun.core.team.FacebookLigue1Clubs.java

@Timeout
// XXX DISABLED/* w w w.  jav  a 2s  .c  om*/
// @Schedule(minute = "*/15", hour = "*", persistent = false)
@Lock(LockType.READ)
public void check() throws Exception {

    if (!available) {
        return;
    } else {
        available = false;
    }

    try {

        Team appTeam = teams.getTeam(APP_TEAM_ID);
        Team[] clubs = new Team[] { teams.getTeam(APP_TEAM_MHSC_ID), teams.getTeam(APP_TEAM_PSG_ID),
                teams.getTeam(APP_TEAM_LOSC_ID), teams.getTeam(APP_TEAM_OL_ID), teams.getTeam(APP_TEAM_GDB_ID),
                teams.getTeam(APP_TEAM_RENNES_ID), teams.getTeam(APP_TEAM_ASSE_ID),
                teams.getTeam(APP_TEAM_TOULOUSE_ID), teams.getTeam(APP_TEAM_EVIAN_ID),
                teams.getTeam(APP_TEAM_OM_ID), teams.getTeam(APP_TEAM_NANCY_ID), teams.getTeam(APP_TEAM_VAL_ID),
                teams.getTeam(APP_TEAM_NICE_ID), teams.getTeam(APP_TEAM_SOCHAUX_ID),
                teams.getTeam(APP_TEAM_BREST_ID), teams.getTeam(APP_TEAM_AJACCIO_ID),
                teams.getTeam(APP_TEAM_TROYES_ID), teams.getTeam(APP_TEAM_LORIENT_ID),
                teams.getTeam(APP_TEAM_BASTIA_ID), teams.getTeam(APP_TEAM_REIMS_ID) };

        List<Team> lclubs = Arrays.asList(clubs);

        Iterator<MemberRankingTableEntry> entriesIt = appTeam.getRankingTable().getEntries().iterator();
        while (entriesIt.hasNext()) {

            MemberRankingTableEntry entry = entriesIt.next();
            boolean up = false;
            for (Team club : lclubs) {
                if (club.isMember(entry.getMember())) {
                    MemberRankingTableEntry clubEntry = club.getRankingTable()
                            .getEntryForMember(entry.getMember());
                    clubEntry.setValue(entry.getValue());
                    up = true;
                    break;
                }
            }
            if (!up) {
                log.error("No entry found for member=" + entry.getMember().getEmail());
                // throw new CoreException("No club found for member="
                // + entry.getMember().getEmail());
            }

        }

        // Compute total points for each clubs
        for (Team club : lclubs) {
            long totalPoints = 0;
            Iterator<MemberRankingTableEntry> clubEntriesIt = club.getRankingTable().getEntries().iterator();
            while (clubEntriesIt.hasNext()) {
                MemberRankingTableEntry entry = clubEntriesIt.next();
                totalPoints += entry.getValue();
            }
            club.getRankingTable().setEntriesTotalPoints(totalPoints);
        }

    } catch (Throwable t) {
        t.printStackTrace();
        log.error(t.getMessage());
    } finally {
        available = true;
    }

}

From source file:org.sofun.core.team.TeamPointsTimer.java

@Timeout
// XXX DISABLE/*  w  w w.  j a  v a  2  s. com*/
// @Schedule(minute = "*/59", hour = "*", persistent = false)
@Lock(LockType.READ)
public void check() throws Exception {

    if (!available) {
        return;
    } else {
        available = false;
    }

    try {

        List<Team> actives = teams.getTeamsWithActiveKups();
        log.info("Found " + actives.size() + " teams for which we need to update ranking");

        List<Long> computed = new ArrayList<Long>();
        ListIterator<Team> teamItr = actives.listIterator();
        while (teamItr.hasNext()) {
            Team team = teamItr.next();
            if (computed.contains(team.getId())) {
                continue;
            }
            team.setNbMembers(team.getMembers().size());
            long entriesTotalPoints = 0;
            log.info("Updating team ranking. Team UUID=" + team.getId() + " name=" + team.getName());
            Iterator<MemberRankingTableEntry> teamEntriesItr = team.getRankingTable().getEntries().iterator();
            while (teamEntriesItr.hasNext()) {
                MemberRankingTableEntry entry = teamEntriesItr.next();
                int total = 0;
                Iterator<Kup> kupItr = team.getKups().iterator();
                while (kupItr.hasNext()) {
                    Kup kup = kupItr.next();
                    if (kup.getStatus() == KupStatus.CANCELED) {
                        continue;
                    }
                    MemberRankingTableEntry teamEntry = kup.getRankingTable()
                            .getEntryForMember(entry.getMember());
                    if (teamEntry != null) {
                        total += teamEntry.getValue();
                    }
                }
                entry.setValue(total);
                entriesTotalPoints += total;
                log.debug("Member with email=" + entry.getMember().getEmail() + " in team with id="
                        + team.getId() + " has now value=" + total);
            }
            team.getRankingTable().setEntriesTotalPoints(entriesTotalPoints);
            computed.add(team.getId());
        }

    } catch (Throwable t) {
        t.printStackTrace();
        log.error(t.getMessage());
    } finally {
        available = true;
    }
}