Skip to content
Permalink
Browse files
Relax control no longer works with 2.0 ldap api
  • Loading branch information
shawnmckinney committed Jun 23, 2021
1 parent 36e8249 commit faf737e60f64f65c1bcaf8f90e9e4a2ebe36d1e6
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 47 deletions.
@@ -275,7 +275,7 @@ protected void add( LdapConnection connection, Entry entry, FortEntity entity, b
// TODO: FIXME #2
if ( setRelaxControl )
{
//addRequest.addControl( new RelaxControlImpl() );
addRequest.addControl( new RelaxControlImpl() );
}
AddResponse response = connection.add( addRequest );
ResultCodeEnum.processResponse(response);
@@ -353,7 +353,7 @@ protected void modify( LdapConnection connection, String dn, List<Modification>
// TODO: FIXME #2
if ( setRelaxControl )
{
//modRequest.addControl( new RelaxControlImpl() );
modRequest.addControl( new RelaxControlImpl() );
}
modRequest.setName( new Dn( dn ) );
ModifyResponse response = connection.modify( modRequest );
@@ -0,0 +1,34 @@
package org.apache.directory.fortress.core.ldap;


import org.apache.directory.api.asn1.Asn1Object;
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.ldap.codec.api.ControlDecorator;
import org.apache.directory.api.ldap.codec.api.LdapApiService;

import java.nio.ByteBuffer;


public class RelaxControlDecorator extends ControlDecorator<RelaxControl> implements RelaxControl
{
public RelaxControlDecorator(LdapApiService codec, RelaxControl control)
{
super(codec, control);
}

public int computeLength()
{
return 0;
}

public Asn1Object decode(byte[] controlBytes) throws DecoderException
{
return this;
}

public ByteBuffer encode(ByteBuffer buffer) throws EncoderException
{
return buffer;
}
}
@@ -0,0 +1,70 @@
package org.apache.directory.fortress.core.ldap;


import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.codec.api.CodecControl;
import org.apache.directory.api.ldap.codec.api.ControlContainer;
import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.model.message.Control;


/**
* A codec {@link ControlFactory} implementation for {@link RelaxControl} controls.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class RelaxControlFactory implements ControlFactory<RelaxControl>
{
/** The LDAP codec responsible for encoding and decoding Cascade Controls */
private LdapApiService codec;


/**
* Creates a new instance of TransactionSpecificationFactory.
*
* @param codec The LDAP codec
*/
public RelaxControlFactory( LdapApiService codec )
{
this.codec = codec;
}


/**
* {@inheritDoc}
*/
@Override
public String getOid()
{
return RelaxControl.OID;
}


/**
* {@inheritDoc}
*/
@Override
public CodecControl<RelaxControl> newControl()
{
return new RelaxControlDecorator( codec, new RelaxControlImpl() );
}


public void encodeValue(Asn1Buffer var1, Control var2)
{

}

public void decodeValue(ControlContainer var1, Control var2, byte[] var3) throws DecoderException
{

}

public void decodeValue(Control var1, byte[] var2) throws DecoderException
{

}

}
@@ -22,6 +22,8 @@

import org.apache.directory.fortress.core.model.PwPolicy;
import org.apache.directory.fortress.core.impl.TestUtils;
import org.apache.directory.fortress.core.model.Session;
import org.apache.directory.fortress.core.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -163,4 +165,27 @@ void add()
}
ReaderUtil.readChar();
}


void assignPolicy()
{
try
{
ReaderUtil.clearScreen();
System.out.println("Enter userId");
String userId = ReaderUtil.readLn();
System.out.println("Enter password policy name or NULL to skip");
String plcyNm = ReaderUtil.readLn();
pm.updateUserPolicy( userId, plcyNm );
System.out.println("userId [" + userId + "]");
System.out.println("policy name [" + plcyNm + "]");
System.out.println("has been updated");
System.out.println("ENTER to continue");
}
catch (SecurityException e)
{
LOG.error("assignPolicy caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
}
ReaderUtil.readChar();
}
}
@@ -902,51 +902,7 @@ void processPasswordPolicyFunction()
policyConsole.add();
break;
case '2':
//policyConsole.updatePolicy();
break;
case '3':
//policyConsole.deletePolicy();
break;
case '4':
//policyConsole.readPolicy();
break;
case '5':
//policyConsole.findPolicies();
break;
case '6':
//policyConsole.updateUserPolicy();
break;
case '7':
//policyConsole.deleteUserPasswordPolicy();
break;
case '8':
//policyConsole.readOperationalAttributes();
break;
case '9':
//policyConsole.resetUserPassword();
break;
case '0':
//adminConsole.unlockAccount();
break;
case 'a':
case 'A':
//policyConsole.lockUserAccount();
break;
case 'b':
case 'B':
//policyConsole.clearResetFlag();
break;
case 'c':
case 'C':
//policyConsole.checkPasswordPolicy();
break;
case 'd':
case 'D':
//policyConsole.getLockedUsers();
break;
case 'e':
case 'E':
//policyConsole.isLockedUser();
policyConsole.assignPolicy();
break;
case 'q':
case 'Q':
@@ -972,6 +928,7 @@ private void showPasswordPolicyFunctionMenu()
ReaderUtil.clearScreen();
System.out.println( "CHOOSE PASSWORD POLICY FUNCTION:" );
System.out.println( "1. Create Password Policy" );
System.out.println( "2. Assign Password Policy to User" );
System.out.println( "Enter q or Q to return to previous menu" );
}

0 comments on commit faf737e

Please sign in to comment.