use of com.peterphi.usermanager.db.entity.OAuthSessionEntity in project stdlib by petergeneric.
the class OAuthSessionDaoImpl method exchangeCodeForToken.
@Transactional
public OAuthSessionEntity exchangeCodeForToken(final OAuthServiceEntity service, final String authorisationCode) {
final OAuthSessionEntity session = uniqueResult(new WebQuery().eq("authorisationCode", authorisationCode).isNull("token").eq("alive", true).eq("context.service.id", service.getId()));
if (session == null)
return null;
session.setToken(SimpleId.alphanumeric("tok-", 36));
session.setAuthorisationCode(null);
update(session);
return session;
}
use of com.peterphi.usermanager.db.entity.OAuthSessionEntity in project stdlib by petergeneric.
the class OAuthSessionDaoImpl method exchangeRefreshTokenForNewToken.
@Transactional
public OAuthSessionEntity exchangeRefreshTokenForNewToken(final OAuthServiceEntity service, final String refreshToken, final DateTime newExpires) {
final OAuthSessionEntity session = uniqueResult(new WebQuery().eq("id", refreshToken).isNotNull("token").eq("alive", true).eq("context.service.id", service.getId()));
if (session == null)
return null;
session.setToken(SimpleId.alphanumeric("tok-", 36));
session.setExpires(newExpires);
update(session);
return session;
}
use of com.peterphi.usermanager.db.entity.OAuthSessionEntity 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.usermanager.db.entity.OAuthSessionEntity 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;
}
Aggregations