Example usage for javax.ejb TransactionAttributeType MANDATORY

List of usage examples for javax.ejb TransactionAttributeType MANDATORY

Introduction

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

Prototype

TransactionAttributeType MANDATORY

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

Click Source Link

Document

If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.

Usage

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void grantUserRoles(PlatformUser user, List<UserRoleType> roles)
        throws ObjectNotFoundException, OperationNotPermittedException, UserRoleAssignmentException {
    for (UserRoleType role : roles) {
        createUserRoleRelationInt(user, role);
    }/*from  w  w w .  j a va 2 s . c  om*/
}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void resetPasswordForUser(PlatformUser user, Marketplace marketplace) throws MailOperationException {

    ensureNoRemoteLdapUsed(user.getOrganization(),
            LogMessageIdentifier.ERROR_PASSWORD_OPERATION_FORBIDDEN_REMOTE_LDAP);

    final String newPwd = new PasswordGenerator().generatePassword();
    setPassword(user, newPwd);/*from  w w  w.  j av  a 2 s  .  c o  m*/
    // send mail to the affected user
    try {
        cm.sendMail(user, EmailType.USER_PASSWORD_RESET, new Object[] { newPwd }, marketplace);
    } catch (MailOperationException e) {
        // Mail reception is essential, otherwise the user cannot work with
        // his account
        MailOperationException mof = new MailOperationException(
                "Mail with your new password cannot be sent. Operation aborted!", e);
        logger.logWarn(Log4jLogger.SYSTEM_LOG, mof, LogMessageIdentifier.WARN_OPERATOR_RESET_PASSWORD_FAILED,
                dm.getCurrentUser().getUserId(), user.getUserId(), e.getId());
        sessionCtx.setRollbackOnly();
        throw mof;
    }

    // unlock the account, if not locked by a platform operator
    if (user.getStatus().getLockLevel() <= UserAccountStatus.LOCKED.getLockLevel()) {
        user.setStatus(UserAccountStatus.PASSWORD_MUST_BE_CHANGED);
        user.setFailedLoginCounter(0);
    }

}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void resetUserPassword(PlatformUser platformUser, String marketplaceId)
        throws UserActiveException, MailOperationException {
    // determine if the user has an active session, if so, throw an
    // exception//  ww  w .java 2  s  . c  o m
    List<Session> sessionsForUserKey = prodSessionMgmt.getSessionsForUserKey(platformUser.getKey());
    if (sessionsForUserKey.size() > 0) {
        UserActiveException uae = new UserActiveException("Reset of password for user '" + platformUser.getKey()
                + "' failed, as the user is still active", new Object[] { platformUser.getUserId() });
        logger.logWarn(Log4jLogger.SYSTEM_LOG, uae, LogMessageIdentifier.WARN_OPERATOR_RESET_PASSWORD_FAILED);
        throw uae;
    }

    // reset the password
    resetPasswordForUser(platformUser, getMarketplace(marketplaceId));
}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void deleteUser(PlatformUser pUser, String marketplaceId) throws OperationNotPermittedException,
        UserDeletionConstraintException, TechnicalServiceNotAliveException, TechnicalServiceOperationException {
    // Check whether user belongs to same organization than the caller
    PermissionCheck.sameOrg(dm.getCurrentUser(), pUser, logger);
    deletePlatformUser(pUser, false, false, getMarketplace(marketplaceId));
}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public List<PlatformUser> getOrganizationUsers() {

    // The organization is determined by the currently logged in user. To
    // obtain the users for this organization, the organization domain
    // object has to be loaded, which then references the users.
    PlatformUser user = dm.getCurrentUser();

    // 1. determine the correlating organization
    Organization organization = user.getOrganization();

    Query q = dm.createNamedQuery("PlatformUser.getVisibleForOrganization");
    q.setParameter("organization", organization);

    return ParameterizedTypes.list(q.getResultList(), PlatformUser.class);
}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public PlatformUser modifyUserData(PlatformUser existingUser, VOUserDetails updatedUser, boolean modifyOwnUser,
        boolean sendMail)
        throws OperationNotPermittedException, NonUniqueBusinessKeyException, TechnicalServiceNotAliveException,
        TechnicalServiceOperationException, ValidationException, ConcurrentModificationException {

    // check whether user belongs to same organization than the caller
    PermissionCheck.sameOrg(dm.getCurrentUser(), existingUser, logger);

    PlatformUser oldUser = existingUser.getEmail() != null ? UserDataAssembler.copyPlatformUser(existingUser)
            : null;/*from ww  w.  j  a  va  2  s.  c o m*/

    // validate permissions for the call, administrator may change any user,
    // a non administrator may only change his own account
    if (!dm.getCurrentUser().isOrganizationAdmin() || modifyOwnUser) {
        if (!String.valueOf(updatedUser.getKey()).equals(sessionCtx.getCallerPrincipal().getName())) {
            OperationNotPermittedException onp = new OperationNotPermittedException(
                    "User is not permitted to modify the specified user account.");
            logger.logWarn(Log4jLogger.SYSTEM_LOG | Log4jLogger.AUDIT_LOG, onp,
                    LogMessageIdentifier.WARN_USER_ACCOUNT_MODIFICATION_FAILED,
                    Long.toString(dm.getCurrentUser().getKey()), updatedUser.getUserId());
            throw onp;
        }
    }

    PlatformUser modUser = UserDataAssembler.toPlatformUser(updatedUser);
    modUser.setKey(existingUser.getKey());
    verifyIdUniquenessAndLdapAttributes(existingUser, modUser);

    // now change the user
    UserDataAssembler.updatePlatformUser(updatedUser, existingUser);

    if (sendMail) {
        sendUserUpdatedMail(existingUser, oldUser);
    }

    notifySubscriptionsAboutUserUpdate(existingUser);

    return existingUser;
}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void verifyIdUniquenessAndLdapAttributes(PlatformUser existingUser, PlatformUser modUser)
        throws NonUniqueBusinessKeyException {

    if (!existingUser.getUserId().equals(modUser.getUserId())) {
        final PlatformUser tmpUser = new PlatformUser();
        tmpUser.setKey(modUser.getKey());
        tmpUser.setUserId(modUser.getUserId());
        dm.validateBusinessKeyUniqueness(tmpUser);
    }//  ww  w  .j  av  a2s .  c om

    // before performing any changes to the platform user, ensure that none
    // of the LDAP managed attributes will be modified
    UserModificationCheck umc = new UserModificationCheck(ldapSettingsMS.getMappedAttributes());
    umc.check(existingUser, modUser);

}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@RolesAllowed("PLATFORM_OPERATOR")
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void setUserAccountStatus(PlatformUser user, UserAccountStatus status)
        throws OrganizationAuthoritiesException {

    // no marketplace passed as this method is only called by the operator
    setUserAccountStatusInternal(user, status, null);

}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void createOrganizationAdmin(VOUserDetails userDetails, Organization organization, String password,
        Long serviceKey, Marketplace marketplace) throws NonUniqueBusinessKeyException, ObjectNotFoundException,
        ValidationException, MailOperationException {
    ArgumentValidator.notNull("organization", organization);
    ArgumentValidator.notNull("userDetails", userDetails);

    PlatformUser organizationAdmin = null;

    // 1. create the user with the given password or with a generated one,
    // if none was set
    String pwd = password;//from  w ww. j a  v  a 2s  .  c om
    boolean isAutoGeneratedPassword = false;
    if (password == null) {
        PasswordGenerator gen = new PasswordGenerator();
        pwd = gen.generatePassword();
        isAutoGeneratedPassword = true;
    }

    try {
        if (organization.isRemoteLdapActive()) {
            organizationAdmin = addPlatformUser(userDetails, organization, pwd, UserAccountStatus.ACTIVE, true,
                    false, marketplace, false, true);

        } else {
            if (isAutoGeneratedPassword) {
                organizationAdmin = addPlatformUser(userDetails, organization, pwd,
                        UserAccountStatus.PASSWORD_MUST_BE_CHANGED, true, true, marketplace, false, true);
            } else {
                organizationAdmin = addPlatformUser(userDetails, organization, pwd,
                        UserAccountStatus.LOCKED_NOT_CONFIRMED, false, true, marketplace, false, true);
            }
        }
    } catch (UserRoleAssignmentException e) {
        throw new ValidationException(e.getMessage());
    }

    if (marketplace == null) {
        checkMinimumUserRoleConstrains(organizationAdmin);
    }

    // 2. send an email to the user to indicate the need to confirm the
    // account. Only required, if a self-chosen password is used
    if (!isAutoGeneratedPassword) {
        String marketplaceId = null;
        if (marketplace != null) {
            marketplaceId = marketplace.getMarketplaceId();
        }
        StringBuffer url = new StringBuffer();

        url.append(cs.getBaseURL());

        // remove any trailing slashes from the base url
        removeTrailingSlashes(url);

        String[] urlParam = new String[4];
        urlParam[0] = organizationAdmin.getOrganization().getOrganizationId();
        urlParam[1] = organizationAdmin.getUserId();
        urlParam[2] = marketplaceId;
        urlParam[3] = serviceKey == null ? null : String.valueOf(serviceKey.longValue());

        if (!organizationAdmin.hasManagerRole()) {
            url.append("/marketplace/confirm.jsf?")
                    .append((marketplaceId != null) ? "mId=" + marketplaceId + "&" : "").append("enc=");
        } else {
            url.append("/public/confirm.jsf?")
                    .append((marketplaceId != null) ? "mId=" + marketplaceId + "&" : "").append("enc=");
        }

        try {
            url.append(URLEncoder.encode(ParameterEncoder.encodeParameters(urlParam), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            MailOperationException mof = new MailOperationException("Confirmation URL creation failed!", e);
            logger.logError(Log4jLogger.SYSTEM_LOG, mof, LogMessageIdentifier.ERROR_UNSUPPORTED_ENCODING);
            throw mof;
        }

        // Bug 7865: Add a dummy postfix to avoid problems with the
        // automatic link recognition in outlook.
        url.append("&et");

        String confirmationURL = url.toString();
        cm.sendMail(organizationAdmin, EmailType.USER_CONFIRM, new Object[] { confirmationURL }, marketplace);
    }

}

From source file:org.oscm.identityservice.bean.IdentityServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void deletePlatformUser(PlatformUser user, Marketplace marketplace)
        throws UserDeletionConstraintException, ObjectNotFoundException, TechnicalServiceNotAliveException,
        TechnicalServiceOperationException {
    dm.getReference(PlatformUser.class, user.getKey());
    // internal call, so also admin users may be revoked
    deletePlatformUser(user, true, true, marketplace);
}