use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
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 klemens.
the class FeedMediaDispatcher method validAuthentication.
/**
* Authenticates the identity by token
*
* @param identity
* @param token
* @return True if authentication is valid
*/
private boolean validAuthentication(Identity identity, String token) {
boolean valid = false;
BaseSecurity secMgr = BaseSecurityManager.getInstance();
Authentication authentication = secMgr.findAuthenticationByAuthusername(identity.getKey().toString(), TOKEN_PROVIDER);
if (authentication != null && authentication.getCredential().equals(token)) {
valid = true;
}
return valid;
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
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"));
}
}
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class JunitTestHelper method createAndPersistIdentityAsAuthor.
/**
* Create an identity with author permissions
* @param login
* @return
*/
public static final Identity createAndPersistIdentityAsAuthor(String login) {
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity identity = securityManager.findIdentityByName(login);
if (identity != null)
return identity;
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
if (group == null)
group = securityManager.createAndPersistNamedSecurityGroup(Constants.GROUP_AUTHORS);
User user = UserManager.getInstance().createUser("first" + login, "last" + login, login + "@" + maildomain);
identity = securityManager.createAndPersistIdentityAndUser(login, null, user, BaseSecurityModule.getDefaultAuthProviderIdentifier(), login, PWD);
securityManager.addIdentityToSecurityGroup(identity, group);
return identity;
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class JunitTestHelper method createAndPersistIdentityAsAdmin.
/**
* Create an identity with admin permissions
* @param login
* @return
*/
public static final Identity createAndPersistIdentityAsAdmin(String login) {
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity identity = securityManager.findIdentityByName(login);
if (identity != null)
return identity;
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
if (group == null)
group = securityManager.createAndPersistNamedSecurityGroup(Constants.GROUP_ADMIN);
User user = UserManager.getInstance().createUser("first" + login, "last" + login, login + "@" + maildomain);
identity = securityManager.createAndPersistIdentityAndUser(login, null, user, BaseSecurityModule.getDefaultAuthProviderIdentifier(), login, PWD);
securityManager.addIdentityToSecurityGroup(identity, group);
return identity;
}
Aggregations