是否可以通过 cfldap 更改密码?

2024-01-02

一段时间以来,我一直尝试通过以下方式更改密码cfldap。连接是通过 SSL 和端口 636 建立的(cfssl_basic),在登录中进行测试。我尝试了以下版本的代码:

<cfset password_new_retyp=charsetEncode(charsetDecode('"'&password_new_retyp&'"','UTF-16LE'),'UTF-8'))>
<!---encoded, decoded password --->
<cfldap action="modify"
    dn="#session.dn_addres#" --- i query this on login
    modifyType="replace"
    attributes="unicodePwd=#password_new_retyp#"
    server="xxxx.xxxx.xxx.xx" --- name of server thet i use on login
    secure = "cfssl_basic" 
    port=636
    username="#session.username#" ---username thet is used on login
    password="#password_old#">  ---- pass before changing

错误是这样的:

尝试执行查询时发生错误:[LDAP:错误代码 49 - 80090308:LdapErr:DSID-0C0903C5,注释:AcceptSecurityContext 错误,数据 52e,v23f0]。

我也尝试过这种方法,无需对密码进行编码:

<cfldap action="modify"
    dn="#session.dn_addres#"
    modifyType="replace"
    attributes="password=#password_new_retyp#"
    server="xxxx.xxxx.xxx.xx"
    secure = "cfssl_basic"
    port=636
    username="#session.username#"
    password="#password_old#" >

和错误是相同的:

尝试执行查询时发生错误:[LDAP:错误代码 49 - 80090308:LdapErr:DSID-0C0903C5,注释:AcceptSecurityContext 错误,数据 52e,v23f0]。 一个或多个必需的属性可能丢失或不正确,或者您无权在服务器上执行此操作。

任何想法?


这是一条漫长而艰难的路,但我还是到达了那里。我希望这对尝试更改密码和实施 LDAP 密码策略的其他人有所帮助。

资料来源:基于 Edward Smith 的代码已存档的 CFTalk 线程 https://groups.yahoo.com/neo/groups/CFTalk/conversations/topics/160110

<cftry>
    <cfscript>
        // You are going to use  the user's credentials to login to LDAP
        // Assuming your LDAP is set up to do so

        // Set up varibles
        newPassword = '"#newPassword#"';
        oldPassword = '"#currentPassword#"';
        // You would probably pass in a variable here, I typed it out so you would ss the format its expecting
        distinguishedName = "CN=theUser,OU=someOU,DC=DDDD,DC=CCC,DC=AAA,DC=ZZZ";
        newUnicodePassword = newPassword.getBytes("UnicodeLittleUnmarked");
        oldUnicodePassword = oldPassword.getBytes("UnicodeLittleUnmarked");
        ldapsURL = "ldap://#ldapServer#:#ldapPort#";

        // Create a Java Hashtable
        javaEnv = CreateObject("java", "java.util.Hashtable").Init();

        // Put stuff in the Hashtable
        javaEnv.put("java.naming.provider.url", ldapsURL);
        // The user's Full DN and Password
        javaEnv.put("java.naming.security.principal", "#distinguishedName#");
        javaEnv.put("java.naming.security.credentials", "#currentPassword#");
        javaEnv.put("java.naming.security.authentication", "simple");
        javaEnv.put("java.naming.security.protocol", "ssl");
        javaEnv.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory");

        // Create a Java InitialDirContext
        javaCtx = CreateObject("java", "javax.naming.directory.InitialDirContext").Init(javaEnv);

        // Create two Java BasicAttributes
        oldBA = CreateObject("java", "javax.naming.directory.BasicAttribute").Init("unicodePwd", oldUnicodePassword);
        newBA = CreateObject("java", "javax.naming.directory.BasicAttribute").Init("unicodePwd", newUnicodePassword);

        /***********************************************
        *   Stick the attributes into an Java Array and tell it what to do with them
        *   Guess what? A CF Array = a Java Array
        *   1 = DirContext.ADD_ATTRIBUTE
        *   2 = DirContext.REPLACE_ATTRIBUTE
        *   3 = DirContext.REMOVE_ATTRIBUTE
        *  This is the big trick 
        *   If you login above as an admin then you only need to do a 2 Replace but will not run LDAP passoword policy (lenght, complexity, history... etc.)
        *       It will let you change password to anything
        *   If you want to check the LDAP password policy then you need to create the array and first Remove (3) then Add (1)
        *       Error Code 19 means something in the LDAP password policy was violated
        *           I haven't figured out how to read what the error is (like "password length too short" or "you have used this password in the past")
        *       Error Code 49 means invalid username/password
        ************************************************/
        mods = [
            createObject( "java", "javax.naming.directory.ModificationItem").init(3, oldBA),
            createObject( "java", "javax.naming.directory.ModificationItem").init(1, newBA)
        ]; 
        // Run it
        javaCtx.modifyAttributes(distinguishedName,mods);
        javaCtx.close();
    </cfscript>
    // Yeah! I could have scripted the cfcatch but this was easier.
    <cfcatch>
        <cfif find('error code 19',cfcatch.message)>
            <!--- I am using cfwheels so this just displays a nice error message on the next page --->
            <cfset flashInsert(error="New password does not meet requirements defined in the password rules.")>
        <cfelseif isDefined('cfcatch.RootCause.cause.Explanation') and find('error code 49', cfcatch.RootCause.cause.Explanation)>
            <!--- I am using cfwheels so this just displays a nice error message on the next page --->
            <cfset flashInsert(error="Current Password IS incorrect.")>
        <cfelse>    
            <!--- This just pukes the error up hard and uncaught --->
            <cfrethrow>
        </cfif>
        <cfset hasError = true>
    </cfcatch>  
