use of org.alfresco.web.config.ClientConfigElement in project acs-community-packaging by Alfresco.
the class ScriptCommandProcessor method validateArguments.
/**
* @see org.alfresco.web.app.servlet.command.CommandProcessor#validateArguments(javax.servlet.ServletContext, java.lang.String, java.util.Map, java.lang.String[])
*/
public boolean validateArguments(ServletContext sc, String command, Map<String, String> args, String[] urlElements) {
boolean allowed = false;
String scriptPath = args.get(ARG_SCRIPT_PATH);
if (scriptPath != null) {
// resolve path to a node
this.scriptRef = BaseServlet.resolveNamePath(sc, scriptPath).NodeRef;
// same for the document context path if specified
String docPath = args.get(ARG_CONTEXT_PATH);
if (docPath != null) {
this.docRef = BaseServlet.resolveNamePath(sc, docPath).NodeRef;
}
} else {
if (urlElements.length < 3) {
throw new IllegalArgumentException("Not enough URL arguments passed to command servlet.");
}
// get NodeRef to the node script to execute
StoreRef storeRef = new StoreRef(urlElements[0], urlElements[1]);
this.scriptRef = new NodeRef(storeRef, urlElements[2]);
if (urlElements.length >= 6) {
storeRef = new StoreRef(urlElements[3], urlElements[4]);
this.docRef = new NodeRef(storeRef, urlElements[5]);
}
}
// check we can READ access the nodes specified
PermissionService ps = Repository.getServiceRegistry(sc).getPermissionService();
allowed = (ps.hasPermission(this.scriptRef, PermissionService.READ) == AccessStatus.ALLOWED);
if (this.docRef != null) {
allowed &= (ps.hasPermission(this.docRef, PermissionService.READ) == AccessStatus.ALLOWED);
}
// check to see if user is allowed to execute arbituary javascript
// by default only an admin authority can perform this action
ConfigService configService = Application.getConfigService(sc);
ClientConfigElement configElement = (ClientConfigElement) configService.getGlobalConfig().getConfigElement("client");
boolean allowScriptExecute = configElement.getAllowUserScriptExecute();
AuthorityService authService = Repository.getServiceRegistry(sc).getAuthorityService();
allowed &= (allowScriptExecute || authService.isAdminAuthority(AuthenticationUtil.getFullyAuthenticatedUser()));
return allowed;
}
use of org.alfresco.web.config.ClientConfigElement 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.config.ClientConfigElement in project acs-community-packaging by Alfresco.
the class AlfrescoFacesPortlet method facesRender.
/**
* @see org.apache.myfaces.portlet.MyFacesGenericPortlet#facesRender(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
*/
protected void facesRender(RenderRequest request, RenderResponse response) throws PortletException, IOException {
Application.setInPortalServer(true);
try {
// Set the current locale
I18NUtil.setLocale(getLanguage(request.getPortletSession()));
if (request.getParameter(ERROR_OCCURRED) != null) {
String errorPage = getErrorPage();
if (logger.isDebugEnabled())
logger.debug("An error has occurred, redirecting to error page: " + errorPage);
response.setContentType("text/html");
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(errorPage);
dispatcher.include(request, response);
} else {
WebApplicationContext ctx = (WebApplicationContext) getPortletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
AuthenticationService auth = (AuthenticationService) ctx.getBean("AuthenticationService");
// if we have no User object in the session then an HTTP Session timeout must have occured
// use the viewId to check that we are not already on the login page
PortletSession session = request.getPortletSession();
String viewId = request.getParameter(VIEW_ID);
// keep track of last view id so we can use it as return page from multi-part requests
request.getPortletSession().setAttribute(SESSION_LAST_VIEW_ID, viewId);
SessionUser sessionUser = (SessionUser) request.getPortletSession().getAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
User user = sessionUser instanceof User ? (User) sessionUser : null;
if (user == null && (viewId == null || viewId.equals(getLoginPage()) == false)) {
if (portalGuestAuthenticate(ctx, session, auth) != null) {
if (logger.isDebugEnabled())
logger.debug("Guest access successful.");
// perform the forward to the page processed by the Faces servlet
response.setContentType("text/html");
request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
// get the start location as configured by the web-client config
ConfigService configService = (ConfigService) ctx.getBean("webClientConfigService");
ClientConfigElement configElement = (ClientConfigElement) configService.getGlobalConfig().getConfigElement("client");
if (NavigationBean.LOCATION_MYALFRESCO.equals(configElement.getInitialLocation())) {
nonFacesRequest(request, response, "/jsp/dashboards/container.jsp");
} else {
nonFacesRequest(request, response, FacesHelper.BROWSE_VIEW_ID);
}
} else {
if (logger.isDebugEnabled())
logger.debug("No valid User login, requesting login page. ViewId: " + viewId);
// set last used username as special session value used by the LoginBean
session.setAttribute(AuthenticationHelper.SESSION_USERNAME, request.getPreferences().getValue(PREF_ALF_USERNAME, null));
// login page is the default portal page
response.setContentType("text/html");
request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
nonFacesRequest(request, response);
}
} else {
if (session.getAttribute(AuthenticationHelper.SESSION_INVALIDATED) != null) {
// remove the username preference value as explicit logout was requested by the user
if (request.getPreferences().isReadOnly(PREF_ALF_USERNAME) == false) {
request.getPreferences().reset(PREF_ALF_USERNAME);
}
session.removeAttribute(AuthenticationHelper.SESSION_INVALIDATED);
}
try {
if (user != null) {
if (logger.isDebugEnabled())
logger.debug("Validating ticket: " + user.getTicket());
// setup the authentication context
auth.validate(user.getTicket());
}
// do the normal JSF processing
super.facesRender(request, response);
} catch (AuthenticationException authErr) {
// ticket is no longer valid!
if (logger.isDebugEnabled())
logger.debug("Invalid ticket, requesting login page.");
// remove User object as it's now useless
session.removeAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
// login page is the default portal page
response.setContentType("text/html");
request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
nonFacesRequest(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.config.ClientConfigElement in project acs-community-packaging by Alfresco.
the class Application method getLoginPage.
/**
* Retrieves the configured login page for the application
*
* @param context The Spring contexr
* @return The configured login page or null if the configuration is missing
*/
public static String getLoginPage(ApplicationContext context) {
String loginPage = null;
ConfigService svc = (ConfigService) context.getBean(BEAN_CONFIG_SERVICE);
ClientConfigElement clientConfig = (ClientConfigElement) svc.getGlobalConfig().getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
if (clientConfig != null) {
loginPage = clientConfig.getLoginPage();
}
return loginPage;
}
use of org.alfresco.web.config.ClientConfigElement in project acs-community-packaging by Alfresco.
the class Application method getErrorPage.
/**
* Retrieves the configured error page for the application
*
* @param context The Spring context
* @return The configured error page or null if the configuration is missing
*/
public static String getErrorPage(ApplicationContext context) {
String errorPage = null;
ConfigService svc = (ConfigService) context.getBean(BEAN_CONFIG_SERVICE);
ClientConfigElement clientConfig = (ClientConfigElement) svc.getGlobalConfig().getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
if (clientConfig != null) {
errorPage = clientConfig.getErrorPage();
}
return errorPage;
}
Aggregations