1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.layout.impl; |
18 |
|
|
19 |
|
import org.apache.commons.logging.Log; |
20 |
|
import org.apache.commons.logging.LogFactory; |
21 |
|
import org.apache.jetspeed.JetspeedActions; |
22 |
|
import org.apache.jetspeed.layout.PortletActionSecurityBehavior; |
23 |
|
import org.apache.jetspeed.om.folder.Folder; |
24 |
|
import org.apache.jetspeed.om.page.ContentPageImpl; |
25 |
|
import org.apache.jetspeed.om.page.Page; |
26 |
|
import org.apache.jetspeed.page.PageManager; |
27 |
|
import org.apache.jetspeed.profiler.impl.ProfilerValveImpl; |
28 |
|
import org.apache.jetspeed.request.RequestContext; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
public class PortletActionSecurityPathBehavior implements PortletActionSecurityBehavior |
37 |
|
{ |
38 |
0 |
protected Log log = LogFactory.getLog(PortletActionSecurityPathBehavior.class); |
39 |
|
protected PageManager pageManager; |
40 |
|
private boolean enableCreateUserPagesFromRolesOnEdit; |
41 |
|
|
42 |
|
public PortletActionSecurityPathBehavior(PageManager pageManager ) |
43 |
|
{ |
44 |
0 |
this( pageManager, Boolean.FALSE ) ; |
45 |
0 |
} |
46 |
|
public PortletActionSecurityPathBehavior(PageManager pageManager, Boolean enableCreateUserPagesFromRolesOnEdit ) |
47 |
0 |
{ |
48 |
0 |
this.pageManager = pageManager; |
49 |
0 |
this.enableCreateUserPagesFromRolesOnEdit = ( enableCreateUserPagesFromRolesOnEdit == null ? false : enableCreateUserPagesFromRolesOnEdit.booleanValue() ); |
50 |
0 |
} |
51 |
|
|
52 |
|
public boolean checkAccess(RequestContext context, String action) |
53 |
|
{ |
54 |
0 |
Page page = context.getPage(); |
55 |
0 |
String path = page.getPath(); |
56 |
0 |
if (path == null) |
57 |
0 |
return false; |
58 |
0 |
if (path.indexOf(Folder.ROLE_FOLDER) > -1 || path.indexOf(Folder.GROUP_FOLDER) > -1) |
59 |
|
{ |
60 |
0 |
if (action.equals(JetspeedActions.VIEW)) |
61 |
0 |
return true; |
62 |
0 |
return false; |
63 |
|
} |
64 |
0 |
return true; |
65 |
|
} |
66 |
|
|
67 |
|
public boolean isCreateNewPageOnEditEnabled() |
68 |
|
{ |
69 |
0 |
return enableCreateUserPagesFromRolesOnEdit; |
70 |
|
} |
71 |
|
public boolean isPageQualifiedForCreateNewPageOnEdit(RequestContext context) |
72 |
|
{ |
73 |
0 |
if ( ! this.enableCreateUserPagesFromRolesOnEdit || context == null ) |
74 |
0 |
return false ; |
75 |
0 |
return isPageQualifiedForCreateNewPageOnEdit( context.getPage().getPath() ); |
76 |
|
} |
77 |
|
|
78 |
|
protected boolean isPageQualifiedForCreateNewPageOnEdit( String pagePath ) |
79 |
|
{ |
80 |
0 |
if (pagePath == null) |
81 |
0 |
return false; |
82 |
|
|
83 |
0 |
return (pagePath.indexOf(Folder.ROLE_FOLDER) == 0); |
84 |
|
} |
85 |
|
|
86 |
|
public boolean createNewPageOnEdit(RequestContext context) |
87 |
|
{ |
88 |
0 |
if ( ! this.enableCreateUserPagesFromRolesOnEdit ) |
89 |
0 |
return false ; |
90 |
|
|
91 |
0 |
Page page = context.getPage(); |
92 |
0 |
String pagePath = page.getPath(); |
93 |
|
try |
94 |
|
{ |
95 |
0 |
if ( isPageQualclass="keyword">ifiedForCreateNewPageOnEdit( pagePath ) ) |
96 |
|
{ |
97 |
0 |
String pageName = page.getName(); |
98 |
0 |
this.pageManager.createUserHomePagesFromRoles(context.getSubject()); |
99 |
0 |
page = this.pageManager.getPage(Folder.USER_FOLDER |
100 |
|
+ context.getRequest().getUserPrincipal().getName() |
101 |
|
+ Folder.PATH_SEPARATOR |
102 |
|
+ pageName); |
103 |
0 |
context.setPage(new ContentPageImpl(page)); |
104 |
0 |
context.getRequest().getSession().removeAttribute(ProfilerValveImpl.PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY); |
105 |
|
} |
106 |
|
} |
107 |
0 |
catch (Exception e) |
108 |
|
{ |
109 |
|
|
110 |
0 |
return false; |
111 |
0 |
} |
112 |
0 |
return true; |
113 |
|
} |
114 |
|
} |