Search in sources :

Example 1 with AccessTokenExistsException

use of org.craftercms.profile.exceptions.AccessTokenExistsException in project profile by craftercms.

the class AccessTokenServiceImpl method createToken.

@Override
public AccessToken createToken(AccessToken token) throws ProfileException {
    checkIfTokenActionIsAllowed(null, Action.CREATE_TOKEN);
    if (token.getId() == null) {
        token.setId(UUID.randomUUID().toString());
    }
    try {
        accessTokenRepository.insert(token);
    } catch (DuplicateKeyException e) {
        throw new AccessTokenExistsException(token.getId());
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_CREATE_ACCESS_TOKEN_ERROR, e, token);
    }
    logger.debug(LOG_KEY_ACCESS_TOKEN_CREATED, token);
    return token;
}
Also used : AccessTokenExistsException(org.craftercms.profile.exceptions.AccessTokenExistsException) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) DuplicateKeyException(org.craftercms.commons.mongo.DuplicateKeyException)

Aggregations

DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)1 MongoDataException (org.craftercms.commons.mongo.MongoDataException)1 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)1 AccessTokenExistsException (org.craftercms.profile.exceptions.AccessTokenExistsException)1