io.gravitee.am.identityprovider.api.UserProvider Maven / Gradle / Ivy
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.am.identityprovider.api;
import io.gravitee.common.component.Lifecycle;
import io.gravitee.common.service.Service;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Single;
/**
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
* @author GraviteeSource Team
*/
public interface UserProvider extends Service {
default Maybe findByEmail(String email) {
return Maybe.empty();
}
Maybe findByUsername(String username);
Single create(User user);
Single update(String id, User updateUser);
default Single updateUsername(User user, String username) {
if (username == null || username.isEmpty()) {
return Single.error(new IllegalArgumentException("Username required for UserProvider.updateUsername"));
}
((DefaultUser) user).setUsername(username);
return this.update(user.getId(), user);
}
default Single updatePassword(User user, String password) {
if (password == null || password.isEmpty()) {
return Single.error(new IllegalArgumentException("Password required for UserProvider.updatePassword"));
}
((DefaultUser) user).setCredentials(password);
return this.update(user.getId(), user);
}
Completable delete(String id);
default Lifecycle.State lifecycleState() {
return Lifecycle.State.INITIALIZED;
}
default UserProvider start() throws Exception {
return this;
}
default Single asyncStart() {
try {
return Single.fromCallable(() -> this.start());
} catch (Exception e) {
return Single.error(e);
}
}
default UserProvider stop() throws Exception {
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy