use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class MarkController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == markLink) {
Identity identity = ureq.getIdentity();
if (marked) {
if (mark == null) {
markingService.getMarkManager().removeMark(ores, ureq.getIdentity(), subPath);
} else {
markingService.getMarkManager().removeMark(mark);
mark = null;
}
} else {
mark = markingService.getMarkManager().setMark(ores, identity, subPath, businessPath);
}
marked = !marked;
markLink.setIconLeftCSS(marked ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
}
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class WebDAVAuthManager method authenticate.
@Override
public Identity authenticate(Identity identity, String login, String password) {
List<String> providers = new ArrayList<>(3);
providers.add(PROVIDER_WEBDAV);
if (userModule.isEmailUnique()) {
providers.add(PROVIDER_HA1_EMAIL);
providers.add(PROVIDER_HA1_INSTITUTIONAL_EMAIL);
}
List<Authentication> authentications = null;
if (identity != null) {
authentications = securityManager.findAuthentications(identity, providers);
} else {
authentications = securityManager.findAuthenticationByAuthusername(login, providers);
}
if (authentications == null || authentications.isEmpty()) {
// fallback to standard OLAT authentication
return olatAuthenticationSpi.authenticate(identity, login, password);
}
Identity authenticatedIdentity = authentications.get(0).getIdentity();
boolean visible = securityManager.isIdentityVisible(authenticatedIdentity);
if (!visible) {
return null;
}
for (Authentication authentication : authentications) {
if (securityManager.checkCredentials(authentication, password)) {
Algorithm algorithm = Algorithm.find(authentication.getAlgorithm());
if (Algorithm.md5.equals(algorithm)) {
authentication = securityManager.updateCredentials(authentication, password, loginModule.getDefaultHashAlgorithm());
}
return authentication.getIdentity();
}
}
return null;
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class WebDAVAuthManager method updateWebDAVPassword.
private void updateWebDAVPassword(Identity doer, Identity identity, String authUsername, String password, String provider, List<Authentication> authentications) {
Authentication authentication = getAndRemoveAuthentication(provider, authentications);
if (authentication == null) {
// create new authentication for provider OLAT
try {
dbInstance.commit();
Identity reloadedIdentity = securityManager.loadIdentityByKey(identity.getKey());
securityManager.createAndPersistAuthentication(reloadedIdentity, provider, authUsername, password, loginModule.getDefaultHashAlgorithm());
log.audit(doer.getName() + " created new WebDAV authentication for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (DBRuntimeException e) {
log.error("Cannot create webdav password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
} else {
try {
dbInstance.commit();
securityManager.updateCredentials(authentication, password, loginModule.getDefaultHashAlgorithm());
log.audit(doer.getName() + " set new WebDAV password for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (Exception e) {
log.error("Cannot update webdav password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
}
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class UserSession method valueUnbound.
/**
* called when the session is invalidated either by app. server timeout or manual session.invalidate (logout)
*
* @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
*/
@Override
public void valueUnbound(HttpSessionBindingEvent be) {
try {
// the identity can be null if an loginscreen only session gets invalidated
// (no user was authenticated yet but a tomcat session was created)
Identity ident = identityEnvironment.getIdentity();
CoreSpringFactory.getImpl(UserSessionManager.class).signOffAndClear(this);
if (log.isDebug()) {
log.debug("Closed UserSession: identity = " + (ident == null ? "n/a" : ident.getName()));
}
// -> in this case we use the special empty activity logger
if (ident == null) {
ThreadLocalUserActivityLoggerInstaller.initEmptyUserActivityLogger();
}
} catch (Exception e) {
log.error("exception while session was unbound!", e);
} finally // called by tomcat's timer thread -> we need to close!! since the next unbound will be called from the same tomcat-thread
{
// o_clusterNOK: put into managed transaction wrapper
DBFactory.getInstance().commitAndCloseSession();
}
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class UserActivityLoggerImpl method log.
@Override
public void log(ILoggingAction loggingAction, Class<?> callingClass, ILoggingResourceable... lriOrNull) {
Long logStart = null;
if (log_.isDebug()) {
logStart = System.currentTimeMillis();
}
final ActionType actionType = stickyActionType_ != null ? stickyActionType_ : loggingAction.getResourceActionType();
// don't log entries with loggingAction type 'tracking'
if (isLogAnonymous_ && actionType.equals(ActionType.tracking)) {
return;
}
// fetch some of the loggingAction fields - used for error logging below
final CrudAction crudAction = loggingAction.getCrudAction();
final ActionVerb actionVerb = loggingAction.getActionVerb();
final String actionObject = loggingAction.getActionObject();
// calculate the combined and ordered list of LoggingResourceables which should go
// to the database below right away
List<ILoggingResourceable> resourceInfos = getCombinedOrderedLoggingResourceables(lriOrNull);
if (session_ == null) {
// then I can't log - log information without session/user information isn't of much use
// issue a log warn with a stacktrace for this
log_.error("No session available to UserActivityLogger. Cannot write log entry: " + crudAction.name() + ":" + actionVerb.name() + ", " + actionObject + ", " + convertLoggingResourceableListToString(resourceInfos), new Exception());
return;
}
final String sessionId;
if (session_.getSessionInfo() != null && session_.getSessionInfo().getSession() == null) {
// background taks
sessionId = Thread.currentThread().getName();
} else if (session_.getSessionInfo() == null) {
// no session Id available - odd
log_.error("No session information available to UserActivityLogger. Cannot write log entry: " + crudAction.name() + ":" + actionVerb.name() + ", " + actionObject + ", " + convertLoggingResourceableListToString(resourceInfos), new Exception());
return;
} else {
sessionId = Long.toString(session_.getSessionInfo().getCreationTime());
}
Identity identity = session_.getIdentity();
if (identity == null) {
// no identity available - odd
log_.error("No identity available to UserActivityLogger. Cannot write log entry: " + crudAction.name() + ":" + actionVerb.name() + ", " + actionObject + ", " + convertLoggingResourceableListToString(resourceInfos), new Exception());
return;
}
Long identityKey = identity.getKey();
if (actionType != ActionType.admin) {
final String identityKeyStr = String.valueOf(identityKey);
for (Iterator<ILoggingResourceable> it = resourceInfos.iterator(); it.hasNext(); ) {
ILoggingResourceable lr = it.next();
// we want this info as too much actionTypes are non-admin and log-entry will then be without value not containing targetIdent!, see FXOLAT-104
if (lr.getResourceableType() == StringResourceableType.targetIdentity && lr.getId().equals(identityKeyStr)) {
if (log_.isDebug()) {
// complain
final Writer strackTraceAsStringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(strackTraceAsStringWriter);
(new Exception("OLAT-4955 debug stacktrac")).printStackTrace(printWriter);
log_.debug("OLAT-4955: Not storing targetIdentity for non-admin logging actions. A non-admin logging action wanted to store a user other than the one from the session: action=" + loggingAction + ", fieldId=" + loggingAction.getJavaFieldIdForDebug(), strackTraceAsStringWriter.toString());
}
// remove targetIdentity (fxdiff: only if same as executing identity!)
it.remove();
}
}
}
// end of moved code
if (resourceInfos != null) {
// remove all ignorable resources
for (Iterator<ILoggingResourceable> riIterator = resourceInfos.iterator(); riIterator.hasNext(); ) {
if (riIterator.next().isIgnorable()) {
riIterator.remove();
}
}
}
if (loggingAction.getTypeListDefinition() == null) {
// this is a foul!
log_.warn("LoggingAction has no ResourceableTypeList defined: action=" + loggingAction + ", fieldId=" + loggingAction.getJavaFieldIdForDebug());
} else {
// good boy
String errorMsg = loggingAction.getTypeListDefinition().executeCheckAndGetErrorMessage(resourceInfos);
if (errorMsg != null) {
// we found an inconsistency
// lets make this a warn
log_.warn("LoggingAction reported an inconsistency (" + errorMsg + ") while logging: " + loggingAction.getActionVerb() + " " + loggingAction.getActionObject() + ", action=" + loggingAction + ", fieldId=" + loggingAction.getJavaFieldIdForDebug() + ", expected: " + loggingAction.getTypeListDefinition().toString() + ", actual: " + convertLoggingResourceableListToString(resourceInfos), new Exception("OLAT-4653"));
}
}
String identityName;
if (isLogAnonymous_ && (actionType != ActionType.admin)) {
identityName = "";
} else {
identityName = identity.getName();
}
// start creating the LoggingObject
final LoggingObject logObj = new LoggingObject(sessionId, identityKey, identityName, crudAction.name().substring(0, 1), actionVerb.name(), actionObject);
if (resourceInfos != null && resourceInfos.size() != 0) {
if (resourceInfos.size() > 4) {
log_.warn("More than 4 resource infos set on a user activity log. Can only have 4. Having: " + resourceInfos.size());
int diff = resourceInfos.size() - 4;
for (int i = 0; i < diff; i++) {
resourceInfos.remove(3);
}
}
// get the target resourceable
ILoggingResourceable ri = resourceInfos.get(resourceInfos.size() - 1);
logObj.setTargetResourceInfo(ri);
// now set parent - if applicable
if (resourceInfos.size() > 1) {
ri = resourceInfos.get(resourceInfos.size() - 2);
logObj.setParentResourceInfo(ri);
}
// and set the grand parent - if applicable
if (resourceInfos.size() > 2) {
ri = resourceInfos.get(resourceInfos.size() - 3);
logObj.setGrandParentResourceInfo(ri);
}
// and set the great grand parent - if applicable
if (resourceInfos.size() > 3) {
ri = resourceInfos.get(resourceInfos.size() - 4);
logObj.setGreatGrandParentResourceInfo(ri);
}
}
// fill the remaining fields
logObj.setBusinessPath(businessPath_);
logObj.setSourceClass(callingClass.getCanonicalName());
logObj.setResourceAdminAction(actionType.equals(ActionType.admin) ? true : false);
Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
// prepare the user properties, set them at once
List<String> tmpUserProperties = new ArrayList<>(12);
for (Iterator<String> iterator = userProperties_.iterator(); iterator.hasNext(); ) {
String userPropString = identity.getUser().getPropertyOrIdentityEnvAttribute(iterator.next(), locale);
boolean shorten = false;
try {
if (userPropString != null && userPropString.getBytes("UTF-8").length > 254) {
shorten = true;
}
} catch (UnsupportedEncodingException uee) {
log_.error("error while calculating real string length: unsupported encoding: ", uee);
shorten = true;
}
if (shorten) {
log_.error("Userproperty was too long for logging-table (shortened automatically). check that nothing valueable is lost! value before cut: " + userPropString);
userPropString = userPropString.substring(0, 255);
}
tmpUserProperties.add(userPropString);
}
logObj.setUserProperties(tmpUserProperties);
// and store it
DB db = DBFactory.getInstance();
if (db != null && db.isError()) {
// then we would run into an ERROR when we'd do more with this DB
// hence we just issue a log.info here with the details
// @TODO: lower to log_.info once we checked that it doesn't occur very often (best for 6.4)
log_.warn("log: DB is in Error state therefore the UserActivityLoggerImpl cannot store the following logging action into the loggingtable: " + logObj);
} else {
DBFactory.getInstance().saveObject(logObj);
}
if (log_.isDebug()) {
Long logEnd = System.currentTimeMillis();
log_.debug("log duration = " + (logEnd - logStart));
}
}
Aggregations