private void changePasswordUsingAttributeModification (DistinguishedName userDn, String oldPassword, String newPassword) { final ModificationItem[] passwordChange = new ModificationItem[] { new ModificationItem( DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(passwordAttributeName, newPassword)) }; if (oldPassword == null) { template.modifyAttributes(userDn, passwordChange); return; } template.executeReadWrite(dirCtx -> { LdapContext ctx = (LdapContext) dirCtx; ctx.removeFromEnvironment("com.sun.jndi.ldap.connect.pool"); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, LdapUtils.getFullDn(userDn, ctx).toString()); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, oldPassword); // TODO: reconnect doesn't appear to actually change the credentials try { ctx.reconnect(null); } catch (javax.naming.AuthenticationException e) { throw new BadCredentialsException( "Authentication for password change failed."); } ctx.modifyAttributes(userDn, passwordChange); return null; }); }
@Override public Void execute(LdapContext context) throws NamingException { context.modifyAttributes(dn, mods); return null; } });
@Override public Void execute(LdapContext context) throws NamingException { context.modifyAttributes(dn, mods); return null; } });
public static void loadPrescriptiveTriggerSpecification( LdapContext apCtx, String subentryCN, String triggerSpec ) throws NamingException { Attributes changes = new BasicAttributes( PRESCRIPTIVE_TRIGGER_SPECIFICATION_ATTR, triggerSpec, true ); apCtx.modifyAttributes( "cn=" + subentryCN, DirContext.ADD_ATTRIBUTE, changes ); }
public static void loadPrescriptiveTriggerSpecification( LdapContext apCtx, String subentryCN, String triggerSpec ) throws NamingException { Attributes changes = new BasicAttributes( PRESCRIPTIVE_TRIGGER_SPECIFICATION_ATTR, triggerSpec, true ); apCtx.modifyAttributes( "cn=" + subentryCN, DirContext.ADD_ATTRIBUTE, changes ); }
public static void loadEntryTriggerSpecification( LdapContext ctx, String triggerSpec ) throws NamingException { Attributes changes = new BasicAttributes( ENTRY_TRIGGER_SPECIFICATION_ATTR, triggerSpec, true ); ctx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
public static void loadEntryTriggerSpecification( LdapContext ctx, String triggerSpec ) throws NamingException { Attributes changes = new BasicAttributes( ENTRY_TRIGGER_SPECIFICATION_ATTR, triggerSpec, true ); ctx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
/** * Load the trigger specification entry * * @param ctx The context * @param triggerSpec The trigger specification * @throws NamingException If the operation failed */ public static void loadEntryTriggerSpecification( LdapContext ctx, String triggerSpec ) throws NamingException { Attributes changes = new BasicAttributes( SchemaConstants.ENTRY_TRIGGER_SPECIFICATION_AT, triggerSpec, true ); ctx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
/** * Load the trigger specification entry * * @param ctx The context * @param triggerSpec The trigger specification * @throws NamingException If the operation failed */ public static void loadEntryTriggerSpecification( LdapContext ctx, String triggerSpec ) throws NamingException { Attributes changes = new BasicAttributes( SchemaConstants.ENTRY_TRIGGER_SPECIFICATION_AT, triggerSpec, true ); ctx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
/** * Load an prescriptive trigger specification * * @param apCtx The administrative point context * @param subentryCN The subentry CN * @param triggerSpec The trigger specification * @throws NamingException If the operation failed */ public static void loadPrescriptiveTriggerSpecification( LdapContext apCtx, String subentryCN, String triggerSpec ) throws NamingException { Attributes changes = new BasicAttributes( SchemaConstants.PRESCRIPTIVE_TRIGGER_SPECIFICATION_AT, triggerSpec, true ); apCtx.modifyAttributes( "cn=" + subentryCN, DirContext.ADD_ATTRIBUTE, changes ); }
public void modifyByDn(String dn, List<ModificationItem> modificationItems) { try { LdapContext context = connectionService.getContext(); context.modifyAttributes(dn, modificationItems.toArray(new ModificationItem[modificationItems.size()])); } catch (NamingException e) { throw new CukesRuntimeException("Cannot modify entity by dn " + dn, e); } finally { connectionService.close(); } } }
public void modify(String dn, ModificationType modType, Map<String, Object> attributes) throws NamingException { List<ModificationItem> mods = new ArrayList<>(); for (String key : attributes.keySet()) { Attribute attr = createAttribute(key, attributes.get(key)); ModificationItem item = new ModificationItem(modType.getValue(), attr); mods.add(item); } ModificationItem[] modItems = mods.toArray(new ModificationItem[mods.size()]); WithContext<Object> action = ctx -> { ctx.modifyAttributes(dn, modItems); return null; }; performWithContext(action); }
public void modifyByDn(String dn, List<ModificationItem> modificationItems) { try { LdapContext context = connectionService.getContext(); context.modifyAttributes(dn, modificationItems.toArray(new ModificationItem[modificationItems.size()])); } catch (NamingException e) { throw new CukesRuntimeException("Cannot modify entity by dn " + dn, e); } finally { connectionService.close(); } } }
public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { ADMINISTRATIVE_ROLE_ATTR } ); Attribute administrativeRole = ap.get( ADMINISTRATIVE_ROLE_ATTR ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, TRIGGER_EXECUTION_SPECIFIC_AREA_ATTR_VALUE ) ) { Attributes changes = new BasicAttributes( ADMINISTRATIVE_ROLE_ATTR, TRIGGER_EXECUTION_SPECIFIC_AREA_ATTR_VALUE, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } ); Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, TRIGGER_EXECUTION_SPECIFIC_AREA_VALUE ) ) { Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT, TRIGGER_EXECUTION_SPECIFIC_AREA_VALUE, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
/** * Defines the Administration point and administrative role for the TriggerExecution specific point * @param apCtx The administrative point context * @throws NamingException If the operation failed */ public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException { Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } ); Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT ); if ( administrativeRole == null || !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) ) { Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true ); apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes ); } }
public Object executeWithContext(DirContext dirCtx) throws NamingException { LdapContext ctx = (LdapContext) dirCtx; ctx.removeFromEnvironment("com.sun.jndi.ldap.connect.pool"); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, LdapUtils.getFullDn(dn, ctx).toString()); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, oldPassword); // TODO: reconnect doesn't appear to actually change the credentials try { ctx.reconnect(null); } catch (javax.naming.AuthenticationException e) { throw new BadCredentialsException("Authentication for password change failed."); } ctx.modifyAttributes(dn, passwordChange); return null; } });
public void removeMember(String groupDN, String memberDN) throws Exception { LdapContext ctxt = getWiredContext(); BasicAttributes attrs = new BasicAttributes(); attrs.put("member", memberDN); ctxt.modifyAttributes(groupDN, DirContext.REMOVE_ATTRIBUTE, attrs); }
public void addMember(String groupDN, String memberDN) throws Exception { LdapContext ctxt = getWiredContext(); BasicAttributes attrs = new BasicAttributes(); attrs.put("member", memberDN); ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs); }
public void addMembers(String groupDN, Iterable<String> memberDNs) throws Exception { LdapContext ctxt = getWiredContext(); Attribute attr = new BasicAttribute("member"); for (String dn : memberDNs) { attr.add(dn); } BasicAttributes attrs = new BasicAttributes(); attrs.put(attr); ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs); }