use of org.activiti.explorer.identity.LoggedInUser in project Activiti by Activiti.
the class SubTaskComponent method initAddSubTaskPanelKeyboardActions.
protected void initAddSubTaskPanelKeyboardActions() {
addSubTaskPanel.addActionHandler(new Handler() {
public void handleAction(Action action, Object sender, Object target) {
if ("escape".equals(action.getCaption())) {
resetAddButton();
} else if ("enter".equals(action.getCaption())) {
if (newTaskTextField != null && newTaskTextField.getValue() != null && !"".equals(newTaskTextField.getValue().toString())) {
LoggedInUser loggedInUser = ExplorerApp.get().getLoggedInUser();
// save task
Task newTask = taskService.newTask();
newTask.setParentTaskId(parentTask.getId());
if (parentTask.getAssignee() != null) {
newTask.setAssignee(parentTask.getAssignee());
} else {
newTask.setAssignee(loggedInUser.getId());
}
if (parentTask.getOwner() != null) {
newTask.setOwner(parentTask.getOwner());
} else {
newTask.setOwner(loggedInUser.getId());
}
newTask.setName(newTaskTextField.getValue().toString());
taskService.saveTask(newTask);
// Reset the add button to its original state
resetAddButton();
// refresh sub tasks section
refreshSubTasks();
}
}
}
public Action[] getActions(Object target, Object sender) {
return new Action[] { new ShortcutAction("enter", ShortcutAction.KeyCode.ENTER, null), new ShortcutAction("escape", ShortcutAction.KeyCode.ESCAPE, null) };
}
});
}
use of org.activiti.explorer.identity.LoggedInUser in project Activiti by Activiti.
the class MainMenuBar method initProfileButton.
protected void initProfileButton() {
final LoggedInUser user = ExplorerApp.get().getLoggedInUser();
// User name + link to profile
MenuBar profileMenu = new MenuBar();
profileMenu.addStyleName(ExplorerLayout.STYLE_HEADER_PROFILE_BOX);
MenuItem rootItem = profileMenu.addItem(user.getFirstName() + " " + user.getLastName(), null);
rootItem.setStyleName(ExplorerLayout.STYLE_HEADER_PROFILE_MENU);
if (useProfile()) {
// Show profile
rootItem.addItem(i18nManager.getMessage(Messages.PROFILE_SHOW), new Command() {
public void menuSelected(MenuItem selectedItem) {
ExplorerApp.get().getViewManager().showProfilePopup(user.getId());
}
});
// Edit profile
rootItem.addItem(i18nManager.getMessage(Messages.PROFILE_EDIT), new Command() {
public void menuSelected(MenuItem selectedItem) {
// TODO: Show in edit-mode
ExplorerApp.get().getViewManager().showProfilePopup(user.getId());
}
});
// Change password
rootItem.addItem(i18nManager.getMessage(Messages.PASSWORD_CHANGE), new Command() {
public void menuSelected(MenuItem selectedItem) {
ExplorerApp.get().getViewManager().showPopupWindow(new ChangePasswordPopupWindow());
}
});
rootItem.addSeparator();
}
// Logout
rootItem.addItem(i18nManager.getMessage(Messages.HEADER_LOGOUT), new Command() {
public void menuSelected(MenuItem selectedItem) {
ExplorerApp.get().close();
}
});
addComponent(profileMenu);
setComponentAlignment(profileMenu, Alignment.TOP_RIGHT);
setExpandRatio(profileMenu, 1.0f);
}
use of org.activiti.explorer.identity.LoggedInUser in project Activiti by Activiti.
the class DefaultLoginHandler method authenticate.
public LoggedInUserImpl authenticate(String userName, String password) {
LoggedInUserImpl loggedInUser = null;
try {
if (identityService.checkPassword(userName, password)) {
User user = identityService.createUserQuery().userId(userName).singleResult();
// Fetch and cache user data
loggedInUser = new LoggedInUserImpl(user, password);
List<Group> groups = identityService.createGroupQuery().groupMember(user.getId()).list();
for (Group group : groups) {
if (Constants.SECURITY_ROLE.equals(group.getType())) {
loggedInUser.addSecurityRoleGroup(group);
if (Constants.SECURITY_ROLE_USER.equals(group.getId())) {
loggedInUser.setUser(true);
}
if (Constants.SECURITY_ROLE_ADMIN.equals(group.getId())) {
loggedInUser.setAdmin(true);
}
} else if (ExplorerApp.get().getAdminGroups() != null && ExplorerApp.get().getAdminGroups().contains(group.getId())) {
loggedInUser.addSecurityRoleGroup(group);
loggedInUser.setAdmin(true);
} else if (ExplorerApp.get().getUserGroups() != null && ExplorerApp.get().getUserGroups().contains(group.getId())) {
loggedInUser.addSecurityRoleGroup(group);
loggedInUser.setUser(true);
} else {
loggedInUser.addGroup(group);
}
}
}
} catch (Exception e) {
// Do nothing, returning null should be enough
}
return loggedInUser;
}
use of org.activiti.explorer.identity.LoggedInUser in project Activiti by Activiti.
the class TaskMenuBar method initItems.
protected void initItems() {
setWidth("100%");
// TODO: the counts should be done later by eg a Refresher component
// Inbox
long inboxCount = new InboxListQuery().size();
ToolbarEntry inboxEntry = addToolbarEntry(ENTRY_INBOX, i18nManager.getMessage(Messages.TASK_MENU_INBOX), new ToolbarCommand() {
public void toolBarItemSelected() {
viewManager.showInboxPage();
}
});
inboxEntry.setCount(inboxCount);
// Tasks
LoggedInUser user = ExplorerApp.get().getLoggedInUser();
long tasksCount = new TasksListQuery().size();
ToolbarEntry tasksEntry = addToolbarEntry(ENTRY_TASKS, i18nManager.getMessage(Messages.TASK_MENU_TASKS), new ToolbarCommand() {
public void toolBarItemSelected() {
viewManager.showTasksPage();
}
});
tasksEntry.setCount(tasksCount);
// Queued
List<Group> groups = user.getGroups();
ToolbarPopupEntry queuedItem = addPopupEntry(ENTRY_QUEUED, (i18nManager.getMessage(Messages.TASK_MENU_QUEUED)));
long queuedCount = 0;
for (final Group group : groups) {
long groupCount = new QueuedListQuery(group.getId()).size();
queuedItem.addMenuItem(group.getName() + " (" + groupCount + ")", new ToolbarCommand() {
public void toolBarItemSelected() {
viewManager.showQueuedPage(group.getId());
}
});
queuedCount += groupCount;
}
queuedItem.setCount(queuedCount);
// Involved
long involvedCount = new InvolvedListQuery().size();
ToolbarEntry involvedEntry = addToolbarEntry(ENTRY_INVOLVED, i18nManager.getMessage(Messages.TASK_MENU_INVOLVED), new ToolbarCommand() {
public void toolBarItemSelected() {
viewManager.showInvolvedPage();
}
});
involvedEntry.setCount(involvedCount);
// Archived
long archivedCount = new ArchivedListQuery().size();
ToolbarEntry archivedEntry = addToolbarEntry(ENTRY_ARCHIVED, i18nManager.getMessage(Messages.TASK_MENU_ARCHIVED), new ToolbarCommand() {
public void toolBarItemSelected() {
viewManager.showArchivedPage();
}
});
archivedEntry.setCount(archivedCount);
}
use of org.activiti.explorer.identity.LoggedInUser in project Activiti by Activiti.
the class ExplorerApp method onRequestStart.
// HttpServletRequestListener -------------------------------------------------------------------
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);
}
Aggregations