001    package railo.runtime.tag;
002    
003    import railo.commons.io.SystemUtil;
004    import railo.runtime.exp.PageException;
005    import railo.runtime.exp.TagNotSupported;
006    import railo.runtime.ext.tag.TagImpl;
007    import railo.runtime.type.Struct;
008    import railo.runtime.type.StructImpl;
009    
010    public class NTAuthenticate extends TagImpl     {
011    
012    
013            private String username;
014        private String password;
015        private String domain;
016        private String result="cfntauthenticate";
017        //private String _action="auth";
018        private boolean listGroups;
019        private boolean throwOnError;
020        
021        public void release()       {
022            super.release();
023            username = null;
024            password = null;
025            domain = null;
026            result = "cfntauthenticate";
027            listGroups=false;
028            throwOnError=false;
029            
030            //_action = "auth";
031            
032        }
033    
034        
035        /*public void setListGroups(boolean b)
036        {
037            if(b)
038            {
039                listGroups = true;
040                _action = "authAndGroups";
041            } else
042            {
043                listGroups = false;
044                _action = "auth";
045            }
046        }*/
047        
048        /**
049             * @param username the username to set
050             */
051            public void setUsername(String username) {
052                    this.username = username;
053            }
054    
055            /**
056             * @param password the password to set
057             */
058            public void setPassword(String password) {
059                    this.password = password;
060            }
061    
062            /**
063             * @param domain the domain to set
064             */
065            public void setDomain(String domain) {
066                    this.domain = domain;
067            }
068    
069            /**
070             * @param result the result to set
071             */
072            public void setResult(String result) {
073                    this.result = result;
074            }
075    
076    
077            /**
078             * @param listGroups the listGroups to set
079             */
080            public void setListgroups(boolean listGroups) {
081                    this.listGroups = listGroups;
082            }
083    
084    
085            /**
086             * @param throwOnError the throwOnError to set
087             */
088            public void setThrowonerror(boolean throwOnError) {
089                    this.throwOnError = throwOnError;
090            }
091    
092    
093            public int doStartTag() throws PageException {
094                    if(true)throw new TagNotSupported("ntauthenticate");
095            String os = System.getProperty("os.name");
096            Struct resultSt = new StructImpl();
097            pageContext.setVariable(result, resultSt);
098            
099            
100            if(SystemUtil.isWindows())      {
101                    /*
102                    
103                NTAuthentication ntauth = new NTAuthentication(domain);
104                if(username != null)
105                    resultSt.set("username", username);
106                try {
107                    boolean isAuth = false;
108    
109                    if(ntauth.IsUserInDirectory(username) && password != null && !StringUtil.isEmpty(domain))
110                        isAuth = ntauth.AuthenticateUser(username, password);
111    
112                    resultSt.set(AUTH, Caster.toBoolean(isAuth));
113                    resultSt.set(STATUS, isAuth?"success":"AuthenticationFailure");
114                    
115                    if(listGroups && isAuth)        {
116                        String groups = railo.runtime.type.List.arrayToList(ntauth.GetUserGroups(username), ",");
117                        resultSt.set(GROUPS, groups); 
118                        }
119                }
120                catch(Exception e)  {
121                    resultSt.set(AUTH, Boolean.FALSE);
122                    if(e instanceof UserNotInDirException)
123                        resultSt.set(STATUS, "UserNotInDirFailure");
124                    else
125                    if(e instanceof AuthenticationFailureException)
126                        resultSt.set(STATUS, "AuthenticationFailure");
127                    
128                    if(throwOnError) throw new JspException(e);
129                }
130                */
131            }
132                
133            return 0;
134        }
135    
136    }