use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class RepositoryMailing method sendEmail.
public static void sendEmail(Identity ureqIdentity, Identity identity, RepositoryEntry re, Type type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
String email = identity.getUser().getProperty(UserConstants.EMAIL, null);
String emailAlt = identity.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
if (!StringHelper.containsNonWhitespace(email) && !StringHelper.containsNonWhitespace(emailAlt)) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
RepositoryModule repositoryModule = CoreSpringFactory.getImpl(RepositoryModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!repositoryModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
template = getDefaultTemplate(type, re, ureqIdentity);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[RepositoryEntry:" + re.getKey() + "]");
}
String metaId = mailing == null ? null : mailing.getUuid();
MailerResult result = new MailerResult();
MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailManager.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class PreferencesFormController method initForm.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
* org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("title.prefs");
setFormContextHelp("Configuration#_einstellungen");
// load preferences
Preferences prefs = tobeChangedIdentity.getUser().getPreferences();
// Username
StaticTextElement username = uifactory.addStaticTextElement("form.username", tobeChangedIdentity.getName(), formLayout);
username.setElementCssClass("o_sel_home_settings_username");
username.setEnabled(false);
// Roles
final String[] roleKeys = new String[] { Constants.GROUP_USERMANAGERS, Constants.GROUP_GROUPMANAGERS, Constants.GROUP_POOL_MANAGER, Constants.GROUP_AUTHORS, Constants.GROUP_INST_ORES_MANAGER, Constants.GROUP_ADMIN };
String iname = getIdentity().getUser().getProperty("institutionalName", null);
String ilabel = iname != null ? translate("rightsForm.isInstitutionalResourceManager.institution", iname) : translate("rightsForm.isInstitutionalResourceManager");
final String[] roleValues = new String[] { translate("rightsForm.isUsermanager"), translate("rightsForm.isGroupmanager"), translate("rightsForm.isPoolmanager"), translate("rightsForm.isAuthor"), ilabel, translate("rightsForm.isAdmin") };
final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
String userRoles = "";
List<String> roles = securityManager.getRolesAsString(tobeChangedIdentity);
for (String role : roles) {
for (int i = 0; i < roleKeys.length; i++) {
if (roleKeys[i].equals(role)) {
userRoles = userRoles + roleValues[i] + ", ";
}
}
}
if (userRoles.equals("")) {
userRoles = translate("rightsForm.isAnonymous.false");
} else {
userRoles = userRoles.substring(0, userRoles.lastIndexOf(","));
}
uifactory.addStaticTextElement("rightsForm.roles", userRoles, formLayout);
username.setElementCssClass("o_sel_home_settings_username");
username.setEnabled(false);
// Language
Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
ArrayHelper.sort(langKeys, langValues, false, true, false);
language = uifactory.addDropdownSingleselect("form.language", formLayout, langKeys, langValues, null);
language.setElementCssClass("o_sel_home_settings_language");
String langKey = prefs.getLanguage();
// this server
if (prefs.getLanguage() != null && i18nModule.getEnabledLanguageKeys().contains(langKey)) {
language.select(prefs.getLanguage(), true);
} else {
language.select(I18nModule.getDefaultLocale().toString(), true);
}
// Font size
String[] cssFontsizeValues = new String[] { translate("form.fontsize.xsmall"), translate("form.fontsize.small"), translate("form.fontsize.normal"), translate("form.fontsize.large"), translate("form.fontsize.xlarge"), translate("form.fontsize.presentation") };
fontsize = uifactory.addDropdownSingleselect("form.fontsize", formLayout, cssFontsizeKeys, cssFontsizeValues, null);
fontsize.setElementCssClass("o_sel_home_settings_fontsize");
fontsize.select(prefs.getFontsize(), true);
fontsize.addActionListener(FormEvent.ONCHANGE);
// Email notification interval
NotificationsManager nMgr = NotificationsManager.getInstance();
List<String> intervals = nMgr.getEnabledNotificationIntervals();
if (intervals.size() > 0) {
String[] intervalKeys = new String[intervals.size()];
intervals.toArray(intervalKeys);
String[] intervalValues = new String[intervalKeys.length];
String i18nPrefix = "interval.";
for (int i = 0; i < intervalKeys.length; i++) {
intervalValues[i] = translate(i18nPrefix + intervalKeys[i]);
}
notificationInterval = uifactory.addDropdownSingleselect("form.notification", formLayout, intervalKeys, intervalValues, null);
notificationInterval.setElementCssClass("o_sel_home_settings_notification_interval");
notificationInterval.select(prefs.getNotificationInterval(), true);
}
// fxdiff VCRP-16: intern mail system
MailModule mailModule = (MailModule) CoreSpringFactory.getBean("mailModule");
if (mailModule.isInternSystem()) {
String userEmail = UserManager.getInstance().getUserDisplayEmail(tobeChangedIdentity, ureq.getLocale());
String[] mailInternLabels = new String[] { translate("mail." + mailIntern[0], userEmail), translate("mail." + mailIntern[1], userEmail) };
mailSystem = uifactory.addRadiosVertical("mail-system", "mail.system", formLayout, mailIntern, mailInternLabels);
mailSystem.setElementCssClass("o_sel_home_settings_mail");
String mailPrefs = prefs.getReceiveRealMail();
if (StringHelper.containsNonWhitespace(mailPrefs)) {
if ("true".equals(mailPrefs)) {
mailSystem.select(mailIntern[1], true);
} else {
mailSystem.select(mailIntern[0], true);
}
} else if (mailModule.isReceiveRealMailUserDefaultSetting()) {
mailSystem.select(mailIntern[1], true);
} else {
mailSystem.select(mailIntern[0], true);
}
}
// Text encoding
Map<String, Charset> charsets = Charset.availableCharsets();
String currentCharset = UserManager.getInstance().getUserCharset(tobeChangedIdentity);
String[] csKeys = StringHelper.getMapKeysAsStringArray(charsets);
charset = uifactory.addDropdownSingleselect("form.charset", formLayout, csKeys, csKeys, null);
charset.setElementCssClass("o_sel_home_settings_charset");
if (currentCharset != null) {
for (String csKey : csKeys) {
if (csKey.equals(currentCharset)) {
charset.select(currentCharset, true);
}
}
}
if (!charset.isOneSelected() && charsets.containsKey("UTF-8")) {
charset.select("UTF-8", true);
}
// Submit and cancel buttons
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
buttonLayout.setElementCssClass("o_sel_home_settings_prefs_buttons");
uifactory.addFormSubmitButton("submit", buttonLayout);
uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class UserTest method setup.
/**
* @see junit.framework.TestCase#setUp()
*/
@Before
public void setup() throws Exception {
System.out.println("running before...: " + this.hashCode());
// create some users with user manager
// set up fixture using the user manager
UserManager um = UserManager.getInstance();
BaseSecurity sm = BaseSecurityManager.getInstance();
if (sm.findIdentityByName("judihui") == null) {
u1 = um.createUser("judihui", "judihui", "judihui@id.uzh.ch");
u1.setProperty(UserConstants.INSTITUTIONALEMAIL, "instjudihui@id.uzh.ch");
u1.setProperty(UserConstants.INSTITUTIONALNAME, "id.uzh.ch");
u1.setProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, "id.uzh.ch");
i1 = sm.createAndPersistIdentityAndUser(u1.getProperty(UserConstants.LASTNAME, new Locale("en")), null, u1, "OLAT", u1.getProperty(UserConstants.LASTNAME, new Locale("en")), "");
} else {
System.out.println("Does not create user, found 'judihui' already in db");
i1 = sm.findIdentityByName("judihui");
u1 = i1.getUser();
}
if (sm.findIdentityByName("migros") == null) {
u2 = um.createUser("migros", "migros", "migros@id.migros.uzh.ch");
u2.setProperty(UserConstants.INSTITUTIONALEMAIL, "instmigros@id.migros.uzh.ch");
u2.setProperty(UserConstants.INSTITUTIONALNAME, "id.migros.uzh.ch");
u2.setProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, "id.uzh.ch");
i2 = sm.createAndPersistIdentityAndUser(u2.getProperty(UserConstants.LASTNAME, new Locale("en")), null, u2, "OLAT", u2.getProperty(UserConstants.LASTNAME, new Locale("en")), "");
} else {
System.out.println("Does not create user, found 'migros' already in db");
i2 = sm.findIdentityByName("migros");
u2 = i2.getUser();
}
if (sm.findIdentityByName("salat") == null) {
u3 = um.createUser("salat", "salat", "salat@id.salat.uzh.ch");
u3.setProperty(UserConstants.INSTITUTIONALEMAIL, "instsalat@id.salat.uzh.ch");
u3.setProperty(UserConstants.INSTITUTIONALNAME, "id.salat.uzh.ch");
u3.setProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, "id.uzh.ch");
i3 = sm.createAndPersistIdentityAndUser(u3.getProperty(UserConstants.LASTNAME, new Locale("en")), null, u3, " OLAT", u3.getProperty(UserConstants.LASTNAME, new Locale("en")), "");
} else {
System.out.println("Does not create user, found 'salat' already in db");
i3 = sm.findIdentityByName("salat");
u3 = i3.getUser();
}
}
use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.
the class BusinessGroupMailing method sendEmail.
protected static void sendEmail(Identity ureqIdentity, Identity identity, BusinessGroupShort group, MailType type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
BusinessGroupModule groupModule = CoreSpringFactory.getImpl(BusinessGroupModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!groupModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
// booking by myself
if (type != null && type == MailType.addParticipant && ureqIdentity != null && ureqIdentity.equals(identity)) {
template = BGMailHelper.createAddMyselfMailTemplate(group, ureqIdentity);
} else {
template = getDefaultTemplate(type, group, ureqIdentity);
}
} else if (group != null && template.getContext() != null && needTemplateEnhancement(template)) {
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
template = new MailTemplateDelegate(template, group, repoEntries);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[BusinessGroup:" + group.getKey() + "]");
}
MailerResult result = new MailerResult();
String metaId = mailing != null ? mailing.getUuid() : null;
MailManager mailService = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailService.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailService.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class NotificationsWebService method subscribe.
@PUT
@Path("subscribers")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response subscribe(PublisherVO publisherVO, @Context HttpServletRequest request) {
if (!isAdmin(request)) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
NotificationsManager notificationsMgr = NotificationsManager.getInstance();
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
SubscriptionContext subscriptionContext = new SubscriptionContext(publisherVO.getResName(), publisherVO.getResId(), publisherVO.getSubidentifier());
PublisherData publisherData = new PublisherData(publisherVO.getType(), publisherVO.getData(), publisherVO.getBusinessPath());
List<UserVO> userVoes = publisherVO.getUsers();
List<Long> identityKeys = new ArrayList<>();
for (UserVO userVo : userVoes) {
identityKeys.add(userVo.getKey());
}
List<Identity> identities = securityManager.loadIdentityByKeys(identityKeys);
notificationsMgr.subscribe(identities, subscriptionContext, publisherData);
return Response.ok().build();
}
Aggregations