Source Code Cross Referenced for CmsSecure.java in  » Content-Management-System » opencms » org » opencms » workplace » commons » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.workplace.commons 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsSecure.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:24 $
004:         * Version: $Revision: 1.35 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.workplace.commons;
033:
034:        import org.opencms.file.CmsObject;
035:        import org.opencms.file.CmsProperty;
036:        import org.opencms.file.CmsPropertyDefinition;
037:        import org.opencms.file.CmsResource;
038:        import org.opencms.file.CmsResourceFilter;
039:        import org.opencms.jsp.CmsJspActionElement;
040:        import org.opencms.main.CmsException;
041:        import org.opencms.main.CmsLog;
042:        import org.opencms.main.OpenCms;
043:        import org.opencms.security.CmsPermissionSet;
044:        import org.opencms.util.CmsStringUtil;
045:        import org.opencms.workplace.CmsDialog;
046:        import org.opencms.workplace.CmsWorkplaceSettings;
047:
048:        import javax.servlet.http.HttpServletRequest;
049:        import javax.servlet.http.HttpServletResponse;
050:        import javax.servlet.jsp.JspException;
051:        import javax.servlet.jsp.PageContext;
052:
053:        import org.apache.commons.logging.Log;
054:
055:        /**
056:         * Provides methods for building the security and export settings dialog.<p> 
057:         * 
058:         * The following files use this class:
059:         * <ul>
060:         * <li>/commons/secure.jsp
061:         * </ul>
062:         * <p>
063:         *
064:         * @author  Jan Baudisch 
065:         * 
066:         * @version $Revision: 1.35 $ 
067:         * 
068:         * @since 6.0.0 
069:         */
070:        public class CmsSecure extends CmsDialog {
071:
072:            /** Value for the action: change the security and export setting. */
073:            public static final int ACTION_CHSECEXP = 100;
074:
075:            /** The dialog type. */
076:            public static final String DIALOG_TYPE = "secure";
077:
078:            /** The log object for this class. */
079:            private static final Log LOG = CmsLog.getLog(CmsSecure.class);
080:
081:            /** Export parameter. */
082:            private String m_paramExport;
083:
084:            /** Export name parameter. */
085:            private String m_paramExportname;
086:
087:            /** Intern parameter. */
088:            private String m_paramIntern;
089:
090:            /** Secure parameter. */
091:            private String m_paramSecure;
092:
093:            /**
094:             * Public constructor.<p>
095:             * 
096:             * @param jsp an initialized JSP action element
097:             */
098:            public CmsSecure(CmsJspActionElement jsp) {
099:
100:                super (jsp);
101:            }
102:
103:            /**
104:             * Public constructor with JSP variables.<p>
105:             * 
106:             * @param context the JSP page context
107:             * @param req the JSP request
108:             * @param res the JSP response
109:             */
110:            public CmsSecure(PageContext context, HttpServletRequest req,
111:                    HttpServletResponse res) {
112:
113:                this (new CmsJspActionElement(context, req, res));
114:            }
115:
116:            /**
117:             * Performs the Security and Export Change.<p>
118:             * 
119:             * @throws JspException if including a JSP sub element is not successful
120:             */
121:            public void actionChangeSecureExport() throws JspException {
122:
123:                // save initialized instance of this class in request attribute for included sub-elements
124:                getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS,
125:                        this );
126:
127:                String filename = getParamResource();
128:
129:                try {
130:                    // lock resource if auto lock is enabled
131:                    checkLock(getParamResource());
132:
133:                    // write the properties
134:                    writeProperty(CmsPropertyDefinition.PROPERTY_EXPORT,
135:                            getParamExport());
136:                    writeProperty(CmsPropertyDefinition.PROPERTY_EXPORTNAME,
137:                            getParamExportname());
138:                    writeProperty(CmsPropertyDefinition.PROPERTY_SECURE,
139:                            getParamSecure());
140:
141:                    // change the flag of the resource so that it is internal            
142:                    CmsResource resource = getCms().readResource(filename,
143:                            CmsResourceFilter.IGNORE_EXPIRATION);
144:                    if (resource.isInternal()
145:                            && !Boolean.valueOf(getParamIntern())
146:                                    .booleanValue()) {
147:                        getCms().chflags(
148:                                filename,
149:                                resource.getFlags()
150:                                        & (~CmsResource.FLAG_INTERNAL));
151:                    } else if (!resource.isInternal()
152:                            && Boolean.valueOf(getParamIntern()).booleanValue()) {
153:                        getCms()
154:                                .chflags(
155:                                        filename,
156:                                        resource.getFlags()
157:                                                | CmsResource.FLAG_INTERNAL);
158:                    }
159:
160:                    actionCloseDialog();
161:                } catch (Throwable e) {
162:                    // error during change of secure settings, show error dialog
163:                    includeErrorpage(this , e);
164:                }
165:
166:            }
167:
168:            /**
169:             * Builds the radio input to set the export and secure property.
170:             *
171:             * @param propName the name of the property to build the radio input for
172:             * 
173:             * @return html for the radio input
174:             * 
175:             * @throws CmsException if the reading of a property fails
176:             */
177:            public String buildRadio(String propName) throws CmsException {
178:
179:                String propVal = readProperty(propName);
180:                StringBuffer result = new StringBuffer(
181:                        "<table border=\"0\"><tr>");
182:                result
183:                        .append(
184:                                "<td><input type=\"radio\" value=\"true\" onClick=\"checkNoIntern()\" name=\"")
185:                        .append(propName)
186:                        .append("\" ")
187:                        .append(
188:                                Boolean.valueOf(propVal).booleanValue() ? "checked=\"checked\""
189:                                        : "").append(
190:                                "/></td><td id=\"tablelabel\">").append(
191:                                key(Messages.GUI_LABEL_TRUE_0)).append("</td>");
192:                result
193:                        .append(
194:                                "<td><input type=\"radio\" value=\"false\" onClick=\"checkNoIntern()\" name=\"")
195:                        .append(propName).append("\" ").append(
196:                                Boolean.valueOf(propVal).booleanValue() ? ""
197:                                        : "checked=\"checked\"").append(
198:                                "/></td><td id=\"tablelabel\">").append(
199:                                key(Messages.GUI_LABEL_FALSE_0))
200:                        .append("</td>");
201:                result
202:                        .append(
203:                                "<td><input type=\"radio\" value=\"\" onClick=\"checkNoIntern()\" name=\"")
204:                        .append(propName)
205:                        .append("\" ")
206:                        .append(
207:                                CmsStringUtil.isEmpty(propVal) ? "checked=\"checked\""
208:                                        : "").append(
209:                                "/></td><td id=\"tablelabel\">").append(
210:                                getPropertyInheritanceInfo(propName)).append(
211:                                "</td></tr></table>");
212:                return result.toString();
213:            }
214:
215:            /**
216:             * Returns the value of the export parameter.<p>
217:             * 
218:             * @return the value of the export parameter
219:             */
220:            public String getParamExport() {
221:
222:                return m_paramExport;
223:            }
224:
225:            /**
226:             * Returns the value of the export name parameter.<p>
227:             * 
228:             * @return the value of the export name parameter
229:             */
230:            public String getParamExportname() {
231:
232:                return m_paramExportname;
233:            }
234:
235:            /**
236:             * Returns the value of the intern parameter.<p>
237:             * 
238:             * @return the value of the intern parameter
239:             */
240:            public String getParamIntern() {
241:
242:                return m_paramIntern;
243:            }
244:
245:            /**
246:             * Returns the value of the secure parameter.<p>
247:             * 
248:             * @return the value of the secure parameter
249:             */
250:            public String getParamSecure() {
251:
252:                return m_paramSecure;
253:            }
254:
255:            /**
256:             * Returns the information from which the property is inherited.<p>
257:             * 
258:             * @param propName the name of the property
259:             * @return a String containing the information from which the property is inherited and inherited value
260:             * @throws CmsException if the reading of the Property fails 
261:             */
262:            public String getPropertyInheritanceInfo(String propName)
263:                    throws CmsException {
264:
265:                String folderName = CmsResource
266:                        .getParentFolder(getParamResource());
267:                String folderPropVal = null;
268:                while (CmsStringUtil.isNotEmpty(folderName)) {
269:                    CmsProperty prop = getCms().readPropertyObject(folderName,
270:                            propName, false);
271:                    folderPropVal = prop.getValue();
272:                    if (CmsStringUtil.isNotEmpty(folderPropVal)) {
273:                        break;
274:                    }
275:                    folderName = CmsResource.getParentFolder(folderName);
276:                }
277:
278:                if (CmsStringUtil.isNotEmpty(folderPropVal)) {
279:                    return key(Messages.GUI_SECURE_INHERIT_FROM_2,
280:                            new Object[] { folderPropVal, folderName });
281:                } else {
282:                    return key(Messages.GUI_SECURE_NOT_SET_0);
283:                }
284:            }
285:
286:            /**
287:             * Returns the path under which the resource is accessible.<p>
288:             *  
289:             * @return the path under which the resource is accessible
290:             */
291:            public String getResourceUrl() {
292:
293:                return OpenCms.getLinkManager().getOnlineLink(getCms(),
294:                        getParamResource());
295:            }
296:
297:            /**
298:             * Returns true if the export user has read permission on a specified resource.<p>
299:             * 
300:             * @return true, if the export user has the permission to read the resource
301:             */
302:            public boolean exportUserHasReadPermission() {
303:
304:                String vfsName = getParamResource();
305:                CmsObject cms = getCms();
306:                try {
307:                    // static export must always be checked with the export users permissions,
308:                    // not the current users permissions
309:                    CmsObject exportCms = OpenCms.initCmsObject(OpenCms
310:                            .getDefaultUsers().getUserExport());
311:                    exportCms.getRequestContext().setSiteRoot(
312:                            getCms().getRequestContext().getSiteRoot());
313:                    // let's look up if the export user has the permission to read
314:                    return exportCms.hasPermissions(cms.readResource(vfsName,
315:                            CmsResourceFilter.IGNORE_EXPIRATION),
316:                            CmsPermissionSet.ACCESS_READ);
317:                } catch (CmsException e) {
318:                    // ignore this exception
319:                }
320:                return false;
321:            }
322:
323:            /**
324:             * Returns value of the the intern property of the resource.<p>
325:             *  
326:             * @return the value of the intern property of the resource
327:             */
328:            public String readInternProp() {
329:
330:                boolean internProp = false;
331:                try {
332:                    internProp = getCms().readResource(getParamResource(),
333:                            CmsResourceFilter.IGNORE_EXPIRATION).isInternal();
334:                } catch (CmsException e) {
335:                    if (LOG.isInfoEnabled()) {
336:                        LOG.info(e.getLocalizedMessage());
337:                    }
338:                }
339:                return String.valueOf(internProp);
340:            }
341:
342:            /**
343:             * Returns value of the property of the resource.<p>
344:             * 
345:             * @param propertyName the name of the property to read 
346:             * 
347:             * @return the value of the secure property of the resource
348:             */
349:            public String readProperty(String propertyName) {
350:
351:                String propVal = null;
352:                try {
353:                    propVal = getCms().readPropertyObject(getParamResource(),
354:                            propertyName, false).getValue();
355:                } catch (CmsException e) {
356:                    if (LOG.isInfoEnabled()) {
357:                        LOG.info(e.getLocalizedMessage());
358:                    }
359:                }
360:                if (CmsStringUtil.isEmpty(propVal)) {
361:                    propVal = "";
362:                }
363:                return propVal;
364:            }
365:
366:            /**
367:             * returns if the resource to be changed is a folder.<p>
368:             * 
369:             * @return true if the resource is a folder
370:             * 
371:             * @throws CmsException if the reading of the resource fails
372:             */
373:            public boolean resourceIsFolder() throws CmsException {
374:
375:                return getCms().readResource(getParamResource(),
376:                        CmsResourceFilter.IGNORE_EXPIRATION).isFolder();
377:            }
378:
379:            /**
380:             * Sets the value of the export parameter.<p>
381:             * 
382:             * @param value for the export parameter
383:             */
384:            public void setParamExport(String value) {
385:
386:                m_paramExport = value;
387:            }
388:
389:            /**
390:             * Sets the value of the export name parameter.<p>
391:             * 
392:             * @param value for the export name parameter
393:             */
394:            public void setParamExportname(String value) {
395:
396:                m_paramExportname = value;
397:            }
398:
399:            /**
400:             * Sets the value of the intern parameter.<p>
401:             * 
402:             * @param value for the intern parameter
403:             */
404:            public void setParamIntern(String value) {
405:
406:                m_paramIntern = value;
407:            }
408:
409:            /**
410:             * Sets the value of the secure parameter.<p>
411:             * 
412:             * @param value for the secure parameter
413:             */
414:            public void setParamSecure(String value) {
415:
416:                m_paramSecure = value;
417:            }
418:
419:            /**
420:             * Determines whether to show the export settings dialog depending on the users settings.<p>
421:             * 
422:             * @return true if dialogs should be shown, otherwise false
423:             */
424:            public boolean showExportSettings() {
425:
426:                return getSettings().getUserSettings()
427:                        .getDialogShowExportSettings();
428:            }
429:
430:            /**
431:             * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
432:             */
433:            protected void initWorkplaceRequestValues(
434:                    CmsWorkplaceSettings settings, HttpServletRequest request) {
435:
436:                // fill the parameter values in the get/set methods
437:                fillParamValues(request);
438:
439:                // check the required permissions to change the resource properties      
440:                if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE,
441:                        false)) {
442:                    // no write permissions for the resource, set cancel action to close dialog
443:                    setParamAction(DIALOG_CANCEL);
444:                }
445:
446:                // set the dialog type
447:                setParamDialogtype(DIALOG_TYPE);
448:                // set the action for the JSP switch 
449:                if (DIALOG_TYPE.equals(getParamAction())) {
450:                    setAction(ACTION_CHSECEXP);
451:                } else if (DIALOG_LOCKS_CONFIRMED.equals(getParamAction())) {
452:                    setAction(ACTION_LOCKS_CONFIRMED);
453:                } else if (DIALOG_CANCEL.equals(getParamAction())) {
454:                    setAction(ACTION_CANCEL);
455:                } else {
456:                    setAction(ACTION_DEFAULT);
457:                    // build title for chnav dialog    
458:                    setParamTitle(key(Messages.GUI_SECURE_EXPORT_RESOURCE_1,
459:                            new Object[] { CmsResource
460:                                    .getName(getParamResource()) }));
461:                }
462:            }
463:
464:            /**
465:             * Writes a property value for a resource.<p>
466:             * 
467:             * @param propertyName the name of the property
468:             * @param propertyValue the new value of the property
469:             * 
470:             * @throws CmsException if something goes wrong
471:             */
472:            protected void writeProperty(String propertyName,
473:                    String propertyValue) throws CmsException {
474:
475:                if (CmsStringUtil.isEmpty(propertyValue)) {
476:                    propertyValue = CmsProperty.DELETE_VALUE;
477:                }
478:
479:                CmsProperty newProp = new CmsProperty();
480:                newProp.setName(propertyName);
481:                CmsProperty oldProp = getCms().readPropertyObject(
482:                        getParamResource(), propertyName, false);
483:                if (oldProp.isNullProperty()) {
484:                    // property value was not already set
485:                    if (OpenCms.getWorkplaceManager()
486:                            .isDefaultPropertiesOnStructure()) {
487:                        newProp.setStructureValue(propertyValue);
488:                    } else {
489:                        newProp.setResourceValue(propertyValue);
490:                    }
491:                } else {
492:                    if (oldProp.getStructureValue() != null) {
493:                        newProp.setStructureValue(propertyValue);
494:                        newProp.setResourceValue(oldProp.getResourceValue());
495:                    } else {
496:                        newProp.setResourceValue(propertyValue);
497:                    }
498:                }
499:
500:                newProp.setAutoCreatePropertyDefinition(true);
501:
502:                String oldStructureValue = oldProp.getStructureValue();
503:                String newStructureValue = newProp.getStructureValue();
504:                if (CmsStringUtil.isEmpty(oldStructureValue)) {
505:                    oldStructureValue = CmsProperty.DELETE_VALUE;
506:                }
507:                if (CmsStringUtil.isEmpty(newStructureValue)) {
508:                    newStructureValue = CmsProperty.DELETE_VALUE;
509:                }
510:
511:                String oldResourceValue = oldProp.getResourceValue();
512:                String newResourceValue = newProp.getResourceValue();
513:                if (CmsStringUtil.isEmpty(oldResourceValue)) {
514:                    oldResourceValue = CmsProperty.DELETE_VALUE;
515:                }
516:                if (CmsStringUtil.isEmpty(newResourceValue)) {
517:                    newResourceValue = CmsProperty.DELETE_VALUE;
518:                }
519:
520:                // change property only if it has been changed            
521:                if (!oldResourceValue.equals(newResourceValue)
522:                        || !oldStructureValue.equals(newStructureValue)) {
523:                    getCms().writePropertyObject(getParamResource(), newProp);
524:                }
525:            }
526:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.