private void deleteCredentialByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(accountId); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
private void deleteCredentialByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(accountId); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
private void deleteCredentialByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(scopeId); query.setPredicate(new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId)); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
private void deleteCredentialByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(scopeId); query.setPredicate(new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId)); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
@Override public Credential update(Credential credential) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(credential, "credential"); ArgumentValidator.notNull(credential.getId(), "credential.id"); ArgumentValidator.notNull(credential.getScopeId(), "credential.scopeId"); ArgumentValidator.notNull(credential.getUserId(), "credential.userId"); ArgumentValidator.notNull(credential.getCredentialType(), "credential.credentialType"); ArgumentValidator.notEmptyOrNull(credential.getCredentialKey(), "credential.credentialKey"); // // Check access KapuaLocator locator = KapuaLocator.getInstance(); AuthorizationService authorizationService = locator.getService(AuthorizationService.class); PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); authorizationService.checkPermission(permissionFactory.newPermission(AuthenticationDomains.CREDENTIAL_DOMAIN, Actions.write, credential.getScopeId())); return entityManagerSession.onTransactedResult(em -> { Credential currentCredential = CredentialDAO.find(em, credential.getScopeId(), credential.getId()); if (currentCredential == null) { throw new KapuaEntityNotFoundException(Credential.TYPE, credential.getId()); } if (currentCredential.getCredentialType() != credential.getCredentialType()) { throw new KapuaIllegalArgumentException("credentialType", credential.getCredentialType().toString()); } // Passing attributes?? return CredentialDAO.update(em, credential); }); }
@Override public Credential update(Credential credential) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(credential, "credential"); ArgumentValidator.notNull(credential.getId(), "credential.id"); ArgumentValidator.notNull(credential.getScopeId(), "credential.scopeId"); ArgumentValidator.notNull(credential.getUserId(), "credential.userId"); ArgumentValidator.notNull(credential.getCredentialType(), "credential.credentialType"); ArgumentValidator.notEmptyOrNull(credential.getCredentialKey(), "credential.credentialKey"); // // Check access KapuaLocator locator = KapuaLocator.getInstance(); AuthorizationService authorizationService = locator.getService(AuthorizationService.class); PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); authorizationService.checkPermission(permissionFactory.newPermission(AuthenticationDomains.CREDENTIAL_DOMAIN, Actions.write, credential.getScopeId())); return entityManagerSession.onTransactedResult(em -> { Credential currentCredential = CredentialDAO.find(em, credential.getScopeId(), credential.getId()); if (currentCredential == null) { throw new KapuaEntityNotFoundException(Credential.TYPE, credential.getId()); } if (currentCredential.getCredentialType() != credential.getCredentialType()) { throw new KapuaIllegalArgumentException("credentialType", credential.getCredentialType().toString()); } // Passing attributes?? return CredentialDAO.update(em, credential); }); }
user = KapuaSecurityUtils.doPrivileged(() -> userService.find(credential.getScopeId(), credential.getUserId())); } catch (AuthenticationException ae) { throw ae;
user = KapuaSecurityUtils.doPrivileged(() -> userService.find(credential.getScopeId(), credential.getUserId())); } catch (AuthenticationException ae) { throw ae;
credential = CredentialDAO.find(em, credential.getScopeId(), credential.getId());
credential = CredentialDAO.find(em, credential.getScopeId(), credential.getId());