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()); } }
public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { if (kapuaEvent == null) { //service bus error. Throw some exception? } LOGGER.info("CredentialService: received kapua event from {}, operation {}", kapuaEvent.getService(), kapuaEvent.getOperation()); if ("user".equals(kapuaEvent.getService()) && "delete".equals(kapuaEvent.getOperation())) { deleteCredentialByUserId(kapuaEvent.getScopeId(), kapuaEvent.getEntityId()); } else if ("account".equals(kapuaEvent.getService()) && "delete".equals(kapuaEvent.getOperation())) { deleteCredentialByAccountId(kapuaEvent.getScopeId(), kapuaEvent.getEntityId()); } }
@Override public void unlock(KapuaId scopeId, KapuaId credentialId) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(credentialId, "credentialId"); // // 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, scopeId)); Credential credential = find(scopeId, credentialId); credential.setLoginFailures(0); credential.setFirstLoginFailure(null); credential.setLoginFailuresReset(null); credential.setLockoutReset(null); update(credential); }
private long countExistingCredentials(CredentialType credentialType, KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); KapuaQuery<Credential> credentialQuery = credentialFactory.newQuery(scopeId); CredentialType ct = credentialType; QueryPredicate credentialTypePredicate = new AttributePredicateImpl<>(CredentialAttributes.CREDENTIAL_TYPE, ct); QueryPredicate userIdPredicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); QueryPredicate andPredicate = new AndPredicateImpl().and(credentialTypePredicate).and(userIdPredicate); credentialQuery.setPredicate(andPredicate); return count(credentialQuery); }
@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(AuthenticationDomains.CREDENTIAL_DOMAIN, Actions.read, scopeId)); // // Build query CredentialQuery query = new CredentialQueryImpl(scopeId); QueryPredicate predicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); query.setPredicate(predicate); // // Query and return result return query(query); }
CredentialListResult existingCredentials = findByUserId(credentialCreator.getScopeId(), credentialCreator.getUserId()); for (Credential credential : existingCredentials.getItems()) { if (credential.getCredentialType().equals(CredentialType.PASSWORD)) {
@Override public void unlock(KapuaId scopeId, KapuaId credentialId) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(credentialId, "credentialId"); // // 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, scopeId)); Credential credential = find(scopeId, credentialId); credential.setLoginFailures(0); credential.setFirstLoginFailure(null); credential.setLoginFailuresReset(null); credential.setLockoutReset(null); update(credential); }
private long countExistingCredentials(CredentialType credentialType, KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); KapuaQuery<Credential> credentialQuery = credentialFactory.newQuery(scopeId); CredentialType ct = credentialType; QueryPredicate credentialTypePredicate = new AttributePredicateImpl<>(CredentialAttributes.CREDENTIAL_TYPE, ct); QueryPredicate userIdPredicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); QueryPredicate andPredicate = new AndPredicateImpl().and(credentialTypePredicate).and(userIdPredicate); credentialQuery.setPredicate(andPredicate); return count(credentialQuery); }
@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(AuthenticationDomains.CREDENTIAL_DOMAIN, Actions.read, scopeId)); // // Build query CredentialQuery query = new CredentialQueryImpl(scopeId); QueryPredicate predicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); query.setPredicate(predicate); // // Query and return result return query(query); }
CredentialListResult existingCredentials = findByUserId(credentialCreator.getScopeId(), credentialCreator.getUserId()); for (Credential credential : existingCredentials.getItems()) { if (credential.getCredentialType().equals(CredentialType.PASSWORD)) {
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()); } }
public void onKapuaEvent(ServiceEvent kapuaEvent) throws KapuaException { if (kapuaEvent == null) { //service bus error. Throw some exception? } LOGGER.info("CredentialService: received kapua event from {}, operation {}", kapuaEvent.getService(), kapuaEvent.getOperation()); if ("user".equals(kapuaEvent.getService()) && "delete".equals(kapuaEvent.getOperation())) { deleteCredentialByUserId(kapuaEvent.getScopeId(), kapuaEvent.getEntityId()); } else if ("account".equals(kapuaEvent.getService()) && "delete".equals(kapuaEvent.getOperation())) { deleteCredentialByAccountId(kapuaEvent.getScopeId(), kapuaEvent.getEntityId()); } }
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()); } }