Search in sources :

Example 1 with CredentialQuery

use of org.eclipse.kapua.service.authentication.credential.CredentialQuery in project kapua by eclipse.

the class CredentialServiceImpl method findByUserId.

@Override
public CredentialListResult findByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(userId, "userId");
    // 
    // Check Access
    KapuaLocator locator = KapuaLocator.getInstance();
    AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
    PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
    authorizationService.checkPermission(permissionFactory.newPermission(CredentialDomain.CREDENTIAL, Actions.read, scopeId));
    // 
    // Build query
    CredentialQuery query = new CredentialQueryImpl(scopeId);
    KapuaPredicate predicate = new AttributePredicate<KapuaId>(CredentialPredicates.USER_ID, userId);
    query.setPredicate(predicate);
    // Query and return result
    return query(query);
}
Also used : CredentialQuery(org.eclipse.kapua.service.authentication.credential.CredentialQuery) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) KapuaPredicate(org.eclipse.kapua.model.query.predicate.KapuaPredicate) AttributePredicate(org.eclipse.kapua.commons.model.query.predicate.AttributePredicate)

Aggregations

AttributePredicate (org.eclipse.kapua.commons.model.query.predicate.AttributePredicate)1 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)1 KapuaPredicate (org.eclipse.kapua.model.query.predicate.KapuaPredicate)1 CredentialQuery (org.eclipse.kapua.service.authentication.credential.CredentialQuery)1 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)1 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)1