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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations