Session session = repository.login(credentials); try { // here your code } finally { session.logout(); }