Search in sources :

Example 16 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class TenantServiceImpl method deleteTenant.

@Override
public void deleteTenant(String name) throws ProfileException {
    checkIfTenantActionIsAllowed(name, TenantAction.DELETE_TENANT);
    try {
        profileRepository.removeAll(name);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_DELETE_ALL_PROFILES_ERROR, e, name);
    }
    try {
        tenantRepository.removeByName(name);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_DELETE_TENANT_ERROR, e, name);
    }
    logger.debug(LOG_KEY_TENANT_DELETED, name);
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 17 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class AuthenticationServiceImpl method refreshPersistentLoginToken.

@Override
public PersistentLogin refreshPersistentLoginToken(String loginId) throws ProfileException {
    PersistentLogin login = getPersistentLogin(loginId);
    if (login != null) {
        try {
            login.setToken(UUID.randomUUID().toString());
            persistentLoginRepository.save(login);
            logger.debug(LOG_KEY_PERSISTENT_LOGIN_TOKEN_REFRESHED, loginId, login.getToken());
            return login;
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_PERSISTENT_LOGIN_ERROR, loginId);
        }
    } else {
        throw new NoSuchPersistentLoginException(loginId);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) NoSuchPersistentLoginException(org.craftercms.profile.exceptions.NoSuchPersistentLoginException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) PersistentLogin(org.craftercms.profile.api.PersistentLogin)

Example 18 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class AuthenticationServiceImpl method getTicket.

@Override
public Ticket getTicket(String ticketId) throws ProfileException {
    Ticket ticket;
    try {
        ticket = ticketRepository.findByStringId(ticketId);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_TICKET_ERROR, e, ticketId);
    }
    if (ticket != null) {
        checkIfManageTicketsIsAllowed(ticket.getTenant());
        ticket.setLastRequestTime(new Date());
        try {
            ticketRepository.save(ticket);
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_TICKET_ERROR, ticketId);
        }
        logger.debug(LOG_KEY_TICKET_REQUESTED, ticketId);
        return ticket;
    }
    return null;
}
Also used : Ticket(org.craftercms.profile.api.Ticket) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Date(java.util.Date)

Example 19 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class TenantServiceImpl method updateTenant.

protected Tenant updateTenant(String tenantName, UpdateCallback callback) throws ProfileException {
    Tenant tenant = getTenant(tenantName);
    if (tenant != null) {
        checkIfTenantActionIsAllowed(tenantName, TenantAction.UPDATE_TENANT);
        UpdateHelper updateHelper = new UpdateHelper();
        TenantUpdater tenantUpdater = new TenantUpdater(tenant, updateHelper, tenantRepository);
        callback.doWithTenant(tenantUpdater);
        try {
            tenantUpdater.update();
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_TENANT_ERROR, e, tenant.getName());
        }
    } else {
        throw new NoSuchTenantException(tenantName);
    }
    return tenant;
}
Also used : NoSuchTenantException(org.craftercms.profile.exceptions.NoSuchTenantException) UpdateHelper(org.craftercms.commons.mongo.UpdateHelper) Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 20 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class TenantServiceImpl method createTenant.

@Override
public Tenant createTenant(Tenant tenant) throws ProfileException {
    checkIfTenantActionIsAllowed(null, TenantAction.CREATE_TENANT);
    // Make sure ID is null, we want it auto-generated
    tenant.setId(null);
    try {
        tenantRepository.insert(tenant);
    } catch (DuplicateKeyException e) {
        throw new TenantExistsException(tenant.getName());
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_CREATE_TENANT_ERROR, e, tenant.getName());
    }
    logger.debug(LOG_KEY_TENANT_CREATED, tenant);
    return tenant;
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) TenantExistsException(org.craftercms.profile.exceptions.TenantExistsException) DuplicateKeyException(org.craftercms.commons.mongo.DuplicateKeyException)

Aggregations

I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)31 MongoDataException (org.craftercms.commons.mongo.MongoDataException)26 Profile (org.craftercms.profile.api.Profile)15 Date (java.util.Date)7 Tenant (org.craftercms.profile.api.Tenant)5 Ticket (org.craftercms.profile.api.Ticket)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)3 PersistentLogin (org.craftercms.profile.api.PersistentLogin)3 DisabledProfileException (org.craftercms.profile.exceptions.DisabledProfileException)3 UpdateHelper (org.craftercms.commons.mongo.UpdateHelper)2 VerificationToken (org.craftercms.profile.api.VerificationToken)2 File (java.io.File)1 IOException (java.io.IOException)1 EmailException (org.craftercms.commons.mail.EmailException)1 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)1 AccessTokenExistsException (org.craftercms.profile.exceptions.AccessTokenExistsException)1 BadCredentialsException (org.craftercms.profile.exceptions.BadCredentialsException)1 InvalidEmailAddressException (org.craftercms.profile.exceptions.InvalidEmailAddressException)1