Search in sources :

Example 1 with OAuthSessionEntity

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;
}
Also used : OAuthSessionEntity(com.peterphi.usermanager.db.entity.OAuthSessionEntity) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 2 with OAuthSessionEntity

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;
}
Also used : OAuthSessionEntity(com.peterphi.usermanager.db.entity.OAuthSessionEntity) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 3 with OAuthSessionEntity

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());
}
Also used : OAuthSessionEntity(com.peterphi.usermanager.db.entity.OAuthSessionEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 4 with OAuthSessionEntity

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;
}
Also used : OAuthSessionEntity(com.peterphi.usermanager.db.entity.OAuthSessionEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Aggregations

Transactional (com.peterphi.std.guice.database.annotation.Transactional)4 OAuthSessionEntity (com.peterphi.usermanager.db.entity.OAuthSessionEntity)4 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)2