Search in sources :

Example 1 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class LoginBean method login.

// ------------------------------------------------------------------------------
// Action event methods
/**
 * Login action handler
 *
 * @return outcome view name
 */
public String login() {
    String outcome = null;
    FacesContext fc = FacesContext.getCurrentInstance();
    if (this.username != null && this.username.length() != 0 && this.password != null && this.password.length() != 0) {
        try {
            // Perform a full session invalidation to ensure no cached data is left around
            // - important if the login page has been accessed directly rather than via the Login/out action links
            logout();
            // Authenticate via the authentication service, then save the details of user in an object
            // in the session - this is used by the servlet filter etc. on each page to check for login
            this.getAuthenticationService().authenticate(this.username, this.password.toCharArray());
            // Set the user name as stored by the back end
            this.username = this.getAuthenticationService().getCurrentUserName();
            // setup User object and Home space ID
            User user = new User(this.username, this.getAuthenticationService().getCurrentTicket(), getPersonService().getPerson(this.username));
            NodeRef homeSpaceRef = (NodeRef) this.getNodeService().getProperty(getPersonService().getPerson(this.username), ContentModel.PROP_HOMEFOLDER);
            // check that the home space node exists - else user cannot login
            if (homeSpaceRef == null || this.getNodeService().exists(homeSpaceRef) == false) {
                throw new InvalidNodeRefException(homeSpaceRef);
            }
            user.setHomeSpaceId(homeSpaceRef.getId());
            // put the User object in the Session - the authentication servlet will then allow
            // the app to continue without redirecting to the login page
            Application.setCurrentUser(fc, user);
            // Save the current username to cookie
            AuthenticationHelper.setUsernameCookie((HttpServletRequest) fc.getExternalContext().getRequest(), (HttpServletResponse) fc.getExternalContext().getResponse(), this.username);
            // Programatically retrieve the LoginOutcomeBean from JSF
            LoginOutcomeBean loginOutcomeBean = (LoginOutcomeBean) fc.getApplication().createValueBinding("#{LoginOutcomeBean}").getValue(fc);
            // if a redirect URL has been provided then use that
            // this allows servlets etc. to provide a URL to return too after a successful login
            String redirectURL = loginOutcomeBean.getRedirectURL();
            // ALF-10312: Validate we are redirecting within this web app
            if (redirectURL != null && !redirectURL.isEmpty() && !redirectURL.startsWith(fc.getExternalContext().getRequestContextPath())) {
                if (logger.isWarnEnabled())
                    logger.warn("Security violation. Unable to redirect to external location: " + redirectURL);
                redirectURL = null;
            }
            if (redirectURL != null && redirectURL.length() > 0) {
                if (logger.isDebugEnabled())
                    logger.debug("Redirect URL found: " + redirectURL);
                try {
                    fc.getExternalContext().redirect(redirectURL);
                    fc.responseComplete();
                    return null;
                } catch (IOException ioErr) {
                    logger.warn("Unable to redirect to url: " + redirectURL, ioErr);
                }
            } else {
                // special case to handle jump to My Alfresco page initially
                // note: to enable MT runtime client config customization, need to re-init NavigationBean
                // in context of tenant login page
                this.navigator.initFromClientConfig();
                if (NavigationBean.LOCATION_MYALFRESCO.equals(this.preferences.getStartLocation())) {
                    return "myalfresco";
                } else {
                    // generally this will navigate to the generic browse screen
                    return "success";
                }
            }
        } catch (AuthenticationDisallowedException aerr) {
            Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_LOGIN_DISALLOWED));
        } catch (AuthenticationMaxUsersException aerr) {
            Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_LOGIN_MAXUSERS));
        } catch (AuthenticationException aerr) {
            Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_UNKNOWN_USER));
        } catch (InvalidNodeRefException refErr) {
            String msg;
            if (refErr.getNodeRef() != null) {
                msg = refErr.getNodeRef().toString();
            } else {
                msg = Application.getMessage(fc, MSG_NONE);
            }
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(fc, Repository.ERROR_NOHOME), msg));
        }
    } else {
        Utils.addErrorMessage(Application.getMessage(fc, MSG_ERROR_MISSING));
    }
    return outcome;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) User(org.alfresco.web.bean.repository.User) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) AuthenticationDisallowedException(org.alfresco.repo.security.authentication.AuthenticationDisallowedException) AuthenticationMaxUsersException(org.alfresco.repo.security.authentication.AuthenticationMaxUsersException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) IOException(java.io.IOException)

