use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class LoginEndpoint method queryLoginUserAuth.
@RequestMapping("/login/{username}")
@ResponseBody
public HashMap<String, Object> queryLoginUserAuth(@PathVariable("username") String username) {
UserInfo userInfo = userInfoService.findByUsername(username);
HashMap<String, Object> authnType = new HashMap<String, Object>();
authnType.put("authnType", userInfo.getAuthnType());
authnType.put("appLoginAuthnType", userInfo.getAppLoginAuthnType());
return authnType;
}
use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class HistoryLoginAppAdapter method postHandle.
/**
* postHandle .
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse, java.lang.Object)
*/
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
_logger.debug("postHandle");
final Apps app = (Apps) WebContext.getAttribute(WebConstants.AUTHORIZE_SIGN_ON_APP);
String sessionId = (String) WebContext.getAttribute(WebConstants.CURRENT_USER_SESSION_ID);
final UserInfo userInfo = WebContext.getUserInfo();
_logger.debug("sessionId : " + sessionId + " ,appId : " + app.getId());
HistoryLoginApps historyLoginApps = new HistoryLoginApps();
historyLoginApps.setAppId(app.getId());
historyLoginApps.setSessionId(sessionId);
historyLoginApps.setAppName(app.getName());
historyLoginApps.setUserId(userInfo.getId());
historyLoginApps.setUsername(userInfo.getUsername());
historyLoginApps.setDisplayName(userInfo.getDisplayName());
historyLoginApps.setInstId(userInfo.getInstId());
historyLoginAppsService.insert(historyLoginApps);
WebContext.removeAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
WebContext.removeAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
}
use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class WorkweixinUsersService method buildUserInfo.
public UserInfo buildUserInfo(WorkWeixinUsers user) {
UserInfo userInfo = new UserInfo();
// 账号
userInfo.setUsername(user.getUserid());
// 名字
userInfo.setNickName(user.getAlias());
// 名字
userInfo.setDisplayName(user.getName());
// 手机
userInfo.setMobile(user.getMobile());
userInfo.setEmail(user.getEmail());
userInfo.setGender(Integer.parseInt(user.getGender()));
// 工作电话
userInfo.setWorkPhoneNumber(user.getTelephone());
userInfo.setDepartmentId(user.getMain_department() + "");
// 职务
userInfo.setJobTitle(user.getPosition());
// 工作地点
userInfo.setWorkAddressFormatted(user.getAddress());
// 激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业。
if (user.getStatus() == 1) {
userInfo.setStatus(ConstsStatus.ACTIVE);
} else {
userInfo.setStatus(ConstsStatus.INACTIVE);
}
userInfo.setInstId(this.synchronizer.getInstId());
return userInfo;
}
use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class ActiveDirectoryUsersService method buildUserInfo.
public UserInfo buildUserInfo(HashMap<String, Attribute> attributeMap, String name, String nameInNamespace) {
UserInfo userInfo = new UserInfo();
userInfo.setLdapDn(nameInNamespace);
String[] namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
String namePah = "/" + rootOrganization.getName();
for (int i = namePaths.length - 1; i >= 0; i--) {
namePah = namePah + "/" + namePaths[i];
}
// namePah = namePah.substring(0, namePah.length());
String deptNamePath = namePah.substring(0, namePah.lastIndexOf("/"));
_logger.info("deptNamePath " + deptNamePath);
Organizations deptOrg = orgsNamePathMap.get(deptNamePath);
if (deptOrg == null) {
deptOrg = rootOrganization;
}
userInfo.setDepartment(deptOrg.getName());
userInfo.setDepartmentId(deptOrg.getId());
try {
userInfo.setId(userInfo.generateId());
// cn
userInfo.setFormattedName(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.CN, attributeMap));
//
// WindowsAccount
userInfo.setUsername(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.SAMACCOUNTNAME, attributeMap));
userInfo.setWindowsAccount(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.SAMACCOUNTNAME, attributeMap));
// userInfo.setWindowsAccount(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.USERPRINCIPALNAME,attributeMap));//
//
// Last Name/SurName
userInfo.setFamilyName(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.SN, attributeMap));
// First Name
userInfo.setGivenName(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.GIVENNAME, attributeMap));
// Initials
userInfo.setNickName(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.INITIALS, attributeMap));
// Initials
userInfo.setNameZhShortSpell(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.INITIALS, attributeMap));
//
userInfo.setDisplayName(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.DISPLAYNAME, attributeMap));
//
userInfo.setDescription(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.DESCRIPTION, attributeMap));
//
userInfo.setWorkPhoneNumber(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.TELEPHONENUMBER, attributeMap));
//
userInfo.setWorkOfficeName(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.PHYSICALDELIVERYOFFICENAME, attributeMap));
//
userInfo.setWorkEmail(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.MAIL, attributeMap));
//
userInfo.setWebSite(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.WWWHOMEPAGE, attributeMap));
//
//
userInfo.setWorkCountry(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.CO, attributeMap));
//
userInfo.setWorkRegion(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.ST, attributeMap));
//
userInfo.setWorkLocality(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.L, attributeMap));
//
userInfo.setWorkStreetAddress(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.STREETADDRESS, attributeMap));
//
userInfo.setWorkPostalCode(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.POSTALCODE, attributeMap));
//
userInfo.setWorkAddressFormatted(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.POSTOFFICEBOX, attributeMap));
if (LdapUtils.getAttributeStringValue(ActiveDirectoryUser.MOBILE, attributeMap).equals("")) {
userInfo.setMobile(userInfo.getId());
} else {
//
userInfo.setMobile(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.MOBILE, attributeMap));
}
//
userInfo.setHomePhoneNumber(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.HOMEPHONE, attributeMap));
//
userInfo.setWorkFax(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.FACSIMILETELEPHONENUMBER, attributeMap));
//
userInfo.setHomeAddressFormatted(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.INFO, attributeMap));
//
userInfo.setDivision(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.COMPANY, attributeMap));
// userInfo.setDepartment(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.DEPARTMENT,attributeMap)); //
// userInfo.setDepartmentId(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.DEPARTMENT,attributeMap)); //
//
userInfo.setJobTitle(LdapUtils.getAttributeStringValue(ActiveDirectoryUser.TITLE, attributeMap));
userInfo.setUserState("RESIDENT");
userInfo.setUserType("EMPLOYEE");
userInfo.setTimeZone("Asia/Shanghai");
userInfo.setStatus(ConstsStatus.ACTIVE);
userInfo.setInstId(this.synchronizer.getInstId());
HistorySynchronizer historySynchronizer = new HistorySynchronizer();
historySynchronizer.setId(historySynchronizer.generateId());
historySynchronizer.setSyncId(this.synchronizer.getId());
historySynchronizer.setSyncName(this.synchronizer.getName());
historySynchronizer.setObjectId(userInfo.getId());
historySynchronizer.setObjectName(userInfo.getUsername());
historySynchronizer.setObjectType(Organizations.class.getSimpleName());
historySynchronizer.setInstId(synchronizer.getInstId());
historySynchronizer.setResult("success");
this.historySynchronizerService.insert(historySynchronizer);
} catch (NamingException e) {
e.printStackTrace();
}
return userInfo;
}
use of org.maxkey.entity.UserInfo in project MaxKey by dromara.
the class ActiveDirectoryUsersService method sync.
public void sync() {
_logger.info("Sync ActiveDirectory Users...");
loadOrgsByInstId(this.synchronizer.getInstId(), Organizations.ROOT_ORG_ID);
try {
SearchControls constraints = new SearchControls();
constraints.setSearchScope(ldapUtils.getSearchScope());
String filter = StringUtils.isNotBlank(this.getSynchronizer().getFilters()) ? getSynchronizer().getFilters() : "(&(objectClass=User))";
NamingEnumeration<SearchResult> results = ldapUtils.getConnection().search(ldapUtils.getBaseDN(), filter, constraints);
long recordCount = 0;
while (null != results && results.hasMoreElements()) {
Object obj = results.nextElement();
if (obj instanceof SearchResult) {
SearchResult sr = (SearchResult) obj;
if (sr.getNameInNamespace().contains("CN=Users,") || sr.getNameInNamespace().contains("OU=Domain Controllers,")) {
_logger.trace("Skip 'CN=Users' or 'OU=Domain Controllers' . ");
continue;
}
_logger.debug("Sync User {} , name [{}] , NameInNamespace [{}]", (++recordCount), sr.getName(), sr.getNameInNamespace());
HashMap<String, Attribute> attributeMap = new HashMap<String, Attribute>();
NamingEnumeration<? extends Attribute> attrs = sr.getAttributes().getAll();
while (null != attrs && attrs.hasMoreElements()) {
Attribute objAttrs = attrs.nextElement();
_logger.trace("attribute {} : {}", objAttrs.getID(), ActiveDirectoryUtils.getAttrStringValue(objAttrs));
attributeMap.put(objAttrs.getID().toLowerCase(), objAttrs);
}
String originId = DigestUtils.md5B64(sr.getNameInNamespace());
UserInfo userInfo = buildUserInfo(attributeMap, sr.getName(), sr.getNameInNamespace());
if (userInfo != null) {
userInfo.setPassword(userInfo.getUsername() + UserInfo.DEFAULT_PASSWORD_SUFFIX);
userInfoService.saveOrUpdate(userInfo);
_logger.info("userInfo " + userInfo);
SynchroRelated synchroRelated = new SynchroRelated(userInfo.getId(), userInfo.getUsername(), userInfo.getDisplayName(), UserInfo.CLASS_TYPE, synchronizer.getId(), synchronizer.getName(), originId, userInfo.getDisplayName(), "", "", synchronizer.getInstId());
synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, UserInfo.CLASS_TYPE);
}
}
}
// ldapUtils.close();
} catch (NamingException e) {
_logger.error("NamingException ", e);
}
}
Aggregations