/** * Creates a principal in the KDC with the specified user and password. * * @param principal principal name, do not include the domain. * @param password password. * @throws Exception thrown if the principal could not be created. */ public synchronized void createPrincipal(String principal, String password) throws Exception { String orgName= conf.getProperty(ORG_NAME); String orgDomain = conf.getProperty(ORG_DOMAIN); String baseDn = "ou=users,dc=" + orgName.toLowerCase() + ",dc=" + orgDomain.toLowerCase(); String content = "dn: uid=" + principal + "," + baseDn + "\n" + "objectClass: top\n" + "objectClass: person\n" + "objectClass: inetOrgPerson\n" + "objectClass: krb5principal\n" + "objectClass: krb5kdcentry\n" + "cn: " + principal + "\n" + "sn: " + principal + "\n" + "uid: " + principal + "\n" + "userPassword: " + password + "\n" + "krb5PrincipalName: " + principal + "@" + getRealm() + "\n" + "krb5KeyVersionNumber: 0"; for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) { ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(), ldifEntry.getEntry())); } }
coreSession.lookup( dn ); LOG.info( "Found {}, will not create.", dn ); coreSession.add( new DefaultEntry( coreSession.getDirectoryService().getSchemaManager(), entry ) ); count++; LOG.info( "Created {}.", dn ); coreSession.modify( dn, items ); LOG.info( "Modified: " + dn + " with modificationItems: " + items );
/** * Creates a new instance of UnbindOperationContext. * * @param session The session to use */ public UnbindOperationContext( CoreSession session ) { super( session, session.getEffectivePrincipal().getDn() ); setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.UNBIND ) ); }
/** * Initialize the replication Store, creating the ou=consumers,ou=system entry (only if it does not exist yet) */ private void createConsumersBranch() throws Exception { if ( !adminSession.exists( replConsumerDn ) ) { LOG.debug( "creating the entry for storing replication consumers' details" ); PROVIDER_LOG .debug( "Creating the entry for storing replication consumers' details in {}", replConsumerDn ); Entry entry = new DefaultEntry( schemaManager, replConsumerDn, SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.ORGANIZATIONAL_UNIT_OC, SchemaConstants.OU_AT, CONSUMERS ); adminSession.add( entry ); } }
public boolean hasPermission( OperationContext opContext ) throws LdapException { Dn principalName = opContext.getSession().getEffectivePrincipal().getDn(); return principalName.equals( opContext.getSession().getDirectoryService().getAdminSession() .getAuthenticatedPrincipal().getDn() ); } }
session.add( new DefaultEntry( service.getSchemaManager(), entry.getEntry() ) ); break; session.delete( dn ); break; session.move( dn, newSuperior ); session.moveAndRename( dn, newSuperior, newRdn, entry.isDeleteOldRdn() ); session.rename( dn, newRdn, entry.isDeleteOldRdn() ); session.modify( dn, entry.getModifications() ); break;
/** * Stream will be closed automatically. */ public void importLdif(InputStream is) throws Exception { try (LdifReader reader = new LdifReader(is)) { CoreSession coreSession = directoryService.getAdminSession(); // see LdifFileLoader for (LdifEntry ldifEntry : reader) { String ldif = ldifEntry.toString(); LOG.info(ldif); if (ChangeType.Add == ldifEntry.getChangeType() || /* assume "add" by default */ ChangeType.None == ldifEntry.getChangeType()) { coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), ldifEntry.getEntry())); } else if (ChangeType.Modify == ldifEntry.getChangeType()) { coreSession.modify(ldifEntry.getDn(), ldifEntry.getModifications()); } else if (ChangeType.Delete == ldifEntry.getChangeType()) { coreSession.delete(ldifEntry.getDn()); } else { throw new IllegalStateException(); } } } }
/** * This seems to be required for objectClass posixGroup. */ private ApacheDS activateNis() throws Exception { directoryService.getAdminSession().modify( new Dn("cn=nis,ou=schema"), new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "FALSE")); return this; }
private void removeMemberFromRoleOrGroup(final CoreSession session, final String dn, final String memberDN, final String attributeName) throws LdapException { final Entry entry = session.lookup(new Dn(dn), attributeName); final Attribute attribute = entry.get(attributeName); if (attribute != null) { attribute.remove(memberDN); final ModifyRequestImpl modifyRequestImpl = new ModifyRequestImpl(); modifyRequestImpl.setName(entry.getDn()); modifyRequestImpl.replace(attribute); session.modify(modifyRequestImpl); } }
private Cursor<Entry> search(final CoreSession session, final String dn, final String filter) throws LdapException { try { return session.search(new Dn(dn), SearchScope.SUBTREE, FilterParser.parse(service.getSchemaManager(), filter), AliasDerefMode.NEVER_DEREF_ALIASES); } catch (final ParseException e) { throw new LdapInvalidSearchFilterException(e.getMessage()); } }
/** * {@inheritDoc} */ @Override public Entry lookup( Dn dn, Control[] controls, String... attributes ) throws LdapException { messageId.incrementAndGet(); Entry entry = null; try { entry = session.lookup( dn, controls, attributes ); } catch ( LdapException e ) { LOG.warn( e.getMessage(), e ); } return entry; }
directoryService.getAdminSession().lookup(new Dn(EXAMPLE_DN)); } catch (LdapException lnnfe) { Entry entry = directoryService.newEntry(new Dn(EXAMPLE_DN)); entry.add("dc", "example"); entry.add("administrativeRole", "accessControlSpecificArea"); directoryService.getAdminSession().add(entry); " } \n" + "}"); directoryService.getAdminSession().add(entry); directoryService.sync();
String spUnitName = StoredProcUtils.extractStoredProcUnitName( fullSPName ); AttributeType storeProcUnitNamAT = session.getDirectoryService() .getSchemaManager().lookupAttributeTypeRegistry( "storedProcUnitName" ); ExprNode filter = new EqualityNode<String>( storeProcUnitNamAT, new Value( storeProcUnitNamAT, spUnitName ) ); Dn dn = session.getDirectoryService().getDnFactory().create( storedProcContainer ); Cursor<Entry> results = session.search( dn, SearchScope.SUBTREE, filter, AliasDerefMode.DEREF_ALWAYS );
/** * {@inheritDoc} */ @Override public Entry lookup( LookupOperationContext lookupContext ) throws LdapException { return session.getDirectoryService().getOperationManager().lookup( lookupContext ); }
String adminDn = session.getEffectivePrincipal().getName(); Cursor<Entry> cursor = session.search( partition.getSuffixDn(), SearchScope.SUBTREE, filter, AliasDerefMode.NEVER_DEREF_ALIASES, MANDATORY_ENTRY_ATOP_AT ); cursor.beforeFirst();
SchemaManager schemaManager = session.getCoreSession().getDirectoryService().getSchemaManager(); Dn newRdn = new Dn( schemaManager, req.getNewRdn().getName() ); coreSession.moveAndRename( req ); coreSession.rename( req ); coreSession.move( req );
/** * {@inheritDoc} */ @Override public LdapPrincipal getEffectivePrincipal() { if ( authorizedPrincipal != null ) { return authorizedPrincipal; } return session.getEffectivePrincipal(); }