use of io.gravitee.am.identityprovider.http.configuration.HttpUsersResourceConfiguration in project gravitee-access-management by gravitee-io.
the class HttpUserProvider method create.
@Override
public Single<User> create(User user) {
try {
// prepare request
final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource();
final HttpResourceConfiguration createResourceConfiguration = usersResourceConfiguration.getPaths().getCreateResource();
final String createUserURI = usersResourceConfiguration.getBaseURL() + createResourceConfiguration.getBaseURL();
final HttpMethod createUserHttpMethod = HttpMethod.valueOf(createResourceConfiguration.getHttpMethod().toString());
final List<HttpHeader> createUserHttpHeaders = createResourceConfiguration.getHttpHeaders();
final String createUserBody = createResourceConfiguration.getHttpBody();
// prepare context
AuthenticationContext authenticationContext = new SimpleAuthenticationContext();
TemplateEngine templateEngine = authenticationContext.getTemplateEngine();
// sanitize password
if (!StringUtils.isEmpty(user.getCredentials())) {
((DefaultUser) user).setCredentials(SanitizeUtils.sanitize(passwordEncoder.encode(user.getCredentials()), createUserBody, createUserHttpHeaders));
}
templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user);
// process request
final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, createUserURI, createUserHttpMethod, createUserHttpHeaders, createUserBody);
return requestHandler.map(httpResponse -> {
final List<HttpResponseErrorCondition> errorConditions = createResourceConfiguration.getHttpResponseErrorConditions();
Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse);
return convert(user.getUsername(), userAttributes);
}).onErrorResumeNext(ex -> {
if (ex instanceof AbstractManagementException) {
return Single.error(ex);
}
LOGGER.error("An error has occurred while creating user {} from the remote HTTP identity provider", user.getUsername(), ex);
return Single.error(new TechnicalManagementException("An error has occurred while creating user from the remote HTTP identity provider", ex));
});
} catch (Exception ex) {
LOGGER.error("An error has occurred while creating the user {}", user.getUsername(), ex);
return Single.error(new TechnicalManagementException("An error has occurred while creating the user", ex));
}
}
use of io.gravitee.am.identityprovider.http.configuration.HttpUsersResourceConfiguration in project gravitee-access-management by gravitee-io.
the class HttpUserProvider method findByUser.
private Maybe<User> findByUser(HttpUsersResourceConfiguration usersResourceConfiguration, HttpResourceConfiguration readResourceConfiguration, User user) {
try {
// prepare context
AuthenticationContext authenticationContext = new SimpleAuthenticationContext();
TemplateEngine templateEngine = authenticationContext.getTemplateEngine();
templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user);
// prepare request
final String readUserURI = usersResourceConfiguration.getBaseURL() + readResourceConfiguration.getBaseURL();
final HttpMethod readUserHttpMethod = HttpMethod.valueOf(readResourceConfiguration.getHttpMethod().toString());
final List<HttpHeader> readUserHttpHeaders = readResourceConfiguration.getHttpHeaders();
final String readUserBody = readResourceConfiguration.getHttpBody();
final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, readUserURI, readUserHttpMethod, readUserHttpHeaders, readUserBody);
return requestHandler.toMaybe().map(httpResponse -> {
final List<HttpResponseErrorCondition> errorConditions = readResourceConfiguration.getHttpResponseErrorConditions();
Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse);
return convert(user.getUsername(), userAttributes);
}).onErrorResumeNext(ex -> {
if (ex instanceof AbstractManagementException) {
return Maybe.error(ex);
}
LOGGER.error("An error has occurred while searching user {} from the remote HTTP identity provider", user.getUsername() != null ? user.getUsername() : user.getEmail(), ex);
return Maybe.error(new TechnicalManagementException("An error has occurred while searching user from the remote HTTP identity provider", ex));
});
} catch (Exception ex) {
LOGGER.error("An error has occurred while searching the user {}", user.getUsername() != null ? user.getUsername() : user.getEmail(), ex);
return Maybe.error(new TechnicalManagementException("An error has occurred while searching the user", ex));
}
}
use of io.gravitee.am.identityprovider.http.configuration.HttpUsersResourceConfiguration in project gravitee-access-management by gravitee-io.
the class HttpUserProvider method delete.
@Override
public Completable delete(String id) {
try {
// prepare context
DefaultUser deleteUser = new DefaultUser();
deleteUser.setId(id);
AuthenticationContext authenticationContext = new SimpleAuthenticationContext();
TemplateEngine templateEngine = authenticationContext.getTemplateEngine();
templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, deleteUser);
// prepare request
final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource();
final HttpResourceConfiguration deleteResourceConfiguration = usersResourceConfiguration.getPaths().getDeleteResource();
final String deleteUserURI = usersResourceConfiguration.getBaseURL() + deleteResourceConfiguration.getBaseURL();
final HttpMethod deleteUserHttpMethod = HttpMethod.valueOf(deleteResourceConfiguration.getHttpMethod().toString());
final List<HttpHeader> deleteUserHttpHeaders = deleteResourceConfiguration.getHttpHeaders();
final String updateUserBody = deleteResourceConfiguration.getHttpBody();
final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, deleteUserURI, deleteUserHttpMethod, deleteUserHttpHeaders, updateUserBody);
return requestHandler.flatMapCompletable(httpResponse -> {
final List<HttpResponseErrorCondition> errorConditions = deleteResourceConfiguration.getHttpResponseErrorConditions();
try {
processResponse(templateEngine, errorConditions, httpResponse);
return Completable.complete();
} catch (Exception ex) {
return Completable.error(ex);
}
}).onErrorResumeNext(ex -> {
if (ex instanceof AbstractManagementException) {
return Completable.error(ex);
}
LOGGER.error("An error has occurred while deleting user {} from the remote HTTP identity provider", id, ex);
return Completable.error(new TechnicalManagementException("An error has occurred while deleting user from the remote HTTP identity provider", ex));
});
} catch (Exception ex) {
LOGGER.error("An error has occurred while deleting the user {}", id, ex);
return Completable.error(new TechnicalManagementException("An error has occurred while deleting the user", ex));
}
}
use of io.gravitee.am.identityprovider.http.configuration.HttpUsersResourceConfiguration in project gravitee-access-management by gravitee-io.
the class HttpUserProvider method findByUsername.
@Override
public Maybe<User> findByUsername(String username) {
// prepare request
final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource();
final HttpResourceConfiguration readResourceConfiguration = usersResourceConfiguration.getPaths().getReadResource();
final DefaultUser user = new DefaultUser(username);
return findByUser(usersResourceConfiguration, readResourceConfiguration, user);
}
use of io.gravitee.am.identityprovider.http.configuration.HttpUsersResourceConfiguration in project gravitee-access-management by gravitee-io.
the class HttpUserProvider method update.
@Override
public Single<User> update(String id, User updateUser) {
try {
// prepare request
final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource();
final HttpResourceConfiguration updateResourceConfiguration = usersResourceConfiguration.getPaths().getUpdateResource();
final String updateUserURI = usersResourceConfiguration.getBaseURL() + updateResourceConfiguration.getBaseURL();
final HttpMethod updateUserHttpMethod = HttpMethod.valueOf(updateResourceConfiguration.getHttpMethod().toString());
final List<HttpHeader> updateUserHttpHeaders = updateResourceConfiguration.getHttpHeaders();
final String updateUserBody = updateResourceConfiguration.getHttpBody();
// prepare context
AuthenticationContext authenticationContext = new SimpleAuthenticationContext();
TemplateEngine templateEngine = authenticationContext.getTemplateEngine();
((DefaultUser) updateUser).setId(id);
// sanitize password
if (!StringUtils.isEmpty(updateUser.getCredentials())) {
((DefaultUser) updateUser).setCredentials(SanitizeUtils.sanitize(passwordEncoder.encode(updateUser.getCredentials()), updateUserBody, updateUserHttpHeaders));
}
templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, updateUser);
// process request
final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, updateUserURI, updateUserHttpMethod, updateUserHttpHeaders, updateUserBody);
return requestHandler.map(httpResponse -> {
final List<HttpResponseErrorCondition> errorConditions = updateResourceConfiguration.getHttpResponseErrorConditions();
Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse);
return convert(updateUser.getUsername(), userAttributes);
}).onErrorResumeNext(ex -> {
if (ex instanceof AbstractManagementException) {
return Single.error(ex);
}
LOGGER.error("An error has occurred while updating user {} from the remote HTTP identity provider", updateUser.getUsername(), ex);
return Single.error(new TechnicalManagementException("An error has occurred while updating user from the remote HTTP identity provider", ex));
});
} catch (Exception ex) {
LOGGER.error("An error has occurred while updating the user {}", updateUser.getUsername(), ex);
return Single.error(new TechnicalManagementException("An error has occurred while updating the user", ex));
}
}
Aggregations