• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SecurityHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.ligoj.bootstrap.core.security.SecurityHelper的典型用法代码示例。如果您正苦于以下问题:Java SecurityHelper类的具体用法?Java SecurityHelper怎么用?Java SecurityHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SecurityHelper类属于org.ligoj.bootstrap.core.security包,在下文中一共展示了SecurityHelper类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: executeInternal

import org.ligoj.bootstrap.core.security.SecurityHelper; //导入依赖的package包/类
@Override
protected void executeInternal(final JobExecutionContext arg0) throws JobExecutionException {
	// Extract the job data to execute the operation
	final int schedule = arg0.getMergedJobDataMap().getInt("schedule");
	final ApplicationContext context = ObjectUtils.defaultIfNull((ApplicationContext) arg0.getMergedJobDataMap().get("context"),
			SpringUtils.getApplicationContext());
	final VmSchedule entity = context.getBean(VmScheduleRepository.class).findOneExpected(schedule);
	log.info("Executing {} for schedule {}, subscription {}", entity.getOperation(), entity.getId(), entity.getSubscription().getId());

	// Set the user
	context.getBean(SecurityHelper.class).setUserName(SecurityHelper.SYSTEM_USERNAME);

	// Execute the operation
	context.getBean(VmResource.class).execute(entity.getSubscription(), entity.getOperation());
	log.info("Succeed {} for schedule {}, subscription {}", entity.getOperation(), entity.getId(), entity.getSubscription().getId());
}
 
开发者ID:ligoj,项目名称:plugin-vm,代码行数:17,代码来源:VmJob.java


示例2: setup

import org.ligoj.bootstrap.core.security.SecurityHelper; //导入依赖的package包/类
@Before
public void setup() {
	task = new UserAtomicLdapTask();
	task.resource = Mockito.mock(UserOrgResource.class);
	task.securityHelper = new SecurityHelper();
	initSpringSecurityContext(DEFAULT_USER);

	final UserOrg user = new UserOrg();
	user.setCompany("untouched");
	user.setDepartment("untouched");
	user.setFirstName("untouched");
	user.setLastName("untouched");
	user.setName(DEFAULT_USER);
	user.setLocalId("untouched");
	user.setMails(new ArrayList<>());
	user.setGroups(new ArrayList<>());
	Mockito.when(task.resource.findById(DEFAULT_USER)).thenReturn(user);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:19,代码来源:UserAtomicLdapTaskTest.java


示例3: testAuditUpdate

import org.ligoj.bootstrap.core.security.SecurityHelper; //导入依赖的package包/类
/**
 * Updated entity test
 */
@Test
public void testAuditUpdate() throws InterruptedException {
	final SystemBench entity = new SystemBench();
	em.persist(entity);
	em.flush();
	Thread.sleep(200); // NOSONAR -- Have to pause the thread for the test
	SecurityContextHolder.clearContext();
	entity.setPrfBool(true);
	em.flush();
	Assert.assertEquals(DEFAULT_USER, entity.getCreatedBy());
	Assert.assertNotNull(entity.getCreatedDate());
	Assert.assertEquals(SecurityHelper.SYSTEM_USERNAME, entity.getLastModifiedBy());
	Assert.assertNotNull(entity.getLastModifiedDate());
	Assert.assertNotEquals(entity.getLastModifiedDate(),entity.getCreatedDate());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:19,代码来源:AuditableTest.java


示例4: setup

import org.ligoj.bootstrap.core.security.SecurityHelper; //导入依赖的package包/类
@Before
public void setup() {
	task = new UserFullLdapTask();
	task.resource = Mockito.mock(UserOrgResource.class);
	task.securityHelper = new SecurityHelper();
	task.jaxrsFactory = ServerProviderFactory.getInstance();
	initSpringSecurityContext(DEFAULT_USER);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:9,代码来源:UserFullLdapTaskTest.java


示例5: testAuditCreate

import org.ligoj.bootstrap.core.security.SecurityHelper; //导入依赖的package包/类
/**
 * Persisted entity test
 */
@Test
public void testAuditCreate() {
	SecurityContextHolder.clearContext();
	final SystemBench entity = new SystemBench();
	em.persist(entity);
	em.flush();
	Assert.assertEquals(SecurityHelper.SYSTEM_USERNAME, entity.getCreatedBy());
	Assert.assertNotNull(entity.getCreatedDate());
	Assert.assertEquals(SecurityHelper.SYSTEM_USERNAME, entity.getLastModifiedBy());
	Assert.assertNotNull(entity.getLastModifiedDate());
	Assert.assertEquals(entity.getLastModifiedDate(), entity.getCreatedDate());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:16,代码来源:AuditableTest.java


示例6: testAuditUpdateWithNew

import org.ligoj.bootstrap.core.security.SecurityHelper; //导入依赖的package包/类
/**
 * Updated entity test
 */
@Test
public void testAuditUpdateWithNew() throws InterruptedException {
	
	// Initial save
	final SystemBench entity = new SystemBench();
	em.persist(entity);
	em.flush();
	em.clear();
	Thread.sleep(200); // NOSONAR -- Have to pause the thread for the test

	// Update from a new instance
	SecurityContextHolder.clearContext();
	SystemBench entityUpdate = new SystemBench();
	entityUpdate.setId(entity.getId().intValue());
	entityUpdate.setPrfBool(true);
	em.merge(entityUpdate);
	em.flush();
	em.clear();

	// Reload the entity to check the state
	entityUpdate = em.find(SystemBench.class,entity.getId());
	Assert.assertEquals(DEFAULT_USER, entityUpdate.getCreatedBy());
	Assert.assertNotNull(entityUpdate.getCreatedDate());
	Assert.assertEquals(SecurityHelper.SYSTEM_USERNAME, entityUpdate.getLastModifiedBy());
	Assert.assertNotNull(entityUpdate.getLastModifiedDate());
	Assert.assertNotEquals(entityUpdate.getLastModifiedDate(),entityUpdate.getCreatedDate());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:31,代码来源:AuditableTest.java


示例7: createAndUpdateSchedule

import org.ligoj.bootstrap.core.security.SecurityHelper; //导入依赖的package包/类
@Test
public void createAndUpdateSchedule() throws Exception {
	final ApplicationContext mockContext = Mockito.mock(ApplicationContext.class);
	final VmScheduleRepository vmScheduleRepository = Mockito.mock(VmScheduleRepository.class);
	final VmResource mockResource = Mockito.mock(VmResource.class);
	final Subscription entity = this.subscriptionRepository.findOneExpected(subscription);
	Mockito.when(mockContext.getBean(VmScheduleRepository.class)).thenReturn(vmScheduleRepository);
	Mockito.when(mockContext.getBean(SecurityHelper.class)).thenReturn(Mockito.mock(SecurityHelper.class));
	Mockito.when(mockContext.getBean(VmResource.class)).thenReturn(mockResource);

	final StdScheduler scheduler = (StdScheduler) vmSchedulerFactoryBean.getScheduler();
	final QuartzScheduler qscheduler = (QuartzScheduler) FieldUtils.getField(StdScheduler.class, "sched", true).get(scheduler);
	final QuartzSchedulerResources resources = (QuartzSchedulerResources) FieldUtils.getField(QuartzScheduler.class, "resources", true)
			.get(qscheduler);
	final JobDetail jobDetail = scheduler.getJobDetail(scheduler.getJobKeys(GroupMatcher.anyJobGroup()).iterator().next());

	// "ON" call would fail
	Mockito.doThrow(new RuntimeException()).when(mockResource).execute(entity, VmOperation.ON);

	try {
		// Mock the factory
		jobDetail.getJobDataMap().put("context", mockContext);
		((RAMJobStore) resources.getJobStore()).storeJob(jobDetail, true);

		Assert.assertEquals(1, this.vmScheduleRepository.findAll().size());

		// Schedule all operations within the next 2 seconds
		final String cron = "" + ((DateUtils.newCalendar().get(Calendar.SECOND) + 2) % 60) + " * * * * ?";
		final int id = mockSchedule(vmScheduleRepository, resource.createSchedule(newSchedule(cron, VmOperation.OFF)));
		mockSchedule(vmScheduleRepository, resource.createSchedule(newSchedule(cron + " *", VmOperation.ON)));
		Assert.assertEquals(3, this.vmScheduleRepository.findAll().size());

		// Yield for the schedules
		Thread.sleep(2500);

		// Check the executions
		Mockito.verify(mockResource).execute(entity, VmOperation.OFF);
		Mockito.verify(mockResource).execute(entity, VmOperation.ON); // Failed
		Mockito.verify(mockResource, Mockito.never()).execute(entity, VmOperation.REBOOT);
		Mockito.verify(mockResource, Mockito.never()).execute(entity, VmOperation.RESET);
		Mockito.verify(mockResource, Mockito.never()).execute(entity, VmOperation.SHUTDOWN);
		Mockito.verify(mockResource, Mockito.never()).execute(entity, VmOperation.SUSPEND);

		// Update the CRON and the operation
		final VmScheduleVo vo = newSchedule("" + ((DateUtils.newCalendar().get(Calendar.SECOND) + 2) % 60) + " * * * * ?",
				VmOperation.SHUTDOWN);
		vo.setId(id);
		vo.setSubscription(subscription);
		resource.updateSchedule(vo);
		Assert.assertEquals(3, this.vmScheduleRepository.findAll().size());

		// Yield for the schedules
		Thread.sleep(2500);
		Mockito.verify(mockResource).execute(entity, VmOperation.SHUTDOWN);
	} finally {
		// Restore the factory's context
		jobDetail.getJobDataMap().put("context", applicationContext);
		((RAMJobStore) resources.getJobStore()).storeJob(jobDetail, true);
	}
}
 
开发者ID:ligoj,项目名称:plugin-vm,代码行数:61,代码来源:VmResourceTest.java



注:本文中的org.ligoj.bootstrap.core.security.SecurityHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WindowedMean类代码示例发布时间:2022-05-22
下一篇:
Java VisibleForTesting类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap