001package com.hfg.ldap.ad; 002 003import java.util.Date; 004import java.util.EnumSet; 005 006import com.hfg.ldap.LDAP_User; 007 008//------------------------------------------------------------------------------ 009/** 010 Container for Active Directory user information. 011 <div> 012 @see <a href='https://docs.microsoft.com/en-us/windows/desktop/ADSchema'>https://docs.microsoft.com/en-us/windows/desktop/ADSchema</a> 013 </div> 014 <div> 015 @author J. Alex Taylor, hairyfatguy.com 016 </div> 017 */ 018//------------------------------------------------------------------------------ 019// com.hfg XML/HTML Coding Library 020// 021// This library is free software; you can redistribute it and/or 022// modify it under the terms of the GNU Lesser General Public 023// License as published by the Free Software Foundation; either 024// version 2.1 of the License, or (at your option) any later version. 025// 026// This library is distributed in the hope that it will be useful, 027// but WITHOUT ANY WARRANTY; without even the implied warranty of 028// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 029// Lesser General Public License for more details. 030// 031// You should have received a copy of the GNU Lesser General Public 032// License along with this library; if not, write to the Free Software 033// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 034// 035// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 036// jataylor@hairyfatguy.com 037//------------------------------------------------------------------------------ 038 039public class ActiveDirectoryUser extends LDAP_User 040{ 041 private EnumSet<UserAccountControlFlag> mUAC_Flags; 042 043 //-------------------------------------------------------------------------- 044 @Override 045 public ActiveDirectoryUser setField(String inName, String inValue) 046 { 047 super.setField(inName, inValue); 048 049 if (inName.equalsIgnoreCase(ActiveDirectoryField.USER_ACCOUNT_CONTROL)) 050 { 051 setUAC_Flags(Integer.parseInt(inValue)); 052 } 053 054 return this; 055 } 056 057 058 //-------------------------------------------------------------------------- 059 public boolean isUAC_FlagSet(UserAccountControlFlag inFlag) 060 { 061 return mUAC_Flags != null && mUAC_Flags.contains(inFlag); 062 } 063 064 //-------------------------------------------------------------------------- 065 public ActiveDirectoryUser setUAC_Flag(UserAccountControlFlag inFlag) 066 { 067 if (null == mUAC_Flags) 068 { 069 mUAC_Flags = EnumSet.of(inFlag); 070 } 071 else 072 { 073 mUAC_Flags.add(inFlag); 074 } 075 076 return this; 077 } 078 079 //-------------------------------------------------------------------------- 080 public ActiveDirectoryUser clearUAC_Flag(UserAccountControlFlag inFlag) 081 { 082 if (mUAC_Flags != null) 083 { 084 mUAC_Flags.remove(inFlag); 085 } 086 087 return this; 088 } 089 090 //-------------------------------------------------------------------------- 091 public ActiveDirectoryUser setUAC_Flags(int inValue) 092 { 093 mUAC_Flags = UserAccountControlFlag.fromBitFlags(inValue); 094 095 return this; 096 } 097 098 //-------------------------------------------------------------------------- 099 public Date getLastLogon() 100 { 101 return ActiveDirectory.convertWin32EpochTimestamp(getField(ActiveDirectoryField.LAST_LOGON_TIMESTAMP)); 102 } 103 104 //-------------------------------------------------------------------------- 105 public Date getWhenCreated() 106 { 107 return ActiveDirectory.convertWin32EpochTimestamp(getField(ActiveDirectoryField.WHEN_CREATED)); 108 } 109}