ASF Bugzilla – Attachment 17114 Details for
Bug 37748
JNDIPrincipalStore that uses J2EE Container
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
J2EEPrincipalStore
J2EEPrincipalStore.java (text/plain), 7.30 KB, created by
Damien Bastin
on 2005-12-02 03:07:23 UTC
(
hide
)
Description:
J2EEPrincipalStore
Filename:
MIME Type:
Creator:
Damien Bastin
Created:
2005-12-02 03:07:23 UTC
Size:
7.30 KB
patch
obsolete
>/* > * Copyright (c) 2005 Your Corporation. All Rights Reserved. > */ > >package org.apache.slide.store.txjndi; > >import org.apache.slide.common.NamespaceAccessToken; >import org.apache.slide.common.ServiceAccessException; >import org.apache.slide.common.ServiceInitializationFailedException; >import org.apache.slide.common.Uri; >import org.apache.slide.content.NodeProperty; >import org.apache.slide.content.NodeRevisionDescriptor; >import org.apache.slide.content.NodeRevisionNumber; >import org.apache.slide.content.RevisionDescriptorNotFoundException; >import org.apache.slide.structure.ObjectNode; >import org.apache.slide.structure.ObjectNotFoundException; >import org.apache.slide.structure.SubjectNode; >import org.apache.slide.util.logger.Logger; >import org.apache.slide.webdav.J2EEWebdavServlet; > >import javax.servlet.http.HttpServletRequest; >import java.util.ArrayList; >import java.util.List; >import java.util.Vector; > >/** > * <p> > * This is a read-only Store implementation for retrieving Slide users > * and roles from a J2EE container. It has been tested with WebLogic 8.1 SP4. > * Other Web Containers implementing J2EE security should work. > * </p> > * > * <h3>Prerequisites</h3> > * <p> > * To use this Store your web container must be set up to authenticate users. > * </p> > * > * <h3>Store Parameters</h3> > * <p> > * Parameters used in Domain.xml when setting up the Store. > * </p> > * <dl> > * <dt>log.validationerrors</dt> > * <dd> > * Whether validation errors will be logged. The default value is > * <em>false</em>. > * </dd> > * > * </dl> > * > */ >public class J2EEPrincipalStore extends AbstractPrincipalStore { > > public static final String LOG_CHANNEL = J2EEPrincipalStore.class.getName(); > private String name; > boolean forceLowercaseLogin; > > public J2EEPrincipalStore() { > name = ""; > } > > public void initialize(NamespaceAccessToken token) > throws ServiceInitializationFailedException { > super.initialize(token); > String forceLowercaseLoginString = token.getNamespaceConfig().getParameter("force-lowercase-login"); > forceLowercaseLogin = "true".equals(forceLowercaseLoginString); > } > > // ----------------------------------------------------------- Service Methods -------- > > // ------------------------------------------------------ NodeStore Methods ---------- > > public ObjectNode retrieveObject( Uri uri ) throws ServiceAccessException, ObjectNotFoundException { > getLogger().log( name + ": Retrieving Object " + uri.toString() + ".", > LOG_CHANNEL, Logger.DEBUG ); > return getObject( uri ); > > } > > // ------------------------------------------- RevisionDescriptorStore Methods -------- > > public NodeRevisionDescriptor retrieveRevisionDescriptor( Uri uri, > NodeRevisionNumber revisionNumber ) throws ServiceAccessException, > RevisionDescriptorNotFoundException { > getLogger().log( name + ": Retrieving Revision Descriptor for " + uri.toString() + ".", > LOG_CHANNEL, Logger.DEBUG ); > return getRevisionDescriptor( uri ); > > } > > // --------------------------------------------------- RevisionDescriptorsStore Methods ----- > > // --------------------------------------------------- XA Methods -------------- > > // --------------------------------------------------- ContentStore Methods ---------- > > // --------------------------------------------------- Security Store Methods --------------- > > // --------------------------------------------------- LockStore Methods --------------- > > // --------------------------------------------------- Worker Methods --------------- > > protected SubjectNode getObject( Uri uri ) > throws ObjectNotFoundException, ServiceAccessException { > > getLogger().log(name + ": Trying to getObject for \"" + uri.toString() + "\".", > LOG_CHANNEL, Logger.DEBUG); > > Uri parentUri = uri.getParentUri(); > String objectName = getObjectNameFromUri( uri ); > > Vector parentBindings = new Vector(); > Vector childBindings = new Vector(); > > // As long as this node isn't the root node create a parent binding. > // This doesn't appear to do anything, but just in case. > if ( !uri.toString().equals( "/" ) ) { > parentBindings.add( new ObjectNode.Binding( objectName, parentUri.toString() ) ); > } > > if ( !uri.isStoreRoot() && J2EEWebdavServlet.threadLocalContext != null) { > HttpServletRequest req = (HttpServletRequest) J2EEWebdavServlet.threadLocalContext.get(); > String user = "root"; > if (req != null && req.getUserPrincipal() != null) { > user = req.getUserPrincipal().getName(); > if (forceLowercaseLogin) { > user = user.toLowerCase(); > } > } > getLogger().log( name + "Uri = \"" + uri.toString() + "\" User = \"" + user + "\".", > LOG_CHANNEL, Logger.DEBUG ); > childBindings.add(new ObjectNode.Binding(uri.toString(), uri.toString() + "/" + user)); > } > > SubjectNode node = new SubjectNode( > uri.toString(), childBindings, parentBindings, new Vector() ); > // Workaround for bug in ObjectNode.validate() > node.setUri( uri.toString() ); > > return node; > } > > protected NodeRevisionDescriptor getRevisionDescriptor( Uri uri ) > throws RevisionDescriptorNotFoundException, ServiceAccessException { > > getLogger().log(name + ": Trying to getRevisionDescriptor for \"" + uri.toString() + "\".", > LOG_CHANNEL, Logger.DEBUG); > > String objectName = getObjectNameFromUri( uri ); > > List props = new ArrayList(); > > String resourceType = "<collection/>"; > if ( !uri.isStoreRoot() ) { > resourceType += "<principal/>"; > } > props.add(new NodeProperty( "resourcetype", resourceType, "DAV:", "", false ) ); > props.add(new NodeProperty( "displayname", objectName, "DAV:", "", false ) ); > > if ( !uri.isStoreRoot() && J2EEWebdavServlet.threadLocalContext != null) { > HttpServletRequest req = (HttpServletRequest) J2EEWebdavServlet.threadLocalContext.get(); > String user = "root"; > if (req != null && req.getUserPrincipal() != null) { > user = req.getUserPrincipal().getName(); > if (forceLowercaseLogin) { > user = user.toLowerCase(); > } > } > String role = uri.getRelative().substring(1); > getLogger().log(name + ": Trying to match role \"" + role + "\": " + > (req == null ? "null" : "" + req.isUserInRole(role)), > LOG_CHANNEL, Logger.DEBUG); > if (req != null && req.isUserInRole(role)) { > String propertyValue = "<D:href xmlns:D='DAV:'>/users/" + user + "</D:href>"; > getLogger().log( > name + ": Adding property \"group-member-set\" in namespace " + > "\"DAV:\" with value of \"" + propertyValue + "\" to " + > uri.toString() + ".", > LOG_CHANNEL, Logger.DEBUG ); > props.add(new NodeProperty("group-member-set", propertyValue, "DAV:")); > } > } > > NodeRevisionDescriptor descriptor = new NodeRevisionDescriptor( > new NodeRevisionNumber( 1, 0 ), > "main", > new Vector(), > props ); > > return descriptor; > } > > // --------------------------------------------------- Helper Methods --------------- > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 37748
:
17112
|
17113
| 17114 |
17115
|
17116
|
17117