/** * Get back an anonymous session */ public CoreSession getSession() { return new DefaultCoreSession( new LdapPrincipal( schemaManager ), this ); }
LdapPrincipal principal = new LdapPrincipal( schemaManager, dn, authenticationLevel );
public static CoreSession getCoreSession( String principalDn, DirectoryService service, String dn ) throws LdapException { if ( principalDn == null ) { principalDn = ""; } Dn userDn = new Dn( service.getSchemaManager(), principalDn ); LdapPrincipal principal = new LdapPrincipal( service.getSchemaManager(), userDn, AuthenticationLevel.SIMPLE ); CoreSession session = service.getSession( principal ); return session; }
/** * Creates a new instance of a DefaultCoreSession * @param principal The principal to use to process operation for this session * @param directoryService The DirectoryService to which we will send requests */ public DefaultCoreSession( LdapPrincipal principal, DirectoryService directoryService ) { this.directoryService = directoryService; authenticatedPrincipal = principal; if ( principal.getAuthenticationLevel() == AuthenticationLevel.NONE ) { anonymousPrincipal = principal; } else { anonymousPrincipal = new LdapPrincipal( directoryService.getSchemaManager() ); } // setup attribute type value objectClassAT = directoryService.getSchemaManager().getAttributeType( SchemaConstants.OBJECT_CLASS_AT ); }
public static LdapContext getContext( String principalDn, DirectoryService service, String dn ) throws Exception { if ( principalDn == null ) { principalDn = ""; } Dn userDn = new Dn( service.getSchemaManager(), principalDn ); LdapPrincipal principal = new LdapPrincipal( service.getSchemaManager(), userDn, AuthenticationLevel.SIMPLE ); if ( dn == null ) { dn = ""; } CoreSession session = service.getSession( principal ); LdapContext ctx = new ServerLdapContext( service, session, new LdapName( dn ) ); return ctx; }
/** * User has already been authenticated during SASL negotiation. Set the authentication level * to strong and return an {@link LdapPrincipal}. */ @Override public LdapPrincipal authenticate( BindOperationContext bindContext ) throws LdapAuthenticationException { // Possibly check if user account is disabled, other account checks. LdapPrincipal principal = new LdapPrincipal( getDirectoryService().getSchemaManager(), bindContext.getDn(), AuthenticationLevel.STRONG ); IoSession session = bindContext.getIoSession(); if ( session != null ) { SocketAddress clientAddress = session.getRemoteAddress(); principal.setClientAddress( clientAddress ); SocketAddress serverAddress = session.getServiceAddress(); principal.setServerAddress( serverAddress ); } return principal; } }
protected void authorize( AuthorizeCallback authorizeCB ) throws Exception { LOG.debug( "Processing conversion of principal name to Dn." ); String username = authorizeCB.getAuthorizationID(); // find the user's entry GetPrincipal getPrincipal = new GetPrincipal( new KerberosPrincipal( username ) ); PrincipalStoreEntry entry = ( PrincipalStoreEntry ) getPrincipal.execute( adminSession, new Dn( ldapSession .getLdapServer().getSearchBaseDn() ) ); String bindDn = entry.getDistinguishedName(); LOG.debug( "Converted username {} to Dn {}.", username, bindDn ); LdapPrincipal ldapPrincipal = new LdapPrincipal( adminSession.getDirectoryService().getSchemaManager(), new Dn( entry.getDistinguishedName() ), AuthenticationLevel.STRONG, Strings.EMPTY_BYTES ); ldapSession.putSaslProperty( SaslConstants.SASL_AUTHENT_USER, ldapPrincipal ); ldapSession.putSaslProperty( Context.SECURITY_PRINCIPAL, bindDn ); authorizeCB.setAuthorizedID( bindDn ); authorizeCB.setAuthorized( true ); } }
adminSession = new DefaultCoreSession( new LdapPrincipal( schemaManager, adminDn, AuthenticationLevel.STRONG ), this );
LdapPrincipal ldapPrincipal = new LdapPrincipal( schemaManager, entry.getDn(),
LdapPrincipal ldapPrincipal = new LdapPrincipal( schemaManager, entry.getDn(),
principal = new LdapPrincipal( getDirectoryService().getSchemaManager(), bindContext.getDn(), AuthenticationLevel.SIMPLE ); principal.setUserPassword( storedPasswords );
LdapPrincipal ldapPrincipal = new LdapPrincipal( getAdminSession().getDirectoryService() .getSchemaManager(), dn, AuthenticationLevel.STRONG );
principal = new LdapPrincipal( getDirectoryService().getSchemaManager(), bindDn, AuthenticationLevel.SIMPLE, bindContext.getCredentials() );