Search in sources :

Example 31 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class LDAPUserAuthenticationService method authenticate.

@Override
@Transactional
public UserEntity authenticate(final String username, final String password, final boolean basicAuth) {
    // TODO Authenticate with LDAP and get user record
    LDAPUserRecord record = ldapAuthenticate(username, password);
    // Sync LDAP record into our database
    UserEntity entity = ensureRolesFetched(registerOrUpdateUser(record));
    // Update the last login timestamp
    entity.setLastLogin(DateTime.now());
    dao.update(entity);
    return entity;
}
Also used : UserEntity(com.peterphi.usermanager.db.entity.UserEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 32 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class OAuthSessionDaoImpl method create.

@Transactional
public OAuthSessionEntity create(final OAuthSessionContextEntity context, final String initiator, final DateTime expires) {
    OAuthSessionEntity session = new OAuthSessionEntity();
    session.setId(SimpleId.alphanumeric("ses-", 36));
    session.setContext(context);
    session.setInitiator(initiator);
    session.setAuthorisationCode(SimpleId.alphanumeric("authc-", 36));
    session.setExpires(expires);
    save(session);
    return getById(session.getId());
}
Also used : OAuthSessionEntity(com.peterphi.usermanager.db.entity.OAuthSessionEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 33 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class OAuthSessionDaoImpl method extend.

@Transactional
public OAuthSessionEntity extend(final String refreshToken, final DateTime newExpires) {
    OAuthSessionEntity session = getById(refreshToken);
    if (refreshToken == null)
        throw new IllegalArgumentException("Invalid refresh token: no live session by id  " + refreshToken);
    else if (!session.isAlive())
        throw new IllegalArgumentException("Invalid refresh token: no live session by id  " + refreshToken);
    session.setExpires(newExpires);
    session.setToken(SimpleId.alphanumeric("tkn-", 36));
    update(session);
    return session;
}
Also used : OAuthSessionEntity(com.peterphi.usermanager.db.entity.OAuthSessionEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 34 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class UserDaoImpl method register.

@Transactional
public int register(String name, String email, String password, final String dateFormat, final String timeZone) {
    if (userExists(email))
        throw new IllegalArgumentException("User '" + email + "' already exists!");
    if (password.isEmpty())
        throw new IllegalArgumentException("Must supply a password!");
    final UserEntity account = new UserEntity();
    account.setLocal(true);
    account.setName(name);
    account.setEmail(email);
    account.setPassword(hashPassword(password));
    account.setDateFormat(dateFormat);
    account.setTimeZone(timeZone);
    account.setSessionReconnectKey(UUID.randomUUID().toString());
    return save(account);
}
Also used : UserEntity(com.peterphi.usermanager.db.entity.UserEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 35 with Transactional

use of com.peterphi.std.guice.database.annotation.Transactional in project stdlib by petergeneric.

the class UserDaoImpl method rotateUserAccessKey.

/**
 * Rotate the primary access key -> secondary access key, dropping the old secondary access key and generating a new primary access key
 *
 * @param id
 */
@Transactional
public void rotateUserAccessKey(final int id) {
    final UserEntity account = getById(id);
    if (account != null) {
        // Set the secondary token to the old primary token
        account.setAccessKeySecondary(account.getAccessKey());
        // Now regenerate the primary token
        account.setAccessKey(SimpleId.alphanumeric(UserManagerBearerToken.PREFIX, 100));
        update(account);
    } else {
        throw new IllegalArgumentException("No such user: " + id);
    }
}
Also used : UserEntity(com.peterphi.usermanager.db.entity.UserEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Aggregations

Transactional (com.peterphi.std.guice.database.annotation.Transactional)46 UserEntity (com.peterphi.usermanager.db.entity.UserEntity)13 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)11 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)9 RoleEntity (com.peterphi.usermanager.db.entity.RoleEntity)9 AuthConstraint (com.peterphi.std.guice.common.auth.annotations.AuthConstraint)8 OAuthServiceEntity (com.peterphi.usermanager.db.entity.OAuthServiceEntity)5 AuthenticationFailureException (com.peterphi.usermanager.guice.authentication.AuthenticationFailureException)5 OAuthSessionEntity (com.peterphi.usermanager.db.entity.OAuthSessionEntity)4 Test (org.junit.Test)4 ResourceInstanceEntity (com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity)3 ResourceTemplateEntity (com.peterphi.servicemanager.service.db.entity.ResourceTemplateEntity)3 Criteria (org.hibernate.Criteria)3 List (java.util.List)2 DateTime (org.joda.time.DateTime)2 Timer (com.codahale.metrics.Timer)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 ServiceInstanceEntity (com.peterphi.servicemanager.service.db.entity.ServiceInstanceEntity)1 ResourceNetworkConfig (com.peterphi.servicemanager.service.guice.ResourceNetworkConfig)1