You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/12/30 00:54:20 UTC
svn commit: r1225696 [1/5] - in /directory/apacheds/branches/apacheds-txns:
core-api/src/main/java/org/apache/directory/server/core/api/
core-api/src/main/java/org/apache/directory/server/core/api/filtering/
core-api/src/main/java/org/apache/directory/...
Author: elecharny
Date: Thu Dec 29 23:54:19 2011
New Revision: 1225696
URL: http://svn.apache.org/viewvc?rev=1225696&view=rev
Log:
o Moved the txn layer to the OperationManager class.
Note : we have some failing tests, but they are mainly due to encapsulated txns into existing txns.
Added:
directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java
Modified:
directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java
directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java
directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursor.java
directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnConflictException.java
directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java
directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java
directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java
directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/authz/SearchAuthorizationIT.java
directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceIT.java
directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/jndi/ListIT.java
directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/AbstractMetaSchemaObjectHandler.java
directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java
directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultOperationExecutionManager.java
directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java
directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/AbstractTransaction.java
directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java
directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadOnlyTxn.java
directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java
directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerInternal.java
directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/logedit/TxnStateChange.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
directory/apacheds/branches/apacheds-txns/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java
directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/LdapCoreSessionConnection.java Thu Dec 29 23:54:19 2011
@@ -138,7 +138,7 @@ public class LdapCoreSessionConnection i
messageId.incrementAndGet();
}
-
+
/**
* {@inheritDoc}
*/
@@ -179,7 +179,7 @@ public class LdapCoreSessionConnection i
LOG.debug( msg );
throw new IllegalArgumentException( msg );
}
-
+
Entry entry = addRequest.getEntry();
if ( entry == null )
@@ -188,10 +188,10 @@ public class LdapCoreSessionConnection i
LOG.debug( msg );
throw new IllegalArgumentException( msg );
}
-
+
if ( !entry.isSchemaAware() )
{
- entry.apply( schemaManager );
+ entry.apply( schemaManager );
}
int newId = messageId.incrementAndGet();
@@ -233,14 +233,14 @@ public class LdapCoreSessionConnection i
AddRequest addRequest = new AddRequestImpl();
addRequest.setEntry( entry );
addRequest.setEntryDn( entry.getDn() );
-
+
if ( !entry.isSchemaAware() )
{
- entry.apply( schemaManager );
+ entry.apply( schemaManager );
}
AddResponse addResponse = add( addRequest );
-
+
processResponse( addResponse );
}
@@ -493,7 +493,7 @@ public class LdapCoreSessionConnection i
*/
public Entry lookup( Dn dn, String... attributes ) throws LdapException
{
- return lookup( dn, (Control[])null, attributes );
+ return lookup( dn, ( Control[] ) null, attributes );
}
@@ -524,7 +524,7 @@ public class LdapCoreSessionConnection i
*/
public Entry lookup( String dn, String... attributes ) throws LdapException
{
- return lookup( new Dn( schemaManager, dn ), (Control[])null, attributes );
+ return lookup( new Dn( schemaManager, dn ), ( Control[] ) null, attributes );
}
@@ -553,9 +553,7 @@ public class LdapCoreSessionConnection i
{
try
{
- Entry entry = lookup( dn, SchemaConstants.NO_ATTRIBUTE );
-
- return entry != null;
+ return session.exists( dn );
}
catch ( LdapNoPermissionException lnpe )
{
@@ -592,7 +590,7 @@ public class LdapCoreSessionConnection i
*/
public Entry lookup( Dn dn ) throws LdapException
{
- return lookup( dn, (Control[])null );
+ return lookup( dn, ( Control[] ) null );
}
@@ -601,7 +599,7 @@ public class LdapCoreSessionConnection i
*/
public Entry lookup( String dn ) throws LdapException
{
- return lookup( new Dn( schemaManager, dn ), (Control[])null );
+ return lookup( new Dn( schemaManager, dn ), ( Control[] ) null );
}
@@ -668,13 +666,12 @@ public class LdapCoreSessionConnection i
modifyRequest.setName( entry.getDn() );
Iterator<Attribute> itr = entry.iterator();
-
+
while ( itr.hasNext() )
{
modifyRequest.addModification( new DefaultModification( modOp, itr.next() ) );
}
-
ModifyResponse modifyResponse = modify( modifyRequest );
processResponse( modifyResponse );
@@ -712,7 +709,7 @@ public class LdapCoreSessionConnection i
}
addResponseControls( modRequest, resp );
-
+
return resp;
}
@@ -741,6 +738,7 @@ public class LdapCoreSessionConnection i
String msg = "Modify Dn is not allowed on Root DSE.";
result.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
result.setDiagnosticMessage( msg );
+
return resp;
}
@@ -791,6 +789,7 @@ public class LdapCoreSessionConnection i
}
addResponseControls( modDnRequest, resp );
+
return resp;
}
@@ -1061,7 +1060,9 @@ public class LdapCoreSessionConnection i
public EntryCursor search( String baseDn, String filter, SearchScope scope, String... attributes )
throws LdapException
{
- return search( new Dn( schemaManager, baseDn ), filter, scope, attributes );
+ Dn dn = new Dn( schemaManager, baseDn );
+
+ return search( dn, filter, scope, attributes );
}
@@ -1167,7 +1168,7 @@ public class LdapCoreSessionConnection i
public void bind() throws LdapException, IOException
{
throw new UnsupportedOperationException(
- "Bind operation using LdapConnectionConfig are not supported on CoreSession based connection" );
+ "Bind operation using LdapConnectionConfig are not supported on CoreSession based connection" );
}
@@ -1256,7 +1257,7 @@ public class LdapCoreSessionConnection i
*/
public void bind( Dn name, String credentials ) throws LdapException, IOException
{
- byte[] credBytes = ( credentials == null ? StringConstants.EMPTY_BYTES : Strings.getBytesUtf8(credentials) );
+ byte[] credBytes = ( credentials == null ? StringConstants.EMPTY_BYTES : Strings.getBytesUtf8( credentials ) );
BindRequest bindRequest = new BindRequestImpl();
bindRequest.setName( name );
Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java?rev=1225696&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java (added)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java Thu Dec 29 23:54:19 2011
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.api.filtering;
+
+
+import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
+import org.apache.directory.server.core.api.txn.TxnHandle;
+import org.apache.directory.server.core.api.txn.TxnManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractEntryFilteringCursor implements EntryFilteringCursor
+{
+ /** A logger for ths class */
+ private static final Logger LOG = LoggerFactory.getLogger( AbstractEntryFilteringCursor.class );
+
+ /** the parameters associated with the search operation */
+ protected final SearchingOperationContext searchContext;
+
+ /** The associated TxnManager */
+ protected TxnManager txnManager;
+
+ /** The associated transaction */
+ protected TxnHandle transaction;
+
+
+ /**
+ * An instance for this class
+ * @param searchContext The associated search context
+ */
+ protected AbstractEntryFilteringCursor( SearchingOperationContext searchContext )
+ {
+ this.searchContext = searchContext;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setTxnManager( TxnManager txnManager )
+ {
+ this.txnManager = txnManager;
+ this.transaction = txnManager.getCurTxn();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public TxnHandle getTransaction()
+ {
+ return transaction;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public SearchingOperationContext getOperationContext()
+ {
+ return searchContext;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAbandoned()
+ {
+ return searchContext.isAbandoned();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setAbandoned( boolean abandoned )
+ {
+ searchContext.setAbandoned( abandoned );
+
+ if ( abandoned )
+ {
+ LOG.info( "Cursor has been abandoned." );
+ }
+ }
+}
Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java Thu Dec 29 23:54:19 2011
@@ -51,29 +51,25 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class BaseEntryFilteringCursor implements EntryFilteringCursor
+public class BaseEntryFilteringCursor extends AbstractEntryFilteringCursor
{
/** the logger used by this class */
- private static final Logger log = LoggerFactory.getLogger( BaseEntryFilteringCursor.class );
+ private static final Logger LOG = LoggerFactory.getLogger( BaseEntryFilteringCursor.class );
/** the underlying wrapped search results Cursor */
private final Cursor<Entry> wrapped;
-
- /** the parameters associated with the search operation */
- private final SearchingOperationContext operationContext;
-
+
/** the list of filters to be applied */
private final List<EntryFilter> filters;
-
+
/** the first accepted search result that is pre fetched */
private Entry prefetched;
-
+
// ------------------------------------------------------------------------
// C O N S T R U C T O R S
// ------------------------------------------------------------------------
-
/**
* Creates a new entry filtering Cursor over an existing Cursor using a
* single filter initially: more can be added later after creation.
@@ -83,13 +79,13 @@ public class BaseEntryFilteringCursor im
* @param invocation the search operation invocation creating this Cursor
* @param filter a single filter to be used
*/
- public BaseEntryFilteringCursor( Cursor<Entry> wrapped,
+ public BaseEntryFilteringCursor( Cursor<Entry> wrapped,
SearchingOperationContext operationContext, EntryFilter filter )
{
this( wrapped, operationContext, Collections.singletonList( filter ) );
}
-
+
/**
* Creates a new entry filtering Cursor over an existing Cursor using a
* no filter initially: more can be added later after creation.
@@ -99,14 +95,14 @@ public class BaseEntryFilteringCursor im
* @param invocation the search operation invocation creating this Cursor
* @param filter a single filter to be used
*/
- public BaseEntryFilteringCursor( Cursor<Entry> wrapped, SearchingOperationContext operationContext )
+ public BaseEntryFilteringCursor( Cursor<Entry> wrapped, SearchingOperationContext searchContext )
{
+ super( searchContext );
this.wrapped = wrapped;
- this.operationContext = operationContext;
this.filters = new ArrayList<EntryFilter>();
}
-
+
/**
* Creates a new entry filtering Cursor over an existing Cursor using a
* list of filters initially: more can be added later after creation.
@@ -116,90 +112,51 @@ public class BaseEntryFilteringCursor im
* @param invocation the search operation invocation creating this Cursor
* @param filters a list of filters to be used
*/
- public BaseEntryFilteringCursor( Cursor<Entry> wrapped,
- SearchingOperationContext operationContext, List<EntryFilter> filters )
+ public BaseEntryFilteringCursor( Cursor<Entry> wrapped,
+ SearchingOperationContext searchContext, List<EntryFilter> filters )
{
+ super( searchContext );
this.wrapped = wrapped;
- this.operationContext = operationContext;
this.filters = new ArrayList<EntryFilter>();
this.filters.addAll( filters );
}
-
-
+
+
// ------------------------------------------------------------------------
// Class Specific Methods
// ------------------------------------------------------------------------
-
-
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#isAbandoned()
- */
- public boolean isAbandoned()
- {
- return getOperationContext().isAbandoned();
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#setAbandoned(boolean)
- */
- public void setAbandoned( boolean abandoned )
- {
- getOperationContext().setAbandoned( abandoned );
-
- if ( abandoned )
- {
- log.info( "Cursor has been abandoned." );
- }
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#addEntryFilter(org.apache.directory.server.core.filtering.EntryFilter)
+ /**
+ * {@inheritDoc}
*/
public boolean addEntryFilter( EntryFilter filter )
{
return filters.add( filter );
}
-
-
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#removeEntryFilter(org.apache.directory.server.core.filtering.EntryFilter)
+
+
+ /**
+ * {@inheritDoc}
*/
public boolean removeEntryFilter( EntryFilter filter )
{
return filters.remove( filter );
}
-
-
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#getEntryFilters()
+
+
+ /**
+ * {@inheritDoc}
*/
public List<EntryFilter> getEntryFilters()
{
return Collections.unmodifiableList( filters );
}
-
-
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#getOperationContext()
- */
- public SearchingOperationContext getOperationContext()
- {
- return operationContext;
- }
-
+
// ------------------------------------------------------------------------
// Cursor Interface Methods
// ------------------------------------------------------------------------
-
-
- /*
- * @see Cursor#after(Object)
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#after(org.apache.directory.server.core.entry.ClonedServerEntry)
+ /**
+ * {@inheritDoc}
*/
public void after( Entry element ) throws Exception
{
@@ -207,11 +164,8 @@ public class BaseEntryFilteringCursor im
}
- /*
- * @see Cursor#afterLast()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#afterLast()
+ /**
+ * {@inheritDoc}
*/
public void afterLast() throws Exception
{
@@ -220,11 +174,8 @@ public class BaseEntryFilteringCursor im
}
- /*
- * @see Cursor#available()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#available()
+ /**
+ * {@inheritDoc}
*/
public boolean available()
{
@@ -232,11 +183,8 @@ public class BaseEntryFilteringCursor im
}
- /*
- * @see Cursor#before(java.lang.Object)
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#before(org.apache.directory.server.core.entry.ClonedServerEntry)
+ /**
+ * {@inheritDoc}
*/
public void before( Entry element ) throws Exception
{
@@ -244,11 +192,8 @@ public class BaseEntryFilteringCursor im
}
- /*
- * @see Cursor#beforeFirst()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#beforeFirst()
+ /**
+ * {@inheritDoc}
*/
public void beforeFirst() throws Exception
{
@@ -257,63 +202,64 @@ public class BaseEntryFilteringCursor im
}
- /*
- * @see Cursor#close()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#close()
+ /**
+ * {@inheritDoc}
*/
public void close() throws Exception
{
wrapped.close();
prefetched = null;
+
+ if ( ( txnManager != null ) && ( txnManager.getCurTxn() != null ) )
+ {
+ txnManager.commitTransaction();
+ }
}
- /*
- * @see Cursor#close()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#close()
+ /**
+ * {@inheritDoc}
*/
public void close( Exception reason ) throws Exception
{
wrapped.close( reason );
prefetched = null;
+
+ if ( txnManager != null )
+ {
+ txnManager.abortTransaction();
+ }
}
-
-
+
+
+ /**
+ * {@inheritDoc}
+ */
public final void setClosureMonitor( ClosureMonitor monitor )
{
wrapped.setClosureMonitor( monitor );
}
- /*
- * @see Cursor#first()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#first()
+ /**
+ * {@inheritDoc}
*/
public boolean first() throws Exception
{
if ( getOperationContext().isAbandoned() )
{
- log.info( "Cursor has been abandoned." );
+ LOG.info( "Cursor has been abandoned." );
close();
throw new OperationAbandonedException();
}
-
+
beforeFirst();
return next();
}
- /*
- * @see Cursor#get()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#get()
+ /**
+ * {@inheritDoc}
*/
public Entry get() throws Exception
{
@@ -321,16 +267,13 @@ public class BaseEntryFilteringCursor im
{
return prefetched;
}
-
+
throw new InvalidCursorPositionException();
}
- /*
- * @see Cursor#isClosed()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#isClosed()
+ /**
+ * {@inheritDoc}
*/
public boolean isClosed() throws Exception
{
@@ -338,17 +281,14 @@ public class BaseEntryFilteringCursor im
}
- /*
- * @see Cursor#last()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#last()
+ /**
+ * {@inheritDoc}
*/
public boolean last() throws Exception
{
if ( getOperationContext().isAbandoned() )
{
- log.info( "Cursor has been abandoned." );
+ LOG.info( "Cursor has been abandoned." );
close();
throw new OperationAbandonedException();
}
@@ -356,22 +296,23 @@ public class BaseEntryFilteringCursor im
afterLast();
return previous();
}
-
-
+
+
private void filterContents( Entry entry ) throws Exception
{
boolean typesOnly = getOperationContext().isTypesOnly();
boolean returnAll = ( getOperationContext().getReturningAttributes() == null ||
- ( getOperationContext().isAllOperationalAttributes() && getOperationContext().isAllUserAttributes() ) ) && ( ! typesOnly );
-
+ ( getOperationContext().isAllOperationalAttributes() && getOperationContext().isAllUserAttributes() ) )
+ && ( !typesOnly );
+
if ( returnAll )
{
return;
}
- Entry originalEntry = ((ClonedServerEntry)entry).getOriginalEntry();
-
+ Entry originalEntry = ( ( ClonedServerEntry ) entry ).getOriginalEntry();
+
if ( getOperationContext().isNoAttributes() )
{
for ( Attribute attribute : originalEntry.getAttributes() )
@@ -379,53 +320,52 @@ public class BaseEntryFilteringCursor im
AttributeType attributeType = attribute.getAttributeType();
entry.remove( entry.get( attributeType ) );
}
-
+
return;
}
-
-
+
if ( getOperationContext().isAllUserAttributes() )
{
for ( Attribute attribute : originalEntry.getAttributes() )
{
AttributeType attributeType = attribute.getAttributeType();
boolean isNotRequested = true;
-
- for ( AttributeTypeOptions attrOptions:getOperationContext().getReturningAttributes() )
+
+ for ( AttributeTypeOptions attrOptions : getOperationContext().getReturningAttributes() )
{
- if ( attrOptions.getAttributeType().equals( attributeType ) ||
+ if ( attrOptions.getAttributeType().equals( attributeType ) ||
attrOptions.getAttributeType().isAncestorOf( attributeType ) )
{
isNotRequested = false;
break;
}
}
-
+
boolean isNotUserAttribute = attributeType.getUsage() != UsageEnum.USER_APPLICATIONS;
-
- if ( isNotRequested && isNotUserAttribute )
+
+ if ( isNotRequested && isNotUserAttribute )
{
entry.removeAttributes( attributeType );
}
- else if( typesOnly )
+ else if ( typesOnly )
{
entry.get( attributeType ).clear();
}
}
-
+
return;
}
-
+
if ( getOperationContext().isAllOperationalAttributes() )
{
for ( Attribute attribute : originalEntry.getAttributes() )
{
AttributeType attributeType = attribute.getAttributeType();
boolean isNotRequested = true;
-
- for ( AttributeTypeOptions attrOptions:getOperationContext().getReturningAttributes() )
+
+ for ( AttributeTypeOptions attrOptions : getOperationContext().getReturningAttributes() )
{
- if ( attrOptions.getAttributeType().equals( attributeType ) ||
+ if ( attrOptions.getAttributeType().equals( attributeType ) ||
attrOptions.getAttributeType().isAncestorOf( attributeType ) )
{
isNotRequested = false;
@@ -434,73 +374,70 @@ public class BaseEntryFilteringCursor im
}
boolean isUserAttribute = attributeType.getUsage() == UsageEnum.USER_APPLICATIONS;
-
+
if ( isNotRequested && isUserAttribute )
{
entry.removeAttributes( attributeType );
}
- else if( typesOnly )
+ else if ( typesOnly )
{
entry.get( attributeType ).clear();
}
}
-
+
return;
}
-
+
if ( getOperationContext().getReturningAttributes() != null )
{
for ( Attribute attribute : originalEntry.getAttributes() )
{
AttributeType attributeType = attribute.getAttributeType();
boolean isNotRequested = true;
-
- for ( AttributeTypeOptions attrOptions:getOperationContext().getReturningAttributes() )
+
+ for ( AttributeTypeOptions attrOptions : getOperationContext().getReturningAttributes() )
{
- if ( attrOptions.getAttributeType().equals( attributeType ) ||
+ if ( attrOptions.getAttributeType().equals( attributeType ) ||
attrOptions.getAttributeType().isAncestorOf( attributeType ) )
{
isNotRequested = false;
break;
}
}
-
+
if ( isNotRequested )
{
entry.removeAttributes( attributeType );
}
- else if( typesOnly )
+ else if ( typesOnly )
{
entry.get( attributeType ).clear();
}
}
}
}
-
-
- /*
- * @see Cursor#next()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#next()
+
+
+ /**
+ * {@inheritDoc}
*/
public boolean next() throws Exception
{
if ( getOperationContext().isAbandoned() )
{
- log.info( "Cursor has been abandoned." );
+ LOG.info( "Cursor has been abandoned." );
close();
throw new OperationAbandonedException();
}
-
+
Entry tempResult = null;
-
+
outer: while ( wrapped.next() )
{
boolean accepted = true;
-
+
Entry tempEntry = wrapped.get();
-
+
if ( tempEntry instanceof ClonedServerEntry )
{
tempResult = tempEntry;
@@ -509,7 +446,7 @@ public class BaseEntryFilteringCursor im
{
tempResult = new ClonedServerEntrySearch( tempEntry );
}
-
+
/*
* O P T I M I Z A T I O N
* -----------------------
@@ -517,67 +454,64 @@ public class BaseEntryFilteringCursor im
* Don't want to waste cycles on enabling a loop for processing
* filters if we have zero or one filter.
*/
-
+
if ( filters.isEmpty() )
{
prefetched = tempResult;
filterContents( prefetched );
return true;
}
-
- if ( ( filters.size() == 1 ) && filters.get( 0 ).accept( getOperationContext(), tempResult ) )
+
+ if ( ( filters.size() == 1 ) && filters.get( 0 ).accept( getOperationContext(), tempResult ) )
{
prefetched = tempResult;
filterContents( prefetched );
return true;
}
-
+
/* E N D O P T I M I Z A T I O N */
for ( EntryFilter filter : filters )
{
// if a filter rejects then short and continue with outer loop
- if ( ! ( accepted &= filter.accept( getOperationContext(), tempResult ) ) )
+ if ( !( accepted &= filter.accept( getOperationContext(), tempResult ) ) )
{
continue outer;
}
}
-
+
/*
* Here the entry has been accepted by all filters.
*/
prefetched = tempResult;
filterContents( prefetched );
-
+
return true;
}
-
+
prefetched = null;
return false;
}
- /*
- * @see Cursor#previous()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#previous()
+ /**
+ * {@inheritDoc}
*/
public boolean previous() throws Exception
{
if ( getOperationContext().isAbandoned() )
{
- log.info( "Cursor has been abandoned." );
+ LOG.info( "Cursor has been abandoned." );
close();
throw new OperationAbandonedException();
}
-
+
Entry tempResult = null;
-
+
outer: while ( wrapped.previous() )
{
boolean accepted = true;
tempResult = new ClonedServerEntrySearch( wrapped.get() );
-
+
/*
* O P T I M I Z A T I O N
* -----------------------
@@ -585,32 +519,32 @@ public class BaseEntryFilteringCursor im
* Don't want to waste cycles on enabling a loop for processing
* filters if we have zero or one filter.
*/
-
+
if ( filters.isEmpty() )
{
prefetched = tempResult;
filterContents( prefetched );
return true;
}
-
+
if ( ( filters.size() == 1 ) && filters.get( 0 ).accept( getOperationContext(), tempResult ) )
{
prefetched = tempResult;
filterContents( prefetched );
return true;
}
-
+
/* E N D O P T I M I Z A T I O N */
-
+
for ( EntryFilter filter : filters )
{
// if a filter rejects then short and continue with outer loop
- if ( ! ( accepted &= filter.accept( getOperationContext(), tempResult ) ) )
+ if ( !( accepted &= filter.accept( getOperationContext(), tempResult ) ) )
{
continue outer;
}
}
-
+
/*
* Here the entry has been accepted by all filters.
*/
@@ -618,18 +552,15 @@ public class BaseEntryFilteringCursor im
filterContents( prefetched );
return true;
}
-
+
prefetched = null;
-
+
return false;
}
- /*
- * @see Iterable#iterator()
- */
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.filtering.EntryFilteringCursor#iterator()
+ /**
+ * {@inheritDoc}
*/
public Iterator<Entry> iterator()
{
Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java Thu Dec 29 23:54:19 2011
@@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class CursorList implements EntryFilteringCursor
+public class CursorList extends AbstractEntryFilteringCursor
{
/** The inner List */
private final List<EntryFilteringCursor> list;
@@ -58,9 +58,6 @@ public class CursorList implements Entry
/** The current position in the list */
private int index = -1;
- /** the operation context */
- private SearchingOperationContext searchContext;
-
/** flag to detect the closed cursor */
private boolean closed;
@@ -81,6 +78,8 @@ public class CursorList implements Entry
*/
public CursorList( int start, List<EntryFilteringCursor> list, int end, SearchingOperationContext searchContext )
{
+ super( searchContext );
+
if ( list != null )
{
this.list = list;
@@ -109,7 +108,6 @@ public class CursorList implements Entry
this.start = start;
this.end = end;
- this.searchContext = searchContext;
}
@@ -130,7 +128,7 @@ public class CursorList implements Entry
*/
public boolean available()
{
- if ( index >= 0 && index < end )
+ if ( ( index >= 0 ) && ( index < end ) )
{
return list.get( index ).available();
}
@@ -375,11 +373,14 @@ public class CursorList implements Entry
{
return list.get( index ).get();
}
-
+
throw new InvalidCursorPositionException();
}
+ /**
+ * {@inheritDoc}
+ */
public boolean addEntryFilter( EntryFilter filter )
{
for ( EntryFilteringCursor efc : list )
@@ -392,51 +393,43 @@ public class CursorList implements Entry
}
+ /**
+ * {@inheritDoc}
+ */
public List<EntryFilter> getEntryFilters()
{
throw new UnsupportedOperationException( "CursorList doesn't support this operation" );
}
- public SearchingOperationContext getOperationContext()
- {
- return searchContext;
- }
-
-
- public boolean isAbandoned()
- {
- return getOperationContext().isAbandoned();
- }
-
-
+ /**
+ * {@inheritDoc}
+ */
public boolean removeEntryFilter( EntryFilter filter )
{
return false;
}
- public void setAbandoned( boolean abandoned )
- {
- getOperationContext().setAbandoned( abandoned );
-
- if ( abandoned )
- {
- LOG.info( "Cursor has been abandoned." );
- }
- }
-
-
+ /**
+ * {@inheritDoc}
+ */
public void close() throws Exception
{
close( null );
}
+ /**
+ * {@inheritDoc}
+ */
+ /**
+ * {@inheritDoc}
+ */
public void close( Exception reason ) throws Exception
{
closed = true;
-
+
for ( Cursor<?> c : list )
{
try
@@ -455,21 +448,42 @@ public class CursorList implements Entry
LOG.warn( "Failed to close the cursor" );
}
}
+
+ if ( txnManager != null )
+ {
+ if ( reason == null )
+ {
+ txnManager.commitTransaction();
+ }
+ else
+ {
+ txnManager.abortTransaction();
+ }
+ }
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isClosed() throws Exception
{
return closed;
}
+ /**
+ * {@inheritDoc}
+ */
public Iterator<Entry> iterator()
{
throw new UnsupportedOperationException();
}
+ /**
+ * {@inheritDoc}
+ */
public void setClosureMonitor( ClosureMonitor monitor )
{
for ( Cursor c : list )
@@ -477,5 +491,4 @@ public class CursorList implements Entry
c.setClosureMonitor( monitor );
}
}
-
}
Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursor.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursor.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/EntryFilteringCursor.java Thu Dec 29 23:54:19 2011
@@ -23,6 +23,8 @@ package org.apache.directory.server.core
import java.util.List;
import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
+import org.apache.directory.server.core.api.txn.TxnHandle;
+import org.apache.directory.server.core.api.txn.TxnManager;
import org.apache.directory.shared.ldap.model.cursor.Cursor;
import org.apache.directory.shared.ldap.model.entry.Entry;
@@ -35,13 +37,12 @@ import org.apache.directory.shared.ldap.
*/
public interface EntryFilteringCursor extends Cursor<Entry>
{
-
/**
* Gets whether or not this BaseEntryFilteringCursor has been abandoned.
*
* @return true if abandoned, false if not
*/
- public abstract boolean isAbandoned();
+ boolean isAbandoned();
/**
@@ -49,7 +50,7 @@ public interface EntryFilteringCursor ex
*
* @param abandoned true if abandoned, false if not
*/
- public abstract void setAbandoned( boolean abandoned );
+ void setAbandoned( boolean abandoned );
/**
@@ -59,7 +60,7 @@ public interface EntryFilteringCursor ex
* @param filter a filter to apply to the entries
* @return the result of {@link List#add(Object)}
*/
- public abstract boolean addEntryFilter( EntryFilter filter );
+ boolean addEntryFilter( EntryFilter filter );
/**
@@ -69,7 +70,7 @@ public interface EntryFilteringCursor ex
* @param filter a filter to remove from the filter list
* @return the result of {@link List#remove(Object)}
*/
- public abstract boolean removeEntryFilter( EntryFilter filter );
+ boolean removeEntryFilter( EntryFilter filter );
/**
@@ -77,11 +78,24 @@ public interface EntryFilteringCursor ex
*
* @return an unmodifiable list of EntryFilters applied
*/
- public abstract List<EntryFilter> getEntryFilters();
+ List<EntryFilter> getEntryFilters();
/**
* @return the operationContext
*/
- public abstract SearchingOperationContext getOperationContext();
+ SearchingOperationContext getOperationContext();
+
+
+ /**
+ * Associate the transaction manager to this cursor
+ * @param txnManager The associated TxnManager
+ */
+ void setTxnManager( TxnManager txnManager );
+
+
+ /**
+ * @return the associated transaction to this cursor
+ */
+ TxnHandle getTransaction();
}
\ No newline at end of file
Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnConflictException.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnConflictException.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnConflictException.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnConflictException.java Thu Dec 29 23:54:19 2011
@@ -19,6 +19,7 @@
*/
package org.apache.directory.server.core.api.txn;
+
/**
* An exception used when the txn conflict is detected.
*
@@ -47,5 +48,4 @@ public class TxnConflictException extend
{
super( s, cause );
}
-
}
\ No newline at end of file
Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java Thu Dec 29 23:54:19 2011
@@ -19,10 +19,12 @@
*/
package org.apache.directory.server.core.api.txn;
-/*
+
+/**
* A handle for clients to use to communicate with txn layer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public interface TxnHandle
{
-
}
Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java Thu Dec 29 23:54:19 2011
@@ -29,7 +29,6 @@ public interface TxnManager
/**
* Starts a new txn and associates it with the current thread.
*
- * @param readOnly whether the txn is read only
* @throws Exception
*/
void beginTransaction( boolean readOnly ) throws Exception;
@@ -43,15 +42,16 @@ public interface TxnManager
* @throws TxnConflictException
*/
void commitTransaction() throws Exception, TxnConflictException;
-
+
+
/**
* Aborts the current txn associated with the current thread.
*
* @throws Exception
*/
void abortTransaction() throws Exception;
-
-
+
+
/**
* Suspends the execution of the current txn and returns
* a handle to it.
@@ -59,28 +59,27 @@ public interface TxnManager
* @return handle for the current txn
*/
TxnHandle suspendCurTxn();
-
-
+
+
/**
* Resumes the execution of the txn corresponding to the given
* handle
*
* @param txnHandle handle for the txn to resume.
*/
- void resumeTxn( TxnHandle txnHandle);
-
-
+ void resumeTxn( TxnHandle txnHandle );
+
+
/**
* returns a handle for the current txn
*
* @return handle for the current txn
*/
TxnHandle getCurTxn();
-
-
+
+
/**
* Flushes the committed txns to partitions.
*/
void applyPendingTxns();
-
}
Modified: directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/authz/AuthorizationServiceAsNonAdminIT.java Thu Dec 29 23:54:19 2011
@@ -30,6 +30,7 @@ import java.util.Arrays;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.api.CoreSession;
import org.apache.directory.server.core.api.LdapPrincipal;
+import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
import org.apache.directory.server.core.integ.FrameworkRunner;
import org.apache.directory.shared.ldap.model.constants.AuthenticationLevel;
@@ -48,6 +49,9 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.model.message.SearchScope;
import org.apache.directory.shared.ldap.model.name.Dn;
import org.apache.directory.shared.ldap.model.name.Rdn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,10 +62,30 @@ import org.junit.runner.RunWith;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-@RunWith ( FrameworkRunner.class )
+@RunWith(FrameworkRunner.class)
@CreateDS(name = "AuthorizationServiceAsNonAdminIT")
-public class AuthorizationServiceAsNonAdminIT extends AbstractLdapTestUnit
+public class AuthorizationServiceAsNonAdminIT extends AbstractLdapTestUnit
{
+ private CoreSession session;
+ private CoreSession userSession;
+ private SchemaManager schemaManager;
+
+
+ @Before
+ public void setup() throws Exception
+ {
+ LdifEntry akarasulu = getUserAddLdif();
+
+ session = getService().getAdminSession();
+ schemaManager = getService().getSchemaManager();
+
+ session.add( new DefaultEntry( schemaManager, akarasulu.getEntry() ) );
+ Dn userDn = new Dn( schemaManager, "uid=akarasulu,ou=users,ou=system" );
+ LdapPrincipal principal = new LdapPrincipal( schemaManager, userDn,
+ AuthenticationLevel.SIMPLE );
+ userSession = getService().getSession( principal );
+ }
+
/**
* Makes sure a non-admin user cannot delete the admin account.
@@ -71,14 +95,29 @@ public class AuthorizationServiceAsNonAd
@Test
public void testNoDeleteOnAdminByNonAdmin() throws Exception
{
- LdifEntry akarasulu = getUserAddLdif();
+ try
+ {
+ userSession.delete( new Dn( "uid=admin,ou=system" ) );
+ fail( "User 'admin' should not be able to delete his account" );
+ }
+ catch ( LdapNoPermissionException e )
+ {
+ assertNotNull( e );
+ }
+ }
- getService().getAdminSession().add(
- new DefaultEntry( getService().getSchemaManager(), akarasulu.getEntry() ) );
+ /**
+ * Makes sure the admin user cannot delete the admin account.
+ *
+ * @throws Exception if there are problems
+ */
+ @Test
+ public void testNoDeleteOnAdminByAdmin() throws Exception
+ {
try
{
- getService().getAdminSession().delete( new Dn( "uid=admin,ou=system") );
+ session.delete( new Dn( "uid=admin,ou=system" ) );
fail( "User 'admin' should not be able to delete his account" );
}
catch ( LdapNoPermissionException e )
@@ -96,14 +135,9 @@ public class AuthorizationServiceAsNonAd
@Test
public void testNoRdnChangesOnAdminByNonAdmin() throws Exception
{
- LdifEntry akarasulu = getUserAddLdif();
-
- getService().getAdminSession().add(
- new DefaultEntry( getService().getSchemaManager(), akarasulu.getEntry() ) );
-
try
{
- getService().getAdminSession().rename(
+ userSession.rename(
new Dn( "uid=admin,ou=system" ),
new Rdn( "uid=alex" ),
false );
@@ -124,27 +158,21 @@ public class AuthorizationServiceAsNonAd
@Test
public void testModifyOnAdminByNonAdmin() throws Exception
{
- LdifEntry akarasulu = getUserAddLdif();
-
- getService().getAdminSession().add(
- new DefaultEntry( getService().getSchemaManager(), akarasulu.getEntry() ) );
-
+ LdifEntry user = getUserAddLdif();
+
// Read the entry we just created using the akarasuluSession
- Entry readEntry = getService().getAdminSession().lookup( akarasulu.getDn(), new String[]{ "userPassword"} );
-
- assertTrue( Arrays.equals( akarasulu.get( "userPassword" ).getBytes(), readEntry.get( "userPassword" ).getBytes() ) );
+ Entry readEntry = session.lookup( user.getDn(), "userPassword" );
+
+ assertTrue( Arrays.equals( user.get( "userPassword" ).getBytes(), readEntry.get( "userPassword" )
+ .getBytes() ) );
Attribute attribute = new DefaultAttribute( "userPassword", "replaced" );
Modification mod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute );
-
- Dn userDn = new Dn( getService().getSchemaManager(), "uid=akarasulu,ou=users,ou=system" );
- LdapPrincipal principal = new LdapPrincipal( getService().getSchemaManager(), userDn, AuthenticationLevel.SIMPLE );
- CoreSession akarasuluSession = getService().getSession( principal );
try
{
- akarasuluSession.modify( new Dn( "uid=admin,ou=system" ), mod );
+ userSession.modify( new Dn( "uid=admin,ou=system" ), mod );
fail( "User 'uid=admin,ou=system' should not be able to modify attributes on admin" );
}
catch ( Exception e )
@@ -159,21 +187,28 @@ public class AuthorizationServiceAsNonAd
* @throws Exception if there are problems
*/
@Test
+ @Ignore
+ // This test is blantantly wrong
public void testNoSearchByNonAdmin() throws Exception
{
LdifEntry akarasulu = getUserAddLdif();
-
- getService().getAdminSession().add(
- new DefaultEntry( getService().getSchemaManager(), akarasulu.getEntry() ) );
+
+ session.add(
+ new DefaultEntry( schemaManager, akarasulu.getEntry() ) );
+
+ ExprNode filter = FilterParser.parse( schemaManager, "(objectClass=*)" );
+ EntryFilteringCursor cursor = userSession.search( new Dn( "ou=system" ), SearchScope.OBJECT, filter,
+ AliasDerefMode.DEREF_ALWAYS, null );
+ cursor.next();
try
{
- ExprNode filter = FilterParser.parse( getService().getSchemaManager(), "(objectClass=*)" );
- getService().getAdminSession().search( new Dn( "ou=system" ), SearchScope.SUBTREE, filter , AliasDerefMode.DEREF_ALWAYS, null );
+ cursor.get();
}
catch ( LdapNoPermissionException e )
{
assertNotNull( e );
+ cursor.close();
}
}
}