001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.tag; 020 021import lucee.commons.io.SystemUtil; 022import lucee.runtime.exp.PageException; 023import lucee.runtime.exp.TagNotSupported; 024import lucee.runtime.ext.tag.TagImpl; 025import lucee.runtime.type.Struct; 026import lucee.runtime.type.StructImpl; 027 028public class NTAuthenticate extends TagImpl { 029 030 031 private String username; 032 private String password; 033 private String domain; 034 private String result="cfntauthenticate"; 035 //private String _action="auth"; 036 private boolean listGroups; 037 private boolean throwOnError; 038 039 public void release() { 040 super.release(); 041 username = null; 042 password = null; 043 domain = null; 044 result = "cfntauthenticate"; 045 listGroups=false; 046 throwOnError=false; 047 048 //_action = "auth"; 049 050 } 051 052 053 /*public void setListGroups(boolean b) 054 { 055 if(b) 056 { 057 listGroups = true; 058 _action = "authAndGroups"; 059 } else 060 { 061 listGroups = false; 062 _action = "auth"; 063 } 064 }*/ 065 066 /** 067 * @param username the username to set 068 */ 069 public void setUsername(String username) { 070 this.username = username; 071 } 072 073 /** 074 * @param password the password to set 075 */ 076 public void setPassword(String password) { 077 this.password = password; 078 } 079 080 /** 081 * @param domain the domain to set 082 */ 083 public void setDomain(String domain) { 084 this.domain = domain; 085 } 086 087 /** 088 * @param result the result to set 089 */ 090 public void setResult(String result) { 091 this.result = result; 092 } 093 094 095 /** 096 * @param listGroups the listGroups to set 097 */ 098 public void setListgroups(boolean listGroups) { 099 this.listGroups = listGroups; 100 } 101 102 103 /** 104 * @param throwOnError the throwOnError to set 105 */ 106 public void setThrowonerror(boolean throwOnError) { 107 this.throwOnError = throwOnError; 108 } 109 110 111 public int doStartTag() throws PageException { 112 if(true)throw new TagNotSupported("ntauthenticate"); 113 String os = System.getProperty("os.name"); 114 Struct resultSt = new StructImpl(); 115 pageContext.setVariable(result, resultSt); 116 117 118 if(SystemUtil.isWindows()) { 119 /* 120 121 NTAuthentication ntauth = new NTAuthentication(domain); 122 if(username != null) 123 resultSt.set("username", username); 124 try { 125 boolean isAuth = false; 126 127 if(ntauth.IsUserInDirectory(username) && password != null && !StringUtil.isEmpty(domain)) 128 isAuth = ntauth.AuthenticateUser(username, password); 129 130 resultSt.set(AUTH, Caster.toBoolean(isAuth)); 131 resultSt.set(STATUS, isAuth?"success":"AuthenticationFailure"); 132 133 if(listGroups && isAuth) { 134 String groups = lucee.runtime.type.List.arrayToList(ntauth.GetUserGroups(username), ","); 135 resultSt.set(GROUPS, groups); 136 } 137 } 138 catch(Exception e) { 139 resultSt.set(AUTH, Boolean.FALSE); 140 if(e instanceof UserNotInDirException) 141 resultSt.set(STATUS, "UserNotInDirFailure"); 142 else 143 if(e instanceof AuthenticationFailureException) 144 resultSt.set(STATUS, "AuthenticationFailure"); 145 146 if(throwOnError) throw new JspException(e); 147 } 148 */ 149 } 150 151 return 0; 152 } 153 154}