Search in sources :

Example 1 with OAuthSessionContextEntity

use of com.peterphi.usermanager.db.entity.OAuthSessionContextEntity in project stdlib by petergeneric.

the class UserManagerOAuthServiceImpl method createSession.

public OAuthSessionEntity createSession(final int userId, final String clientId, final String redirectUri, final String scope, final boolean allowCreateApproval) {
    final OAuthServiceEntity client = serviceDao.getByClientIdAndEndpoint(clientId, redirectUri);
    if (client == null)
        throw new IllegalArgumentException("No such client with id " + clientId + " at the provided endpoint! There is a problem with the service that sent you here.");
    OAuthSessionContextEntity context = contextDao.get(userId, client.getId(), scope);
    // Try to create a context for a session to live within (if permitted)
    if (context == null) {
        if (allowCreateApproval || autoGrantAccessToAllServices)
            context = contextDao.create(userDao.getById(userId), client, scope);
        else
            // Not allowed to create an approval so cannot create a session
            return null;
    }
    // Now create a Session
    return sessionDao.create(context, computeInitiatorInfo(), DateTime.now().plus(tokenRefreshInterval));
}
Also used : OAuthSessionContextEntity(com.peterphi.usermanager.db.entity.OAuthSessionContextEntity) OAuthServiceEntity(com.peterphi.usermanager.db.entity.OAuthServiceEntity)

Example 2 with OAuthSessionContextEntity

use of com.peterphi.usermanager.db.entity.OAuthSessionContextEntity in project stdlib by petergeneric.

the class OAuthSessionContextDaoImpl method create.

/**
 * Create a context (or reuse an existing active context)
 *
 * @param user
 * 		the user
 * @param service
 * 		the service
 * @param scope
 * 		the access scope the service is granted
 *
 * @return
 */
@Transactional
public OAuthSessionContextEntity create(final UserEntity user, final OAuthServiceEntity service, final String scope) {
    // Create a new context
    OAuthSessionContextEntity entity = get(user.getId(), service.getId(), scope);
    // No active context exists, we must create one
    if (entity == null) {
        entity = new OAuthSessionContextEntity();
        entity.setUser(user);
        entity.setScope(StringUtils.trimToEmpty(scope));
        entity.setService(service);
        entity.setActive(true);
        entity.setId(save(entity));
    }
    return entity;
}
Also used : OAuthSessionContextEntity(com.peterphi.usermanager.db.entity.OAuthSessionContextEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Aggregations

OAuthSessionContextEntity (com.peterphi.usermanager.db.entity.OAuthSessionContextEntity)2 Transactional (com.peterphi.std.guice.database.annotation.Transactional)1 OAuthServiceEntity (com.peterphi.usermanager.db.entity.OAuthServiceEntity)1