Example 2 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class EmailSpaceUsersDialog method finishImpl.

/**
 * @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String)
 */
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    // get the space ref this mail applies to
    NodeRef spaceRef = getSpace().getNodeRef();
    // calculate the 'from' email address
    User user = Application.getCurrentUser(context);
    String from = (String) this.getNodeService().getProperty(user.getPerson(), ContentModel.PROP_EMAIL);
    if (from == null || from.length() == 0) {
        // if the user does not have an email address get the default one from the config service
        from = Application.getClientConfig(context).getFromEmailAddress();
    }
    Set<String> mailedAuthorities = new HashSet<String>(usersGroups.size());
    // walk the list of users/groups to notify - handle duplicates along the way
    for (Map node : usersGroups) {
        String authority = (String) node.get(PROP_USERNAME);
        boolean selected = (Boolean) node.get(PROP_SELECTED);
        // if User, email then, else if Group get all members and email them
        AuthorityType authType = AuthorityType.getAuthorityType(authority);
        if (authType.equals(AuthorityType.USER)) {
            if (selected == true && this.getPersonService().personExists(authority)) {
                if (mailedAuthorities.contains(authority) == false) {
                    this.mailHelper.notifyUser(this.getPersonService().getPerson(authority), spaceRef, from, (String) node.get(PROP_ROLES));
                    mailedAuthorities.add(authority);
                }
            }
        } else if (authType.equals(AuthorityType.GROUP)) {
            // is the group expanded? if so we'll deal with the child authorities instead
            boolean expanded = (Boolean) node.get(PROP_EXPANDED);
            if (expanded == false && selected == true) {
                // notify all members of the group
                Set<String> users = this.getAuthorityService().getContainedAuthorities(AuthorityType.USER, authority, false);
                for (String userAuth : users) {
                    if (this.getPersonService().personExists(userAuth) == true) {
                        if (mailedAuthorities.contains(userAuth) == false) {
                            this.mailHelper.notifyUser(this.getPersonService().getPerson(userAuth), spaceRef, from, (String) node.get(PROP_ROLES));
                            mailedAuthorities.add(userAuth);
                        }
                    }
                }
            }
        }
    }
    return outcome;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) User(org.alfresco.web.bean.repository.User) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class WorkflowBean method getTasksCompleted.

/**
 * Returns a list of nodes representing the completed tasks the
 * current user has.
 *
 * @return List of completed tasks
 */
public List<Node> getTasksCompleted() {
    if (this.completedTasks == null) {
        // get the current username
        FacesContext context = FacesContext.getCurrentInstance();
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // get the current in progress tasks for the current user
            ClientConfigElement clientConfig = (ClientConfigElement) Application.getConfigService(context).getGlobalConfig().getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
            WorkflowTaskQuery query = new WorkflowTaskQuery();
            query.setActive(null);
            query.setActorId(userName);
            query.setTaskState(WorkflowTaskState.COMPLETED);
            query.setLimit(clientConfig.getTasksCompletedMaxResults());
            List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
            // create a list of transient nodes to represent
            this.completedTasks = new ArrayList<Node>(tasks.size());
            for (WorkflowTask task : tasks) {
                Node node = createTask(task);
                this.completedTasks.add(node);
                if (logger.isDebugEnabled())
                    logger.debug("Added completed task: " + node);
            }
            // commit the changes
            tx.commit();
        } catch (Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception ex) {
            }
            Utils.addErrorMessage("Failed to get completed tasks: " + e.toString(), e);
        }
    }
    return this.completedTasks;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) User(org.alfresco.web.bean.repository.User) Node(org.alfresco.web.bean.repository.Node) TransientNode(org.alfresco.web.bean.repository.TransientNode) TransientMapNode(org.alfresco.web.bean.repository.TransientMapNode) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) ClientConfigElement(org.alfresco.web.config.ClientConfigElement) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 4 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class WorkflowBean method getPooledTasks.