</cftry>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

是否可以通过 cfldap 更改密码? 的相关文章

随机推荐

  • JavaScript 数组到 CSV

    我关注了这个帖子如何将 JavaScript 数组信息导出到 csv 在客户端 https stackoverflow com questions 14964035 how to export javascript array info t
  • 模型内的简单验证规则

    我在这里提到Laravel 4 2 验证规则 当前密码必须与数据库值匹配 https stackoverflow com questions 24830119 laravel 4 2 validation rules current pas
  • 根据父级 div 大小按比例调整图像大小

    我正在使用全浏览器宽度高度 jquery blockUI 来显示从图库中选择的图像 下图是 blockUI 中的视图方案 基本上侧块 UI 中的视图的宽度和高度设置为 100 里面还有两个 div 右侧的宽度设置为视图的 80 并且包含图像
  • 以编程方式更改“默认使用此操作”

    我有普通的 电话 拨号器和新的 拨号器 应用程序 现在 如果我选中 默认情况下使用此操作 并单击 拨号器 应用程序 那么每次按下电话按钮时 拨号器 应用程序都会自动启动 但我怎样才能在代码中改变它呢 此首选项存储在哪里 这是如何映射的 这是
  • 计算椭圆尺寸与距中心点距离的关系

    我想在每次崩溃时实现尺寸的缓慢消失 换句话说 当圆最大时 椭圆的尺寸也最大 反之 收缩时则相反 到目前为止 我试图通过从中心点的距离重新映射 cSize 来实现这种影响 但在此过程中的某个地方出了问题 目前 我的椭圆尺寸正在从小到大的缓慢过
  • 通过正则表达式获取模式的不匹配部分

    在本主题中 想法是 剥离 数字 除以x通过正则表达式 gt 如何使用 Excel 正则表达式从字符串中提取广告尺寸 https stackoverflow com questions 48427343 how to extract ad s
  • 在 Windows 7 中使用 .NET Windows 服务显示消息框

    在 Windows 7 中使用 NET Windows 服务显示消息框 我们有一个 Windows 服务 用于在用户在 Windows XP 上扫描访问卡后显示确认消息框 但一旦我们迁移到 Windows 7 该弹出功能就不再起作用 正如这
  • XSL 显示属性名称

    所以 用那个
  • 如何通过 SQL 查询特定 JSON 格式的父子关系?

    我希望我的 jQuery 代码有这个 JSON projects id 1 project name Carmichael House parent id 0 children id 2 project name Carmichael Ki
  • Node.js 中的加密

    我正在尝试将以下 php 代码移植到 node js 上的 javascript mac hash hmac SHA256 string secret true coded base64 encode mac 我尝试过以下方法 var Cr
  • CSS“clip”的 Safari 渲染错误

    我在使用 Safari 时遇到以下问题 http cl ly ZlJ8 http cl ly ZlJ8 现场演示 http drpdev de labs example html http drpdev de labs example ht
  • 在AVPlayer中使用秒seekToTime

    这应该是一个简单的问题 我有一个AVPlayer播放视频文件 我希望能够跳到特定时间 但我在理解如何跳到特定时间时遇到了一些困难CMTime works 我需要以秒为单位指定时间 例如 如果我想跳到第二个 10 8 我想做这样的事情 sel
  • Windows 10 和 Visual Studio 2015

    我可以开始使用 Visual Studio 2015 预览版在预览版上构建 Windows 10 应用程序吗 或者至少开始修补和测试 3 月 23 日更新 适用于 Windows 10 技术预览版的 Visual Studio 工具 htt
  • 将 EJB 方法公开为 REST 服务

    在 J2EE 6 中 您可以将 EJB 会话 bean 公开为 REST Web 服务 如下所示 Stateless Path test public class TestSessionBean GET Produces applicati
  • 无法删除该对象,因为在 ObjectStateManager 中未找到该对象

    我收到此错误 无法删除该对象 因为在 ObjectStateManager 中未找到该对象 我的代码是 protected MyEntities sqlEntities public virtual void Delete TEntity
  • 隐藏 JComBox 框箭头

    是否可以隐藏JComboBox中显示的箭头 我尝试设置 combo getComponent 0 setSize new Dimension 1 1 但似乎不起作用 您必须为此创建一个新的组合框 UI combo setUI new Bas
  • 在 Laravel 中获取每个用户的最新消息(行)

    TL DR 需要来自每个发件人的最新消息 在我的 Laravel 应用程序中 我有两个表 Users id name 留言 id 发件人ID 收件人 ID body 创建时间 当然还有模型 用户模型 public function mess
  • HttpWeb请求错误403

    我是 C 新手 需要从 C 检索 url 大多数情况下它工作正常 但在一种情况下它会抛出错误 网址如下http whois afrinic net cgi bin whois searchtext 41 132 178 138 http w
  • ObjC 到 Swift 将 NSDictionary 转换为 NSObject : AnyObject

    我正在使用 Swift 实现 Segment com 的 iOS 库 一切都运行良好 只是停留在下面的代码转换上identify method ref https segment com docs libraries ios identif
  • 是否可以通过 cfldap 更改密码?

    一段时间以来 我一直尝试通过以下方式更改密码cfldap 连接是通过 SSL 和端口 636 建立的 cfssl basic 在登录中进行测试 我尝试了以下版本的代码