Search in sources :

Example 11 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery 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 12 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery 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 13 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.

the class UserDaoImpl method loginBySessionReconnectKey.

@Transactional
public UserEntity loginBySessionReconnectKey(String key) {
    final UserEntity account = uniqueResult(new WebQuery().eq("local", true).eq("sessionReconnectKey", key));
    if (account != null) {
        log.info("Allowed login by session reconnect key for user: " + account.getEmail());
        account.setLastLogin(new DateTime());
        update(account);
    }
    return account;
}
Also used : WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) UserEntity(com.peterphi.usermanager.db.entity.UserEntity) DateTime(org.joda.time.DateTime) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 14 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.

the class RoleUIServiceImpl method getRoles.

@Override
@Transactional(readOnly = true)
public String getRoles(UriInfo query) {
    ConstrainedResultSet<RoleEntity> resultset = dao.findByUriQuery(new WebQuery().orderAsc("id").decode(query));
    TemplateCall call = templater.template("roles");
    call.set("resultset", resultset);
    call.set("roles", resultset.getList());
    call.set("nonce", nonceStore.getValue(NONCE_USE));
    return call.process();
}
Also used : RoleEntity(com.peterphi.usermanager.db.entity.RoleEntity) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 15 with WebQuery

use of com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery in project stdlib by petergeneric.

the class WebQueryTest method testEncodeResultStable.

@Test
public void testEncodeResultStable() {
    WebQuery query = new WebQuery().orderDesc("id").orderAsc("name").orderAsc("name2").limit(99).computeSize(true).or(g -> g.eq("id", 1).contains("id", "some_value")).eq("name", "x");
    assertEquals("{_compute_size=[true], _fetch=[entity], _order=[id desc, name asc, name2 asc], _limit=[99], name=[x], id=[1, _f_contains_some_value]}", query.encode().toString());
}
Also used : ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test) URI(java.net.URI) Assert.assertEquals(org.junit.Assert.assertEquals) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) Test(org.junit.Test)

Aggregations

WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)24 Test (org.junit.Test)15 Transactional (com.peterphi.std.guice.database.annotation.Transactional)12 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)4 OAuthSessionEntity (com.peterphi.usermanager.db.entity.OAuthSessionEntity)2 RoleEntity (com.peterphi.usermanager.db.entity.RoleEntity)2 UserEntity (com.peterphi.usermanager.db.entity.UserEntity)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ResteasyUriInfo (org.jboss.resteasy.spi.ResteasyUriInfo)2 DateTime (org.joda.time.DateTime)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Inject (com.google.inject.Inject)1 ResourceInstanceDTO (com.peterphi.servicemanager.service.rest.resource.type.ResourceInstanceDTO)1 AuthConstraint (com.peterphi.std.guice.common.auth.annotations.AuthConstraint)1 HibernateDao (com.peterphi.std.guice.hibernate.dao.HibernateDao)1 QEntityFactory (com.peterphi.std.guice.hibernate.webquery.impl.QEntityFactory)1 JPASearchExecutor (com.peterphi.std.guice.hibernate.webquery.impl.jpa.JPASearchExecutor)1 JPASearchStrategy (com.peterphi.std.guice.hibernate.webquery.impl.jpa.JPASearchStrategy)1 GuiceUnit (com.peterphi.std.guice.testing.GuiceUnit)1