use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class AdvancedPropertySearchForm method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
int c = 0;
if (userName.getValue().length() > 0) {
c++;
BaseSecurity secMgr = BaseSecurityManager.getInstance();
identity = secMgr.findIdentityByName(userName.getValue());
if (identity == null) {
userName.setErrorKey("error.search.form.nousername", null);
return false;
}
}
if (resourceTypeName.getSelected() > 0)
c++;
if (resourceTypeId.getValue().length() > 0)
c++;
if (category.getValue().length() > 0)
c++;
if (propertyName.getValue().length() > 0)
c++;
if (c == 0) {
showInfo("error.search.form.notempty");
return false;
}
return true;
}
use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class QuotaManagerImpl method hasQuotaEditRights.
@Override
public boolean hasQuotaEditRights(Identity identity) {
BaseSecurity mgr = BaseSecurityManager.getInstance();
boolean hasQuoaRights = mgr.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ACCESS, OresHelper.lookupType(GenericQuotaEditController.class));
return hasQuoaRights;
}
use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class UserBulkChangePasswordController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (event == Event.DONE_EVENT) {
String[] usernames = changePasswordForm.getUsernames();
String password = changePasswordForm.getPassword();
boolean autodisc = changePasswordForm.getDisclaimerAccept();
boolean langGerman = changePasswordForm.getLangGerman();
BaseSecurity identityManager = BaseSecurityManager.getInstance();
int c = 0;
for (String username : usernames) {
if (username.length() == 0)
continue;
try {
Identity identity = identityManager.findIdentityByName(username);
if (identity != null) {
if (password != null && password.trim().length() > 0) {
olatAuthenticationSpi.changePassword(ureq.getIdentity(), identity, password);
log.info("changePassword for username: " + username);
}
if (autodisc) {
registrationManager.setHasConfirmedDislaimer(identity);
log.info("Disclaimer accepted for username: " + username);
}
if (langGerman) {
identity.getUser().getPreferences().setLanguage("de");
UserManager.getInstance().updateUserFromIdentity(identity);
log.info("Set language German for username: " + username);
}
c++;
} else {
log.warn("could find user with username: " + username);
}
} catch (Exception e) {
log.error("Failed to change password/settings for username: " + username, e);
}
}
// notify done
getWindowControl().setInfo(translate("bulk.psw.done", "" + c));
// TODO: clear the form
// changePasswordForm.clearForm(); //???
}
}
use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class InfoMessagesWebService method createEmptyCourse.
/**
* Creates a new info message
* @response.representation.200.qname {http://www.example.com}infoMessageVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The info message
* @response.representation.200.example {@link org.olat.commons.info.restapi.Examples#SAMPLE_INFOMESSAGEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param resName The OLAT Resourceable name
* @param resId The OLAT Resourceable id
* @param resSubPath The resource sub path (optional)
* @param businessPath The business path
* @param authorKey The identity key of the author
* @param title The title
* @param message The message
* @param request The HTTP request
* @return It returns the id of the newly info message
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(@QueryParam("resName") final String resName, @QueryParam("resId") final Long resId, @QueryParam("resSubPath") String resSubPath, @QueryParam("businessPath") String businessPath, @QueryParam("authorKey") Long authorKey, @QueryParam("title") String title, @QueryParam("message") String message, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
OLATResourceable ores = new OLATResourceable() {
@Override
public String getResourceableTypeName() {
return resName;
}
@Override
public Long getResourceableId() {
return resId;
}
};
Identity author;
UserRequest ureq = getUserRequest(request);
if (authorKey == null) {
author = ureq.getIdentity();
} else {
BaseSecurity securityManager = BaseSecurityManager.getInstance();
author = securityManager.loadIdentityByKey(authorKey, false);
if (author == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
InfoMessageFrontendManager messageManager = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
InfoMessage msg = messageManager.createInfoMessage(ores, resSubPath, businessPath, author);
msg.setTitle(title);
msg.setMessage(message);
messageManager.sendInfoMessage(msg, null, ureq.getLocale(), ureq.getIdentity(), Collections.<Identity>emptyList());
InfoMessageVO infoVO = new InfoMessageVO(msg);
return Response.ok(infoVO).build();
}
use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class ShibbolethRegistrationController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == migrationForm) {
if (event == Event.CANCELLED_EVENT) {
mainContainer.setPage(VELOCITY_ROOT + "/register.html");
} else if (event == Event.DONE_EVENT) {
state = STATE_MIGRATED_SHIB_USER;
mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
}
} else if (source == regWithUserPropForm) {
if (event == Event.CANCELLED_EVENT) {
mainContainer.setPage(VELOCITY_ROOT + "/register.html");
} else if (event == Event.DONE_EVENT) {
state = STATE_NEW_SHIB_USER;
mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
}
} else if (source == regForm) {
if (event == Event.DONE_EVENT) {
String choosenLogin = regForm.getLogin();
BaseSecurity secMgr = BaseSecurityManager.getInstance();
Identity identity = secMgr.findIdentityByName(choosenLogin);
if (identity == null) {
// ok, create new user
if (isMandatoryUserPropertyMissing()) {
regWithUserPropForm = new ShibbolethRegistrationUserPropertiesFrom(ureq, getWindowControl(), shibbolethAttributes);
regWithUserPropForm.addControllerListener(this);
mainContainer.put("getUserPropsForm", regWithUserPropForm.getInitialComponent());
mainContainer.setPage(VELOCITY_ROOT + "/register_user_props.html");
} else {
state = STATE_NEW_SHIB_USER;
mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
}
} else {
// offer identity migration, if OLAT provider exists
Authentication auth = secMgr.findAuthentication(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier());
if (auth == null) {
// no OLAT provider, migration not possible...
getWindowControl().setError(translator.translate("sr.error.loginexists", new String[] { WebappHelper.getMailConfig("mailSupport") }));
} else {
// OLAT provider exists, offer migration...
migrationForm = new ShibbolethMigrationForm(ureq, getWindowControl(), auth);
migrationForm.addControllerListener(this);
mainContainer.put("migrationForm", migrationForm.getInitialComponent());
mainContainer.setPage(VELOCITY_ROOT + "/migration.html");
}
}
}
} else if (source == languageChooserController) {
if (event == Event.DONE_EVENT) {
// language choosed
mainContainer.setPage(VELOCITY_ROOT + "/register.html");
ureq.getUserSession().removeEntry(LocaleNegotiator.NEGOTIATED_LOCALE);
} else if (event instanceof LanguageChangedEvent) {
LanguageChangedEvent lcev = (LanguageChangedEvent) event;
translator.setLocale(lcev.getNewLocale());
dclController.changeLocale(lcev.getNewLocale());
}
} else if (source == dclController) {
if (event == Event.DONE_EVENT) {
// disclaimer accepted...
if (state == STATE_NEW_SHIB_USER) {
// ...proceed and create user
String choosenLogin;
if (regForm == null) {
choosenLogin = proposedUsername;
} else {
choosenLogin = regForm.getLogin();
}
// check if login has been taken by another user in the meantime...
BaseSecurity secMgr = BaseSecurityManager.getInstance();
// check if login has been taken by another user in the meantime...
Identity identity = secMgr.findIdentityByName(choosenLogin);
if (identity != null) {
getWindowControl().setError(translator.translate("sr.login.meantimetaken"));
mainContainer.setPage(VELOCITY_ROOT + "/register.html");
state = STATE_UNDEFINED;
return;
}
String email = shibbolethAttributes.getValueForUserPropertyName(UserConstants.EMAIL);
if (!UserManager.getInstance().isEmailAllowed(email)) {
// error, email already exists. should actually not happen if OLAT Authenticator has
// been set after removing shibboleth authenticator
getWindowControl().setError(translator.translate("sr.error.emailexists", new String[] { WebappHelper.getMailConfig("mailSupport") }));
mainContainer.setPage(VELOCITY_ROOT + "/register.html");
state = STATE_UNDEFINED;
return;
}
identity = shibbolethManager.createUser(choosenLogin, shibbolethUniqueID, locale.getLanguage(), shibbolethAttributes);
// tell system that this user did accept the disclaimer
CoreSpringFactory.getImpl(RegistrationManager.class).setHasConfirmedDislaimer(identity);
doLogin(identity, ureq);
return;
} else if (state == STATE_MIGRATED_SHIB_USER) {
// ...proceed and migrate user
// create additional authentication
Authentication auth = migrationForm.getAuthentication();
Identity authenticationedIdentity = auth.getIdentity();
BaseSecurity secMgr = BaseSecurityManager.getInstance();
secMgr.createAndPersistAuthentication(authenticationedIdentity, ShibbolethDispatcher.PROVIDER_SHIB, shibbolethUniqueID, null, null);
// update user profile
shibbolethManager.syncUser(authenticationedIdentity, shibbolethAttributes);
doLogin(authenticationedIdentity, ureq);
return;
}
} else if (event == Event.CANCELLED_EVENT) {
mainContainer.setPage(VELOCITY_ROOT + "/register.html");
getWindowControl().setError(translator.translate("sr.error.disclaimer"));
}
}
}
Aggregations