use of org.olat.user.UserManager in project openolat by klemens.
the class UserVOFactory method post.
public static void post(User dbUser, UserVO user, Locale locale) {
UserManager um = UserManager.getInstance();
List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
dbUser.setProperty(UserConstants.FIRSTNAME, user.getFirstName());
dbUser.setProperty(UserConstants.LASTNAME, user.getLastName());
dbUser.setProperty(UserConstants.EMAIL, user.getEmail());
for (UserPropertyVO entry : user.getProperties()) {
for (UserPropertyHandler propertyHandler : propertyHandlers) {
if (entry.getName().equals(propertyHandler.getName())) {
String value = parseUserProperty(entry.getValue(), propertyHandler, locale);
String parsedValue;
if (propertyHandler instanceof DatePropertyHandler) {
parsedValue = formatDbDate(value, locale);
} else if (propertyHandler instanceof GenderPropertyHandler) {
parsedValue = parseGender(value, (GenderPropertyHandler) propertyHandler, locale);
} else {
parsedValue = propertyHandler.getStringValue(value, locale);
}
dbUser.setProperty(entry.getName(), parsedValue);
break;
}
}
}
}
use of org.olat.user.UserManager in project openolat by klemens.
the class UserWebService method validateUser.
private List<ErrorVO> validateUser(User user, UserVO userVo, HttpServletRequest request) {
UserManager um = UserManager.getInstance();
Locale locale = getLocale(request);
List<ErrorVO> errors = new ArrayList<>();
List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(PROPERTY_HANDLER_IDENTIFIER, false);
validateProperty(user, UserConstants.FIRSTNAME, userVo.getFirstName(), propertyHandlers, errors, um, locale);
validateProperty(user, UserConstants.LASTNAME, userVo.getLastName(), propertyHandlers, errors, um, locale);
validateProperty(user, UserConstants.EMAIL, userVo.getEmail(), propertyHandlers, errors, um, locale);
for (UserPropertyHandler propertyHandler : propertyHandlers) {
if (!UserConstants.FIRSTNAME.equals(propertyHandler.getName()) && !UserConstants.LASTNAME.equals(propertyHandler.getName()) && !UserConstants.EMAIL.equals(propertyHandler.getName())) {
validateProperty(user, userVo, propertyHandler, errors, um, locale);
}
}
return errors;
}
use of org.olat.user.UserManager in project openolat by klemens.
the class UserWebService method getUserListQuery.
/**
* Search users and return them in a simple form (without user properties). User properties
* can be added two the query parameters. If the authUsername and the authProvider are set,
* the search is made only with these two parameters because they are sufficient to return
* a single user.<br>
* The search with login and user properties are made default with wild cards. If an exact
* match is needed, the parameter msut be quoted:<br>
* users?login="username"<br>
* Don't forget the right escaping in the URL!<br>
* You can make a search with the user properties like this:<br>
* users?telMobile=39847592&login=test
* <br >/ The lookup is possible for authors, usermanagers and system administrators. Normal
* users are not allowed to use the lookup service.
*
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The list of all users in the OLAT system
* @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_USERVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param login The login (search with like)
* @param authProvider An authentication provider (optional)
* @param authUsername An specific username from the authentication provider
* @param uriInfo The URI infos
* @param httpRequest The HTTP request
* @return An array of users
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getUserListQuery(@QueryParam("login") String login, @QueryParam("authProvider") String authProvider, @QueryParam("authUsername") String authUsername, @QueryParam("statusVisibleLimit") String statusVisibleLimit, @Context UriInfo uriInfo, @Context HttpServletRequest httpRequest) {
// User lookup allowed for authors, usermanagers and admins. For
// usernamanger and up are considered "administrative" when it comes to
// lookup of the user properties
boolean isAdministrativeUser = isUserManager(httpRequest);
if (!isAdministrativeUser && !isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
List<Identity> identities;
// make only a search by authUsername
if (StringHelper.containsNonWhitespace(authProvider) && StringHelper.containsNonWhitespace(authUsername)) {
Authentication auth = BaseSecurityManager.getInstance().findAuthenticationByAuthusername(authUsername, authProvider);
if (auth == null) {
identities = Collections.emptyList();
} else {
identities = Collections.singletonList(auth.getIdentity());
}
} else {
String[] authProviders = null;
if (StringHelper.containsNonWhitespace(authProvider)) {
authProviders = new String[] { authProvider };
}
// retrieve and convert the parameters value
Map<String, String> userProps = new HashMap<String, String>();
if (!params.isEmpty()) {
UserManager um = UserManager.getInstance();
Locale locale = getLocale(httpRequest);
List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(PROPERTY_HANDLER_IDENTIFIER, isAdministrativeUser);
for (UserPropertyHandler handler : propertyHandlers) {
if (!params.containsKey(handler.getName()))
continue;
List<String> values = params.get(handler.getName());
if (values.isEmpty())
continue;
String value = formatDbUserProperty(values.get(0), handler, locale);
userProps.put(handler.getName(), value);
}
}
Integer status = Identity.STATUS_VISIBLE_LIMIT;
if (isAdministrativeUser && "all".equalsIgnoreCase(statusVisibleLimit)) {
status = null;
}
identities = BaseSecurityManager.getInstance().getIdentitiesByPowerSearch(login, userProps, true, null, null, authProviders, null, null, null, null, status);
}
int count = 0;
UserVO[] userVOs = new UserVO[identities.size()];
for (Identity identity : identities) {
userVOs[count++] = get(identity);
}
return Response.ok(userVOs).build();
}
use of org.olat.user.UserManager in project openolat by klemens.
the class GenericSelectionPropertyHandler method addFormItem.
/**
* @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale,
* org.olat.core.id.User, java.lang.String, boolean,
* org.olat.core.gui.components.form.flexible.FormItemContainer)
*/
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
FormItem newItem = null;
if (isMultiselect) {
MultipleSelectionElement mse = FormUIFactory.getInstance().addCheckboxesHorizontal(getName(), i18nFormElementLabelKey(), formItemContainer, selectionKeys, getTranslatedValues(selectionKeys, locale));
for (String sKey : getSelectedKeys(user)) {
mse.select(sKey, true);
}
newItem = mse;
} else {
String[] allKeys = new String[selectionKeys.length + 1];
System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
allKeys[0] = NO_SEL_KEY;
SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, getTranslatedValues(allKeys, locale), null);
// make pre-selection of the formItem
String internalValue = getInternalValue(user);
if (isValidValue(user, internalValue, null, null) && internalValue != null)
sse.select(internalValue, true);
newItem = sse;
}
// enable/disable according to settings
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
newItem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
newItem.setMandatory(true);
}
return newItem;
}
use of org.olat.user.UserManager in project openolat by klemens.
the class YearPropertyHandler method addFormItem.
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
/* let's load the years */
loadSelectionKeysFromConfig();
// add the no-selection entry to the dropdown
String[] allKeys = new String[selectionKeys.length + 1];
System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
allKeys[0] = NO_SEL_KEY;
SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, allKeys, null);
String internalValue = getInternalValue(user);
if (isValidValue(user, internalValue, null, null) && internalValue != null)
sse.select(internalValue, true);
// enable/disable according to settings
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
sse.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
sse.setMandatory(true);
}
return sse;
}
Aggregations