Package javax.naming.directory

Examples of javax.naming.directory.Attributes


     final Hashtable<String, String> env = new Hashtable<String, String>();
     env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); //$NON-NLS-1$ //$NON-NLS-2$
    
     try{
       final DirContext ictx = new InitialDirContext( env );
       final Attributes attrs = ictx.getAttributes( domain, new String[] { "MX" }); //$NON-NLS-1$
    
       final Attribute attr = attrs.get( "MX" ); //$NON-NLS-1$
    
       if( attr == null || attr.size() == 0){
         return null;
       }
    
View Full Code Here


    }
  }
 
  public static Identity authenticate(String username, String pwd, LDAPError ldapError) {
    LDAPLoginManager ldapManager = LDAPLoginManager.getInstance();
    Attributes attrs = ldapManager.bindUser(username, pwd, ldapError);
    if (ldapError.isEmpty() && attrs != null) {
      Identity identity = ldapManager.findIdentyByLdapAuthentication(username, ldapError);
      if (!ldapError.isEmpty()) return null;
      if (identity == null) {
        // User authenticated but not yet existing - create as new OLAT user
View Full Code Here

      enableSSL(env);
    }

    try {
      InitialDirContext userBind = new InitialDirContext(env);
      Attributes attributes = userBind.getAttributes(userDN, userAttr);
      userBind.close();
      return attributes;
    } catch (AuthenticationException e) {
      log.info("Error when trying to bind user with username::" + uid + " - invalid LDAP password");
      errors.insert("Username or passwort incorrect");
View Full Code Here

      int counter = 0;
      try {
        NamingEnumeration<SearchResult> enm = ctx.search(ldapBase, "(objectClass=" + objctClass + ")", ctls);
        while (enm.hasMore()) {
          SearchResult result = enm.next();
          Attributes attrs = result.getAttributes();
          NamingEnumeration<? extends Attribute> aEnum = attrs.getAll();
          while (aEnum.hasMore()) {
            Attribute attr = aEnum.next();
            // use lowercase username
            ldapList.add(attr.get().toString().toLowerCase());
          }
View Full Code Here

   
    boolean usersSyncedAtStartup = LDAPLoginModule.isLdapSyncOnStartup();
    //user should not exits in OLAT when not synced during startup
    assertEquals(usersSyncedAtStartup, (securityManager.findIdentityByName(uid) != null));
    // bind user
    Attributes attrs = ldapManager.bindUser(uid, userPW, errors);
    assertEquals(usersSyncedAtStartup, (securityManager.findIdentityByName(uid) != null));
    //user should be created
    ldapManager.createAndPersistUser(attrs);
    assertEquals(true, (securityManager.findIdentityByName(uid) != null));
View Full Code Here

    LDAPError errors = new LDAPError();
    String uid = "mrohrer";
    String userPW = "olat";
   
    //normal bind, should work
    Attributes attrs = ldapManager.bindUser(uid, userPW, errors);
    assertEquals("Rohrer", attrs.get("sn").get());

    //wrong password, should fail
    userPW = "haha";
    attrs = ldapManager.bindUser(uid, userPW, errors);
    assertEquals("Username or passwort incorrect", errors.get());
View Full Code Here

        fail("Expected constrant violation becaus of doupliate entry");     
      } catch (Exception e) {
        // success, this is what we expected
      }
      //changedAttrMap empty since already synchronized
      Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
      Identity identitys = securityManager.findIdentityByName(uid);
      Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
      // map is empty - no attributes to sync
      assertNull(changedAttrMap);
    } else {
      //create user but with different attributes - must fail since user already exists
      User user = UserManager.getInstance().createUser("klaus", "Meier", "klaus@meier.ch");
      Identity identity = securityManager.createAndPersistIdentityAndUser("kmeier", user, "LDAP", "kmeier", null);
      SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
      securityManager.addIdentityToSecurityGroup(identity, secGroup);
      // simulate closed session (user adding from startup job)
      DBFactory.getInstance().intermediateCommit();
     
      //changedAttrMap has 2 changes and uid as entrys (Klaus!=klaus, klaus@olat.org!=klaus@meier.ch)
      Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
      Identity identitys = securityManager.findIdentityByName(uid);
      Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
      // result must be 3: 2 changed plus the user ID which is always in the map
      assertEquals(3, changedAttrMap.keySet().size());
    }
   
    //nothing to change for this user
    uid= "mrohrer";
    Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
    Identity identitys = securityManager.findIdentityByName(uid);
    Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
    assertEquals(true, (changedAttrMap==null));
  }
View Full Code Here

    Identity identity = securityManager.findIdentityByName("kmeier");
    ldapManager.syncUser(changedMap, identity);
   
   
    changedMap.put("userID", "kmeier");
    Attributes attrs = ldapManager.bindUser("kmeier", "olat", errors);
    changedMap = ldapManager.prepareUserPropertyForSync(attrs, identity);
    assertEquals(true, (changedMap==null));
  }
View Full Code Here

    try {
      results = authContext.search(searchBase, searchFilter,  searchCtls);
      while (results.hasMore()) {
        SearchResult searchResult = (SearchResult) results.next();
        String cn = searchResult.getName();
        Attributes attributes = searchResult.getAttributes();
        Attribute attrib = attributes.get("uid");
       
        if (attrib != null) {
          String uid = (String) attrib.get();
          uidCnDictionary.put(uid, cn);
        }
View Full Code Here

      Object credential, String searchBaseDN, String filter)
      throws NamingException {
    String userDN = super.bindDNAuthentication(ctx, user, credential,
        searchBaseDN, filter);

    Attributes attrs = ctx.getAttributes(userDN, null);

    NameParser nameParser = ctx.getNameParser(userDN);

    UserPrincipal userPrincipal = (UserPrincipal) getIdentity();

    for (Map.Entry<String, String> option : ((Map<String, String>) options)
        .entrySet()) {
      if (option.getKey().startsWith(CUSTOM_PROPERTY_OPT)) {
        String attributeId = option.getValue();
        if (option.getValue().contains(SLICE_START)) {
          String attributeIdBase = attributeId.substring(0, attributeId
              .indexOf(SLICE_START));

          String[] indices = option.getValue().substring(
              option.getValue().indexOf(SLICE_START) + 1,
              option.getValue().indexOf(SLICE_END)).split(
              SLICE_START + "," + SLICE_END);
          int startIndex = Integer.parseInt(indices[0]);
          int endIndex = Integer.parseInt(indices[1]);

          if ("DN".equalsIgnoreCase(attributeIdBase)) {
            String dnSlice = extractSlice(userDN, nameParser, startIndex,
                endIndex);
            int dotIndex = attributeId.indexOf(".");
            if (dotIndex > -1) {
              Attributes nestedAttrs = ctx.getAttributes(dnSlice, null);
              Attribute attr = nestedAttrs.get(attributeId
                  .substring(dotIndex + 1));
              if (attr != null && attr.size() > 0) {
                if (attr.size() == 1) {
                  userPrincipal.putCustomProperty(option.getKey().substring(
                      CUSTOM_PROPERTY_OPT.length()), attr.get());
View Full Code Here

TOP

Related Classes of javax.naming.directory.Attributes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.