/**
 * Returns a list of nodes representing the "pooled" to do tasks the
 * current user has.
 *
 * @return List of to do tasks
 */
public List<Node> getPooledTasks() {
    if (this.pooledTasks == null) {
        // get the current username
        FacesContext context = FacesContext.getCurrentInstance();
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // get the current pooled tasks for the current user
            List<WorkflowTask> tasks = this.getWorkflowService().getPooledTasks(userName, true);
            // create a list of transient nodes to represent
            this.pooledTasks = new ArrayList<Node>(tasks.size());
            for (WorkflowTask task : tasks) {
                Node node = createTask(task);
                this.pooledTasks.add(node);
                if (logger.isDebugEnabled())
                    logger.debug("Added pooled task: " + node);
            }
            // commit the changes
            tx.commit();
        } catch (Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception ex) {
            }
            Utils.addErrorMessage("Failed to get pooled tasks: " + e.toString(), e);
        }
    }
    return this.pooledTasks;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) User(org.alfresco.web.bean.repository.User) Node(org.alfresco.web.bean.repository.Node) TransientNode(org.alfresco.web.bean.repository.TransientNode) TransientMapNode(org.alfresco.web.bean.repository.TransientMapNode) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 5 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class WorkflowBean method getTasksToDo.

/**
 * Returns a list of nodes representing the to do tasks the
 * current user has.
 *
 * @return List of to do tasks
 */
public List<Node> getTasksToDo() {
    if (this.tasks == null) {
        // get the current username
        FacesContext context = FacesContext.getCurrentInstance();
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // get the current in progress tasks for the current user
            List<WorkflowTask> tasks = this.getWorkflowService().getAssignedTasks(userName, WorkflowTaskState.IN_PROGRESS, true);
            // create a list of transient nodes to represent
            this.tasks = new ArrayList<Node>(tasks.size());
            for (WorkflowTask task : tasks) {
                Node node = createTask(task);
                this.tasks.add(node);
                if (logger.isDebugEnabled())
                    logger.debug("Added to do task: " + node);
            }
            // commit the changes
            tx.commit();
        } catch (Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception ex) {
            }
            Utils.addErrorMessage("Failed to get to do tasks: " + e.toString(), e);
        }
    }
    return this.tasks;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) User(org.alfresco.web.bean.repository.User) Node(org.alfresco.web.bean.repository.Node) TransientNode(org.alfresco.web.bean.repository.TransientNode) TransientMapNode(org.alfresco.web.bean.repository.TransientMapNode) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Aggregations

User (org.alfresco.web.bean.repository.User)29 SessionUser (org.alfresco.repo.SessionUser)14 FacesContext (javax.faces.context.FacesContext)9 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)6 UserTransaction (javax.transaction.UserTransaction)5 AuthenticationService (org.alfresco.service.cmr.security.AuthenticationService)5 Node (org.alfresco.web.bean.repository.Node)5 WebApplicationContext (org.springframework.web.context.WebApplicationContext)5 HttpSession (javax.servlet.http.HttpSession)4 TransientMapNode (org.alfresco.web.bean.repository.TransientMapNode)4 TransientNode (org.alfresco.web.bean.repository.TransientNode)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 NodeService (org.alfresco.service.cmr.repository.NodeService)3 Map (java.util.Map)2 Set (java.util.Set)2 PortletException (javax.portlet.PortletException)2 PortletSession (javax.portlet.PortletSession)2