This discussion is archived
0 Replies Latest reply: Aug 15, 2008 5:52 PM by 843785 RSS

Setting the logonHours attribute for a user in Active Directory

843785 Newbie
Currently Being Moderated
Hi Anyone,

I'm a brasilian guy and I need your help. How can I set the logonHours attribute on my Active Directory?

I have this code but it doesn't works good:
    public void setLogonHours(boolean[] logonHoursBits){
        
        int i;
        int j;
        int k;
        int index21 = 0;
        int index24 = 0;
        byte[] byteLogonHour = new byte[21];
        byte byte8Hours = 0;
        
        for(i=0; i <= 6; i++){
            
            for(j=1; j <= 3; j++){
                
                for(k=7; k >= 0; k--){
                
                    if (i < 6){
                        
                        if (logonHoursBits[i] == (boolean)(index24 == 0) ? true : false){
                            byte8Hours += (byte)Math.pow(2,k);
                        }
                        
                    }
                    else{
                        
                        if (logonHoursBits[0] == (boolean)(index24 == 0) ? true : false){                            
                            byte8Hours += (byte)Math.pow(2,k);
                        }

                    }
                    
                    index24++;
                
                }
                
                byteLogonHour[index21] = byte8Hours;
                index21++;
                
            }
            
            index24 = 0;

        }                                        
                                    
        try{ 
            
            String nome = "CN=Dryelle,OU=Pesquisa,DC=cifya,DC=com,DC=br";
            ctx = new InitialLdapContext(env,null); 
            ModificationItem logonHours[] = new ModificationItem[1];
            logonHours[0]= new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("logonHours",byteLogonHour)); 
            ctx.modifyAttributes(name,logonHours); 
            System.out.println("Atributo logonHours alterado com sucesso."); 
            
        }  
        catch (NamingException e) { 
           System.err.println("Problema na altera??o " + e);
        }         
                                
    }
the code set the attribute but wrong. Can anyone help-me? It's making me crazy.

Sorry about my poor english.

Tks.

Edited by: th_slopes on Aug 15, 2008 5:50 PM