@Override public CoreSession getAdminSession() { return wrapped.getAdminSession(); }
public void setDirectoryService( DirectoryService directoryService ) { this.directoryService = directoryService; this.schemaManager = directoryService.getSchemaManager(); this.session = directoryService.getAdminSession(); }
public void loadLDIF(String fileName) { File ldifFile = new File(fileName); LdifFileLoader loader = new LdifFileLoader(service.getAdminSession(), ldifFile, null, getClass().getClassLoader()); loader.execute(); } }
/** * Sets the contexts of this class taking into account the extras and overrides * properties. * * @param env an environment to use while setting up the system root. * @throws NamingException if there is a failure of any kind */ protected void setContexts(Hashtable<String, Object> env) throws Exception { Hashtable<String, Object> envFinal = new Hashtable<String, Object>(env); envFinal.put(Context.PROVIDER_URL, ""); rootDSE = directoryService.getAdminSession(); }
/** * Returns the {@link User} with email <code>email</code> or <code>null</code> * if it doesn't exist. * * @param email * the email of the desired {@link User}. * * @return the {@link User} with email <code>email</code> or <code>null</code> * if it doesn't exist. * * @throws GenericException * if the user information could not be retrieved from the LDAP * server. */ public User getUserWithEmail(final String email) throws GenericException { try { return getUserWithEmail(service.getAdminSession(), email); } catch (final LdapException e) { throw new GenericException("Error getting user with email " + email, e); } }
/** * 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 PrincipalStoreEntry findPrincipal( LdapServer ldapServer, GetPrincipal getPrincipal ) throws Exception { CoreSession adminSession = ldapServer.getDirectoryService().getAdminSession(); return ( PrincipalStoreEntry ) getPrincipal.execute( adminSession, new Dn( ldapServer.getSearchBaseDn() ) ); } }
/** * Create a new instance of the producer replication manager. * * @param directoryService The directoryService instance * @throws Exception if we add an error while creating the configuration */ public ReplConsumerManager( DirectoryService directoryService ) throws Exception { this.directoryService = directoryService; adminSession = directoryService.getAdminSession(); schemaManager = directoryService.getSchemaManager(); replConsumerDn = directoryService.getDnFactory().create( REPL_CONSUMER_DN_STR ); adsReplLastSentCsn = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ADS_REPL_LAST_SENT_CSN ); PROVIDER_LOG.debug( "Starting the replication consumer manager" ); createConsumersBranch(); }
/** * {@inheritDoc} */ public SaslServer handleMechanism( LdapSession ldapSession, BindRequest bindRequest ) throws Exception { SaslServer ss = ( SaslServer ) ldapSession.getSaslProperty( SaslConstants.SASL_SERVER ); if ( ss == null ) { CoreSession adminSession = ldapSession.getLdapServer().getDirectoryService().getAdminSession(); ss = new PlainSaslServer( ldapSession, adminSession, bindRequest ); ldapSession.putSaslProperty( SaslConstants.SASL_SERVER, ss ); } return ss; }
private void importLdif(LdifReader ldifReader) throws Exception { try { for (LdifEntry ldifEntry : ldifReader) { checkPartition(ldifEntry); System.out.print(ldifEntry.toString()); directoryService.getAdminSession() .add(new DefaultEntry(directoryService.getSchemaManager(), ldifEntry.getEntry())); } } finally { IOUtils.closeQuietly(ldifReader); } }
public boolean isInternal(String username) throws GenericException, NotFoundException { final CoreSession session = this.service.getAdminSession(); Entry entry; try { entry = session.lookup(new Dn(getUserDN(username))); return entry.containsAttribute(USER_PASSWORD); } catch (LdapNoSuchObjectException e) { throw new NotFoundException(username); }catch (LdapException e) { throw new GenericException(e); } }
private static void enabledPosixSchema( DirectoryService service ) throws LdapException { service.getSchemaManager().getLoadedSchema( "nis" ).enable(); service.getAdminSession().modify( new Dn( "cn=nis,ou=schema" ), new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "FALSE" ) ); }
private static void enabledPosixSchema( DirectoryService service ) throws LdapException { service.getSchemaManager().getLoadedSchema( "nis" ).enable(); service.getAdminSession().modify( new Dn( "cn=nis,ou=schema" ), new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "FALSE" ) ); }
private void updateTlsKey( DirectoryService ds ) throws LdapException, LdapInvalidDnException { // Update TLS key for tests. Newer Java 8 releases consider RSA keys // with less than 1024 bits as insecure and such are disabled by default, see // http://www.oracle.com/technetwork/java/javase/8-compatibility-guide-2156366.html Entry adminEntry = ds.getAdminSession().lookup( new Dn( ServerDNConstants.ADMIN_SYSTEM_DN ) ); TlsKeyGenerator.addKeyPair( adminEntry, TlsKeyGenerator.CERTIFICATE_PRINCIPAL_DN, TlsKeyGenerator.CERTIFICATE_PRINCIPAL_DN, "RSA", 1024 ); Modification mod1 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, adminEntry.get( TlsKeyGenerator.PRIVATE_KEY_AT ) ); Modification mod2 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, adminEntry.get( TlsKeyGenerator.PUBLIC_KEY_AT ) ); Modification mod3 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, adminEntry.get( TlsKeyGenerator.USER_CERTIFICATE_AT ) ); ds.getAdminSession().modify( adminEntry.getDn(), mod1, mod2, mod3 ); } }
public SaslServer handleMechanism( LdapSession ldapSession, BindRequest bindRequest ) throws Exception { SaslServer ss = ( SaslServer ) ldapSession.getSaslProperty( SaslConstants.SASL_SERVER ); if ( ss == null ) { if ( provider == null ) { initProvider(); } ss = new NtlmSaslServer( provider, bindRequest, ldapSession, ldapSession.getLdapServer() .getDirectoryService().getAdminSession() ); ldapSession.putSaslProperty( SaslConstants.SASL_SERVER, ss ); } return ss; }
private void checkPartition(LdifEntry ldifEntry) throws Exception { Dn dn = ldifEntry.getDn(); Dn parent = dn.getParent(); try { directoryService.getAdminSession().exists(parent); } catch (Exception e) { System.out.println("Creating new partition for DN=" + dn + "\n"); AvlPartition partition = new AvlPartition(directoryService.getSchemaManager()); partition.setId(dn.getName()); partition.setSuffixDn(dn); directoryService.addPartition(partition); } }
public boolean hasPermission( OperationContext opContext ) throws LdapException { Dn principalName = opContext.getSession().getEffectivePrincipal().getDn(); return principalName.equals( opContext.getSession().getDirectoryService().getAdminSession() .getAuthenticatedPrincipal().getDn() ); } }
/** * Init the replication service * @param directoryservice The directory service */ public void init( DirectoryService directoryservice ) throws Exception { this.directoryService = directoryservice; session = directoryService.getAdminSession(); schemaManager = directoryservice.getSchemaManager(); adsReplCookieAT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ADS_REPL_COOKIE ); adsDsReplicaIdAT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ADS_DS_REPLICA_ID ); Attribute cookieAttr = new DefaultAttribute( adsReplCookieAT ); cookieMod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, cookieAttr ); Attribute ridAttr = new DefaultAttribute( adsDsReplicaIdAT ); ridMod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, ridAttr ); prepareSyncSearchRequest(); }
public SaslServer handleMechanism( LdapSession ldapSession, BindRequest bindRequest ) throws Exception { SaslServer ss = ( SaslServer ) ldapSession.getSaslProperty( SaslConstants.SASL_SERVER ); if ( ss == null ) { CoreSession adminSession = ldapSession.getLdapServer().getDirectoryService().getAdminSession(); CallbackHandler callbackHandler = new DigestMd5CallbackHandler( ldapSession, adminSession, bindRequest ); ss = Sasl.createSaslServer( SupportedSaslMechanisms.DIGEST_MD5, SaslConstants.LDAP_PROTOCOL, ( String ) ldapSession.getSaslProperty( SaslConstants.SASL_HOST ), ( Map<String, String> ) ldapSession.getSaslProperty( SaslConstants.SASL_PROPS ), callbackHandler ); ldapSession.putSaslProperty( SaslConstants.SASL_SERVER, ss ); } return ss; }
public synchronized void createPrincipal(String principal, String password) throws Exception { String baseDn = getKdcServer().getSearchBaseDn(); 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" // using businessCategory as a proxy for memberoOf attribute pending: https://issues.apache.org/jira/browse/DIRSERVER-1844 + "businessCategory: " + "cn=admins,ou=system" + "\n" + "businessCategory: " + "cn=bees,ou=system" + "\n" + "krb5PrincipalName: " + principal + "@" + getRealm() + "\n" + "krb5KeyVersionNumber: 0"; for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) { service.getAdminSession().add(new DefaultEntry(service.getSchemaManager(), ldifEntry.getEntry())); } }