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;
}
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());
}
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;
}
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);
}
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);
}
}
Aggregations