本文整理了Java中org.sakaiproject.tool.api.Session.setUserId()
方法的一些代码示例,展示了Session.setUserId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.setUserId()
方法的具体详情如下:
包路径:org.sakaiproject.tool.api.Session
类名称:Session
方法名:setUserId
[英]Set the user id associated with this session.
[中]设置与此会话关联的用户id。
代码示例来源:origin: sakaiproject/sakai
private void logIn() {
Session sakaiSession = sessionManager.getCurrentSession();
sakaiSession.setUserId("admin");
sakaiSession.setUserEid("admin");
}
代码示例来源:origin: org.sakaiproject.samigo/samigo-services
private void logIn() {
Session sakaiSession = sessionManager.getCurrentSession();
sakaiSession.setUserId("admin");
sakaiSession.setUserEid("admin");
}
代码示例来源:origin: sakaiproject/sakai
/**
* implement the quartz job interface, which is called by the scheduler when a trigger associated with the job fires.
* this quartz job removes course sites that are more than a specified number of terms old.
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
synchronized (this) {
log.info("execute()");
if (user == null) {
log.error("The scheduled job to remove course sites can not be run with an invalid user. No courses were published.");
} else {
try {
// switch the current user to the one specified to run the quartz job
Session sakaiSesson = sessionManager.getCurrentSession();
sakaiSesson.setUserId(user.getId());
int numSitesPublished = courseSitePublishService.publishCourseSites(numDaysBeforeTermStarts);
log.info(numSitesPublished + " course sites were published.");
} catch (Exception ex) {
log.error(ex.getMessage());
}
}
}
}
代码示例来源:origin: org.sakaiproject.scheduler/scheduler-component-shared
/**
* implement the quartz job interface, which is called by the scheduler when a trigger associated with the job fires.
* this quartz job removes course sites that are more than a specified number of terms old.
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
synchronized (this) {
log.info("execute()");
if (user == null) {
log.error("The scheduled job to remove course sites can not be run with an invalid user. No courses were removed.");
} else {
try {
// switch the current user to the one specified to run the quartz job
Session sakaiSesson = sessionManager.getCurrentSession();
sakaiSesson.setUserId(user.getId());
int numSitesRemoved = courseSiteRemovalService.removeCourseSites(action, numDaysAfterTermEnds);
log.info(numSitesRemoved + " course sites were removed.");
} catch (Exception ex) {
log.error(ex.getMessage());
}
}
}
}
代码示例来源:origin: org.sakaiproject.scheduler/scheduler-component-shared
/**
* implement the quartz job interface, which is called by the scheduler when a trigger associated with the job fires.
* this quartz job removes course sites that are more than a specified number of terms old.
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
synchronized (this) {
log.info("execute()");
if (user == null) {
log.error("The scheduled job to remove course sites can not be run with an invalid user. No courses were published.");
} else {
try {
// switch the current user to the one specified to run the quartz job
Session sakaiSesson = sessionManager.getCurrentSession();
sakaiSesson.setUserId(user.getId());
int numSitesPublished = courseSitePublishService.publishCourseSites(numDaysBeforeTermStarts);
log.info(numSitesPublished + " course sites were published.");
} catch (Exception ex) {
log.error(ex.getMessage());
}
}
}
}
代码示例来源:origin: sakaiproject/sakai
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
if (siteId == null) {
siteId = UUID.randomUUID().toString();
}
log.info("Attempting to import: " + zip+ " into "+ siteId);
Session currentSession = sessionManager.getCurrentSession();
String oldId = currentSession.getUserId();
String oldEid = currentSession.getUserEid();
try {
currentSession.setUserId("admin");
currentSession.setUserEid("admin");
archiveService.mergeFromZip(zip, siteId, null);
} catch (Exception e) {
log.warn("Failed to import " + zip + " to " + siteId + " " + e.getMessage());
} finally {
currentSession.setUserId(oldId);
currentSession.setUserEid(oldEid);
}
}
代码示例来源:origin: sakaiproject/sakai
/**
* implement the quartz job interface, which is called by the scheduler when a trigger associated with the job fires.
* this quartz job removes course sites that are more than a specified number of terms old.
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
synchronized (this) {
log.info("execute()");
String actionStr = CourseSiteRemovalService.Action.remove.equals(action) ? " course sites were removed." : " course sites were unpublished.";
if (user == null) {
log.error("The scheduled job to remove course sites can not be run with an invalid user. No{}", actionStr);
} else {
try {
// switch the current user to the one specified to run the quartz job
Session sakaiSesson = sessionManager.getCurrentSession();
sakaiSesson.setUserId(user.getId());
int numSitesRemoved = courseSiteRemovalService.removeCourseSites(action, numDaysAfterTermEnds);
log.info("{}{}", numSitesRemoved, actionStr);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
}
}
}
代码示例来源:origin: org.sakaiproject.scheduler/scheduler-component-shared
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
if (siteId == null) {
siteId = UUID.randomUUID().toString();
}
log.info("Attempting to import: " + zip+ " into "+ siteId);
Session currentSession = sessionManager.getCurrentSession();
String oldId = currentSession.getUserId();
String oldEid = currentSession.getUserEid();
try {
currentSession.setUserId("admin");
currentSession.setUserEid("admin");
archiveService.mergeFromZip(zip, siteId, null);
} catch (Exception e) {
log.warn("Failed to import " + zip + " to " + siteId + " " + e.getMessage());
} finally {
currentSession.setUserId(oldId);
currentSession.setUserEid(oldEid);
}
}
代码示例来源:origin: sakaiproject/sakai
public void execute(JobExecutionContext arg0) throws JobExecutionException {
Session sakaiSession = sessionManager.getCurrentSession();
sakaiSession.setUserId("admin");
sakaiSession.setUserEid("admin");
contentReviewService.processQueue();
}
}
代码示例来源:origin: org.sakaiproject/sakai-syllabus-impl
protected void loginToSakai() {
Session sakaiSession = SessionManager.getCurrentSession();
sakaiSession.setUserId(userId);
sakaiSession.setUserEid(userId);
// establish the user's session
UsageSessionService.startSession(userId, "127.0.0.1", FixPublicSyllabusAttachmentsJob.class.getName());
// update the user's externally provided realm definitions
authzGroupService.refreshUser(userId);
// post the login event
EventTrackingService.post(EventTrackingService.newEvent(UsageSessionService.EVENT_LOGIN, null, true));
}
代码示例来源:origin: org.sakaiproject.metaobj/sakai-metaobj-impl
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
Session sakaiSession = SessionManager.getCurrentSession();
String userId = sakaiSession.getUserId();
String eId = sakaiSession.getUserEid();
try {
sakaiSession.setUserId("admin");
sakaiSession.setUserEid("admin");
boolean updateSchemaHashes = ServerConfigurationService.getBoolean("metaobj.schemahash.update", false);
getStructuredArtifactDefinitionManager().verifySchemaHashes(updateSchemaHashes);
} finally {
sakaiSession.setUserEid(userId);
sakaiSession.setUserId(eId);
}
}
代码示例来源:origin: sakaiproject/sakai
session = sessionManager.getCurrentSession();
session.setUserEid("admin");
session.setUserId("admin");
List<String> collection_ids = sqlService.dbRead(sql);
totalFolders = collection_ids.size();
代码示例来源:origin: sakaiproject/sakai
public String restoreCurrentUser() {
// switch user session back if it was taken over
Session currentSession = sessionManager.getCurrentSession();
String currentUserId = null;
if (currentSession != null) {
currentUserId = (String) currentSession.getAttribute(CURRENT_USER_MARKER);
if (currentUserId != null) {
currentSession.removeAttribute(CURRENT_USER_MARKER);
currentSession.setUserId(currentUserId);
authzGroupService.refreshUser(currentUserId);
sessionManager.setCurrentSession(currentSession);
}
if ("".equals(currentUserId)) {
currentUserId = null;
}
}
return getUserRefFromUserId(currentUserId);
}
代码示例来源:origin: sakaiproject/sakai
protected void loginToSakai() {
Session sakaiSession = SessionManager.getCurrentSession();
sakaiSession.setUserId("admin");
sakaiSession.setUserEid("admin");
// establish the user's session
UsageSessionService.startSession("admin", "127.0.0.1", "CMSync");
// update the user's externally provided realm definitions
authzGroupService.refreshUser("admin");
// post the login event
EventTrackingService.post(EventTrackingService.newEvent(UsageSessionService.EVENT_LOGIN, null, true));
}
代码示例来源:origin: sakaiproject/sakai
private void loginToSakai() {
Session sakaiSession = SessionManager.getCurrentSession();
sakaiSession.setUserId("admin");
sakaiSession.setUserEid("admin");
// establish the user's session
UsageSessionService.startSession("admin", "127.0.0.1", "CMSync");
// update the user's externally provided realm definitions
authzGroupService.refreshUser("admin");
// post the login event
EventTrackingService.post(EventTrackingService.newEvent(UsageSessionService.EVENT_LOGIN, null, true));
}
代码示例来源:origin: sakaiproject/sakai
try {
session.setUserEid("admin");
session.setUserId("admin");
代码示例来源:origin: sakaiproject/sakai
/**
* <p>Login to sakai and start a user session. This users is intended
* to be one of the 'hard wired' users; admin, postmaster, or synchrobot.</p>
* <p>( this list of users can be extended; add the user via UI, update
* the sakai_users table so their EID matches ID, add them to the
* admin realm, restart )</p>
* @param whoAs - who to log in as
*/
protected void loginToSakai(String whoAs) {
serverName = ServerConfigurationService.getServerName();
log.debug(" AutoSubmitAssessmentsJob Logging into Sakai on " + serverName + " as " + whoAs);
UsageSession session = UsageSessionService.startSession(whoAs, serverName, "AutoSubmitAssessmentsJob");
if (session == null)
{
EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_AUTO_SUBMIT_JOB_ERROR, whoAs + " unable to log into " + serverName, true));
return;
}
Session sakaiSession = SessionManager.getCurrentSession();
sakaiSession.setUserId(whoAs);
sakaiSession.setUserEid(whoAs);
// update the user's externally provided realm definitions
authzGroupService.refreshUser(whoAs);
// post the login events
EventTrackingService.post(EventTrackingService.newEvent(UsageSessionService.EVENT_LOGIN, whoAs + " running " + serverName, true));
}
代码示例来源:origin: sakaiproject/sakai
public String setCurrentUser(String userReference) {
if (userReference == null) {
throw new IllegalArgumentException("userReference cannot be null");
}
String userId = getUserIdFromRef(userReference);
try {
// make sure the user id is valid
userDirectoryService.getUser(userId);
} catch (UserNotDefinedException e) {
throw new IllegalArgumentException("Invalid user reference ("+userReference+"), could not find user");
}
Session currentSession = sessionManager.getCurrentSession();
if (currentSession == null) {
// start a session if none is around
currentSession = sessionManager.startSession(userId);
}
String currentUserId = currentSession.getUserId();
if (currentSession.getAttribute(CURRENT_USER_MARKER) == null) {
// only set this if it is not already set
if (currentUserId == null) {
currentUserId = "";
}
currentSession.setAttribute(CURRENT_USER_MARKER, currentUserId);
}
currentSession.setUserId(userId);
currentSession.setActive();
sessionManager.setCurrentSession(currentSession);
authzGroupService.refreshUser(userId);
return getUserRefFromUserId(currentUserId);
}
代码示例来源:origin: org.sakaiproject.samigo/samigo-services
/**
* <p>Login to sakai and start a user session. This users is intended
* to be one of the 'hard wired' users; admin, postmaster, or synchrobot.</p>
* <p>( this list of users can be extended; add the user via UI, update
* the sakai_users table so their EID matches ID, add them to the
* admin realm, restart )</p>
* @param whoAs - who to log in as
*/
protected void loginToSakai(String whoAs) {
serverName = ServerConfigurationService.getServerName();
log.debug(" AutoSubmitAssessmentsJob Logging into Sakai on " + serverName + " as " + whoAs);
UsageSession session = UsageSessionService.startSession(whoAs, serverName, "AutoSubmitAssessmentsJob");
if (session == null)
{
EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_AUTO_SUBMIT_JOB_ERROR, whoAs + " unable to log into " + serverName, true));
return;
}
Session sakaiSession = SessionManager.getCurrentSession();
sakaiSession.setUserId(whoAs);
sakaiSession.setUserEid(whoAs);
// update the user's externally provided realm definitions
authzGroupService.refreshUser(whoAs);
// post the login events
EventTrackingService.post(EventTrackingService.newEvent(UsageSessionService.EVENT_LOGIN, whoAs + " running " + serverName, true));
}
代码示例来源:origin: sakaiproject/sakai
try {
session.setUserEid("admin");
session.setUserId("admin");
内容来源于网络,如有侵权,请联系作者删除!