use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.
the class AlfrescoFacesPortlet method processAction.
/**
* Called by the portlet container to allow the portlet to process an action request.
*/
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
Application.setInPortalServer(true);
try {
// Set the current locale
I18NUtil.setLocale(getLanguage(request.getPortletSession()));
boolean isMultipart = PortletFileUpload.isMultipartContent(request);
if (isMultipart) {
if (logger.isDebugEnabled())
logger.debug("Handling multipart request...");
PortletSession session = request.getPortletSession();
// get the file from the request and put it in the session
DiskFileItemFactory factory = new DiskFileItemFactory();
PortletFileUpload upload = new PortletFileUpload(factory);
List<FileItem> fileItems = upload.parseRequest(request);
Iterator<FileItem> iter = fileItems.iterator();
FileUploadBean bean = new FileUploadBean();
while (iter.hasNext()) {
FileItem item = iter.next();
String filename = item.getName();
if (item.isFormField() == false) {
if (logger.isDebugEnabled())
logger.debug("Processing uploaded file: " + filename);
// workaround a bug in IE where the full path is returned
// IE is only available for Windows so only check for the Windows path separator
int idx = filename.lastIndexOf('\\');
if (idx == -1) {
// if there is no windows path separator check for *nix
idx = filename.lastIndexOf('/');
}
if (idx != -1) {
filename = filename.substring(idx + File.separator.length());
}
File tempFile = TempFileProvider.createTempFile("alfresco", ".upload");
item.write(tempFile);
bean.setFile(tempFile);
bean.setFileName(filename);
bean.setFilePath(tempFile.getAbsolutePath());
session.setAttribute(FileUploadBean.FILE_UPLOAD_BEAN_NAME, bean, PortletSession.PORTLET_SCOPE);
}
}
// Set the VIEW_ID parameter to tell the faces portlet bridge to treat the request
// as a JSF request, this will send us back to the previous page we came from.
String lastViewId = (String) request.getPortletSession().getAttribute(SESSION_LAST_VIEW_ID);
if (lastViewId != null) {
response.setRenderParameter(VIEW_ID, lastViewId);
}
} else {
SessionUser sessionUser = (SessionUser) request.getPortletSession().getAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
User user = sessionUser instanceof User ? (User) sessionUser : null;
if (user != null) {
// setup the authentication context
try {
WebApplicationContext ctx = (WebApplicationContext) getPortletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
AuthenticationService auth = (AuthenticationService) ctx.getBean("AuthenticationService");
auth.validate(user.getTicket());
// save last username into portlet preferences, get from LoginBean state
LoginBean loginBean = (LoginBean) request.getPortletSession().getAttribute(AuthenticationHelper.LOGIN_BEAN);
if (loginBean != null) {
// TODO: Need to login to the Portal to get a user here to store prefs against
// so not really a suitable solution as they get thrown away at present!
// Also would need to store prefs PER user - so auto login for each...?
String oldValue = request.getPreferences().getValue(PREF_ALF_USERNAME, null);
if (oldValue == null || oldValue.equals(loginBean.getUsernameInternal()) == false) {
if (request.getPreferences().isReadOnly(PREF_ALF_USERNAME) == false) {
request.getPreferences().setValue(PREF_ALF_USERNAME, loginBean.getUsernameInternal());
request.getPreferences().store();
}
}
}
// do the normal JSF processing
super.processAction(request, response);
} catch (AuthenticationException authErr) {
// remove User object as it's now useless
request.getPortletSession().removeAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
}
} else {
// do the normal JSF processing as we may be on the login page
super.processAction(request, response);
}
}
} catch (Throwable e) {
if (getErrorPage() != null) {
handleError(request, response, e);
} else {
logger.warn("No error page configured, re-throwing exception");
if (e instanceof PortletException) {
throw (PortletException) e;
} else if (e instanceof IOException) {
throw (IOException) e;
} else {
throw new PortletException(e);
}
}
} finally {
Application.setInPortalServer(false);
}
}
use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.
the class WebscriptCookieAuthenticationFilter method createUserObject.
@Override
protected SessionUser createUserObject(String userName, String ticket, NodeRef personNode, NodeRef homeSpaceRef) {
// Create a web client user object
User user = new User(userName, ticket, personNode);
user.setHomeSpaceId(homeSpaceRef.getId());
return user;
}
use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.
the class ScriptCommandProcessor method process.
/**
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, javax.servlet.http.HttpServletRequest, java.lang.String)
*/
public void process(ServiceRegistry serviceRegistry, HttpServletRequest request, String command) {
Map<String, Object> properties = new HashMap<String, Object>(4, 1.0f);
properties.put(ExecuteScriptCommand.PROP_SCRIPT, this.scriptRef);
properties.put(ExecuteScriptCommand.PROP_DOCUMENT, this.docRef);
User user = Application.getCurrentUser(request.getSession());
properties.put(ExecuteScriptCommand.PROP_USERPERSON, user.getPerson());
// add URL arguments as a special Scriptable Map property called 'args'
Map<String, String> args = new ScriptableHashMap<String, String>();
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
args.put(name, request.getParameter(name));
}
properties.put(ExecuteScriptCommand.PROP_ARGS, args);
Command cmd = CommandFactory.getInstance().createCommand(command);
if (cmd == null) {
throw new AlfrescoRuntimeException("Unregistered script command specified: " + command);
}
this.result = cmd.execute(serviceRegistry, properties);
}
use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.
the class BaseInviteUsersWizard 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 {
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();
}
// get the Space to apply changes too
NodeRef nodeRef = this.getNode().getNodeRef();
// set permissions for each user and send them a mail
for (int i = 0; i < this.userGroupRoles.size(); i++) {
UserGroupRole userGroupRole = this.userGroupRoles.get(i);
String authority = userGroupRole.getAuthority();
// find the selected permission ref from it's name and apply for the specified user
Set<String> perms = getPermissionsForType();
for (String permission : perms) {
if (userGroupRole.getRole().equals(permission)) {
this.getPermissionService().setPermission(nodeRef, authority, permission, true);
break;
}
}
// Create the mail message for sending to each User
if (NOTIFY_YES.equals(this.notify)) {
// if User, email then, else if Group get all members and email them
AuthorityType authType = AuthorityType.getAuthorityType(authority);
if (authType.equals(AuthorityType.USER)) {
if (this.getPersonService().personExists(authority) == true) {
this.mailHelper.notifyUser(this.getPersonService().getPerson(authority), nodeRef, from, userGroupRole.getRole());
}
} else if (authType.equals(AuthorityType.GROUP)) {
// else 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) {
this.mailHelper.notifyUser(this.getPersonService().getPerson(userAuth), nodeRef, from, userGroupRole.getRole());
}
}
}
}
}
// reset max users flag
this.maxUsersReturned = false;
return outcome;
}
use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method getUserSearchesRef.
/**
* @return the cached reference to the shared Saved Searches folder
*/
protected NodeRef getUserSearchesRef() {
if (properties.getUserSearchesRef() == null) {
NodeRef globalRef = getGlobalSearchesRef();
if (globalRef != null) {
FacesContext fc = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(fc);
String userName = ISO9075.encode(user.getUserName());
String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + QName.createValidLocalName(userName);
List<NodeRef> results = null;
try {
results = getSearchService().selectNodes(globalRef, xpath, null, getNamespaceService(), false);
} catch (AccessDeniedException err) {
// ignore and return null
}
if (results != null) {
if (results.size() == 1) {
properties.setUserSearchesRef(results.get(0));
} else if (results.size() == 0 && new Node(globalRef).hasPermission(PermissionService.ADD_CHILDREN)) {
// attempt to create folder for this user for first time
// create the preferences Node for this user
ChildAssociationRef childRef = getNodeService().createNode(globalRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, QName.createValidLocalName(user.getUserName())), ContentModel.TYPE_FOLDER, null);
properties.setUserSearchesRef(childRef.getChildRef());
}
}
}
}
return properties.getUserSearchesRef();
}
Aggregations