本文整理汇总了Java中org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId方法的典型用法代码示例。如果您正苦于以下问题:Java Authentication.setAuthenticatedUserId方法的具体用法?Java Authentication.setAuthenticatedUserId怎么用?Java Authentication.setAuthenticatedUserId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.activiti.engine.impl.identity.Authentication
的用法示例。
在下文中一共展示了Authentication.setAuthenticatedUserId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParticipantUserLink
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
@Deployment(resources = "org/activiti/engine/test/api/runtime/IdentityLinksProcess.bpmn20.xml")
public void testParticipantUserLink() {
Authentication.setAuthenticatedUserId(null);
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String processInstanceId = runtimeService
.createProcessInstanceQuery()
.singleResult()
.getId();
runtimeService.addParticipantUser(processInstanceId, "kermit");
List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(processInstanceId);
IdentityLink identityLink = identityLinks.get(0);
assertNull(identityLink.getGroupId());
assertEquals("kermit", identityLink.getUserId());
assertEquals(IdentityLinkType.PARTICIPANT, identityLink.getType());
assertEquals(processInstanceId, identityLink.getProcessInstanceId());
assertEquals(1, identityLinks.size());
runtimeService.deleteParticipantUser(processInstanceId, "kermit");
assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstanceId).size());
}
示例2: onRequestEnd
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) {
// Clean up thread-local app
current.remove();
// Clear authentication context
Authentication.setAuthenticatedUserId(null);
// Callback to the login handler
loginHandler.onRequestEnd(request, response);
if(!isRunning() && !invalidatedSession) {
// Clear the session context, the application has been closed during this request, otherwise
// the application will be stuck on the spring-session scope and will be reused on the next
// request, which will lead to problems
if(request.getSession(false) != null) {
request.getSession().invalidate();
invalidatedSession = true;
}
}
}
示例3: testCustomTypeUserLink
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
@Deployment(resources = "org/activiti/engine/test/api/runtime/IdentityLinksProcess.bpmn20.xml")
public void testCustomTypeUserLink() {
Authentication.setAuthenticatedUserId(null);
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String processInstanceId = runtimeService
.createProcessInstanceQuery()
.singleResult()
.getId();
runtimeService.addUserIdentityLink(processInstanceId, "kermit", "interestee");
List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(processInstanceId);
IdentityLink identityLink = identityLinks.get(0);
assertNull(identityLink.getGroupId());
assertEquals("kermit", identityLink.getUserId());
assertEquals("interestee", identityLink.getType());
assertEquals(processInstanceId, identityLink.getProcessInstanceId());
assertEquals(1, identityLinks.size());
runtimeService.deleteUserIdentityLink(processInstanceId, "kermit", "interestee");
assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstanceId).size());
}
示例4: testCustomLinkGroupLink
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
@Deployment(resources = "org/activiti/engine/test/api/runtime/IdentityLinksProcess.bpmn20.xml")
public void testCustomLinkGroupLink() {
Authentication.setAuthenticatedUserId(null);
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String processInstanceId = runtimeService
.createProcessInstanceQuery()
.singleResult()
.getId();
runtimeService.addGroupIdentityLink(processInstanceId, "muppets", "playing");
List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(processInstanceId);
IdentityLink identityLink = identityLinks.get(0);
assertEquals("muppets", identityLink.getGroupId());
assertNull("kermit", identityLink.getUserId());
assertEquals("playing", identityLink.getType());
assertEquals(processInstanceId, identityLink.getProcessInstanceId());
assertEquals(1, identityLinks.size());
runtimeService.deleteGroupIdentityLink(processInstanceId, "muppets", "playing");
assertEquals(0, runtimeService.getIdentityLinksForProcessInstance(processInstanceId).size());
}
示例5: testProcessInstanceIdentityDeleteCandidateGroupEvents
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
/**
* Check deletion of links on process instances.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceIdentityDeleteCandidateGroupEvents() throws Exception {
Authentication.setAuthenticatedUserId(null);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
// Add identity link
taskService.addCandidateUser(task.getId(), "kermit");
taskService.addCandidateGroup(task.getId(), "sales");
// Three events are received, since the user link on the task also creates an involvement in the process. See previous test
assertEquals(6, listener.getEventsReceived().size());
listener.clearEventsReceived();
taskService.deleteCandidateUser(task.getId(), "kermit");
assertEquals(1, listener.getEventsReceived().size());
listener.clearEventsReceived();
taskService.deleteCandidateGroup(task.getId(), "sales");
assertEquals(1, listener.getEventsReceived().size());
}
示例6: testAuthenticatedUserIdAvailable
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
@Deployment
public void testAuthenticatedUserIdAvailable() {
try {
// Setup authentication
Authentication.setAuthenticatedUserId("frederik");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testAuthenticatedUserIdAvailableProcess");
// Check if the variable that has been set in service-task is the authenticated user
String value = (String) runtimeService.getVariable(processInstance.getId(), "theUser");
assertNotNull(value);
assertEquals("frederik", value);
} finally {
// Cleanup
Authentication.setAuthenticatedUserId(null);
}
}
示例7: endProcessInstance
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
@RequestMapping("workspace-endProcessInstance")
public String endProcessInstance(
@RequestParam("processInstanceId") String processInstanceId) {
Authentication.setAuthenticatedUserId(currentUserHolder.getUserId());
processEngine.getRuntimeService().deleteProcessInstance(
processInstanceId, "人工终止");
return "redirect:/bpm/workspace-listRunningProcessInstances.do";
}
示例8: execute
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
public Void execute(CommandContext commandContext) {
HistoricProcessInstanceEntity historicProcessInstanceEntity = commandContext
.getHistoricProcessInstanceEntityManager()
.findHistoricProcessInstance(historicProcessInstanceId);
if (historicProcessInstanceEntity.getEndTime() == null) {
logger.info("historicProcessInstanceId is running");
return null;
}
historicProcessInstanceEntity.setEndActivityId(null);
historicProcessInstanceEntity.setEndTime(null);
String processDefinitionId = historicProcessInstanceEntity
.getProcessDefinitionId();
String initiator = historicProcessInstanceEntity.getStartUserId();
String businessKey = historicProcessInstanceEntity.getBusinessKey();
ProcessDefinitionEntity processDefinition = new GetDeploymentProcessDefinitionCmd(
processDefinitionId).execute(commandContext);
// ExecutionEntity processInstance = processDefinition
// .createProcessInstance(businessKey);
ExecutionEntity processInstance = this.createProcessInstance(
historicProcessInstanceEntity.getId(), businessKey, initiator,
processDefinition);
try {
Authentication.setAuthenticatedUserId(initiator);
// start
processInstance.start();
} finally {
Authentication.setAuthenticatedUserId(null);
}
return null;
}
示例9: requestRequiresAuthentication
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
@Override
public boolean requestRequiresAuthentication(Request request) {
// Get relevant information from the request
String userId = getUserId(request);
String userId2 = getUserIdFromHeader(request);
String password = getPassword(request);
String apiCalled = getApiCalled(request);
// Check if the user is authorized to perform the operation
ensureUserIsAuthorized(apiCalled, userId);
// If the BASIC authentication header is present and the user is the session user,
// persist the user in the Activiti database
if (userId2 != null && password != null && userId2.equals(userId)) {
persistUser(userId, password);
}
// Set authenticated user id for this Activiti thread
Authentication.setAuthenticatedUserId(userId);
// Update request client info
setRequestClientInfo(request, userId);
// Return false to skip any Activiti-specific authentication
return false;
}
示例10: testProcessInstanceIdentityLinkEvents
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
/**
* Check identity links on process instances.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceIdentityLinkEvents() throws Exception {
Authentication.setAuthenticatedUserId(null);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// Add identity link
runtimeService.addUserIdentityLink(processInstance.getId(), "kermit", "test");
assertEquals(2, listener.getEventsReceived().size());
FlowableEngineEntityEvent event = (FlowableEngineEntityEvent) listener.getEventsReceived().get(0);
assertEquals(FlowableEngineEventType.ENTITY_CREATED, event.getType());
assertTrue(event.getEntity() instanceof IdentityLink);
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
IdentityLink link = (IdentityLink) event.getEntity();
assertEquals("kermit", link.getUserId());
assertEquals("test", link.getType());
event = (FlowableEngineEntityEvent) listener.getEventsReceived().get(1);
assertEquals(FlowableEngineEventType.ENTITY_INITIALIZED, event.getType());
listener.clearEventsReceived();
// Deleting process should delete identity link
runtimeService.deleteProcessInstance(processInstance.getId(), "test");
assertEquals(1, listener.getEventsReceived().size());
event = (FlowableEngineEntityEvent) listener.getEventsReceived().get(0);
assertEquals(FlowableEngineEventType.ENTITY_DELETED, event.getType());
assertTrue(event.getEntity() instanceof IdentityLink);
link = (IdentityLink) event.getEntity();
assertEquals("kermit", link.getUserId());
assertEquals("test", link.getType());
}
示例11: testHistoricIdenityLinksOnProcessInstance
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
@Deployment(resources = { "org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testHistoricIdenityLinksOnProcessInstance() {
Authentication.setAuthenticatedUserId(null);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
runtimeService.addUserIdentityLink(pi.getId(), "kermit", "myType");
// Check historic links
List<HistoricIdentityLink> historicLinks = historyService.getHistoricIdentityLinksForProcessInstance(pi.getId());
assertEquals(1, historicLinks.size());
assertEquals("myType", historicLinks.get(0).getType());
assertEquals("kermit", historicLinks.get(0).getUserId());
assertNull(historicLinks.get(0).getGroupId());
assertEquals(pi.getId(), historicLinks.get(0).getProcessInstanceId());
// When process is ended, link should remain
taskService.complete(taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult().getId());
assertNull(runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult());
assertEquals(1, historyService.getHistoricIdentityLinksForProcessInstance(pi.getId()).size());
// When process is deleted, identitylinks shouldn't exist anymore
historyService.deleteHistoricProcessInstance(pi.getId());
assertEquals(0, historyService.getHistoricIdentityLinksForProcessInstance(pi.getId()).size());
}
}
示例12: onRequestStart
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
public void onRequestStart(HttpServletRequest request, HttpServletResponse response) {
// Set current application object as thread-local to make it easy accessible
current.set(this);
// Authentication: check if user is found, otherwise send to login page
LoggedInUser user = (LoggedInUser) getUser();
if (user == null) {
// First, try automatic login
user = loginHandler.authenticate(request, response);
if(user == null) {
if (mainWindow != null && !mainWindow.isShowingLoginPage()) {
viewManager.showLoginPage();
}
} else {
setUser(user);
}
}
if(user != null) {
Authentication.setAuthenticatedUserId(user.getId());
if (mainWindow != null && mainWindow.isShowingLoginPage()) {
viewManager.showDefaultPage();
}
}
// Callback to the login handler
loginHandler.onRequestStart(request, response);
}
示例13: setUp
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
// Normally the UI will do this automatically for us
Authentication.setAuthenticatedUserId("kermit");
}
示例14: doFilter
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
if (userManagementService.isUserAuthenticated())
Authentication.setAuthenticatedUserId(userManagementService.getCurrentUserLogin());
else
Authentication.setAuthenticatedUserId(null);
chain.doFilter(request, response);
}
示例15: authenticate
import org.activiti.engine.impl.identity.Authentication; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void authenticate(final String login, final String password) {
final Subject subject = SecurityUtils.getSubject();
final UsernamePasswordToken token = new UsernamePasswordToken(login, password);
subject.login(token);
// Логин в Activiti
Authentication.setAuthenticatedUserId(login);
}