List of usage examples for javax.naming.directory BasicAttribute BasicAttribute
public BasicAttribute(String id, boolean ordered)
From source file:egovframework.com.ext.ldapumt.service.impl.OrgManageLdapDAO.java
/** * ? // w ww. j a va 2 s .com * @param vo * vo? dn? ? ?? ? ??. */ protected void updateOrg(LdapObject vo) { String dn = vo.getDn(); final ArrayList<ModificationItem> itemList = new ArrayList<ModificationItem>(); introspect(vo, new Executable() { @Override public void execute(String key, Object value) { Attribute attr = new BasicAttribute(key, value); ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr); itemList.add(item); } }); ModificationItem[] items = new ModificationItem[itemList.size()]; itemList.toArray(items); ldapTemplate.modifyAttributes(dn, items); }
From source file:org.easy.ldap.LdapDao.java
/** * @param user/*from w w w .j a v a2 s.c om*/ * @return */ public static Attributes toAttributes(LdapUser user) { Attributes attributes = new BasicAttributes(); if (user.getCommonName() != null) attributes.put(new BasicAttribute(RdnType.CN.toString(), user.getCommonName())); if (user.getGivenName() != null) attributes.put(new BasicAttribute(RdnType.GIVEN_NAME.toString(), user.getGivenName())); if (user.getSurname() != null) attributes.put(new BasicAttribute(RdnType.SN.toString(), user.getSurname())); if (user.getUserId() != null) attributes.put(new BasicAttribute(RdnType.UID.toString(), user.getUserId())); if (user.getEmail() != null) attributes.put(new BasicAttribute(RdnType.MAIL.toString(), user.getEmail())); if (user.getPassword() != null) attributes.put(new BasicAttribute(RdnType.PASSWORD.toString(), user.getPassword())); return attributes; }
From source file:org.swordess.ldap.util.AttrUtils.java
/** * Construct attributes with the same value. * //from ww w .j a v a 2s .c om * @param ids * id of each attribute * @param value * @return */ public static List<Attribute> create(String[] ids, Object value) { if (null == value) { return null; } List<Attribute> attrs = new ArrayList<Attribute>(); for (String id : ids) { attrs.add(new BasicAttribute(id, value)); } return attrs; }
From source file:org.easy.ldap.AdminServiceImpl.java
@Override public void addUser(LdapUser newUser) { Preconditions.checkNotNull(newUser); LoggingUtil.createDebugLog(log, "addUser", newUser); try {//from w w w .ja va 2s.c o m Attributes attributes = LdapDao.toAttributes(newUser); attributes.put(NamingFactory.getUserObjectClasses()); String userRdnName = environment.getProperty(PropertyNames.USERS_RDN); userRdnName = userRdnName.replace(RdnType.OU.toString() + "=", ""); Attribute ouAttr = new BasicAttribute(RdnType.OU.toString(), userRdnName); attributes.put(ouAttr); LdapName rootDn = namingFactory.createUsersDn(newUser.getTenantId()); Rdn userRdn = NamingFactory.createRdn(RdnType.UID, newUser.getUserId()); ldapDao.createSubContext(rootDn, userRdn, attributes); } catch (Exception e) { log.error(e); throw new java.lang.RuntimeException(e); } }
From source file:org.apache.ftpserver.usermanager.LdapUserManager.java
/** * Instantiate LDAP based <code>UserManager</code> implementation. *///from w w w. j a v a 2 s . co m public void configure(Configuration config) throws FtpException { try { // get admin name m_adminName = config.getString("admin", "admin"); // get ldap parameters String url = config.getString("ldap-url"); String admin = config.getString("ldap-admin-dn"); String password = config.getString("ldap-admin-password"); String auth = config.getString("ldap-authentication", "simple"); m_userBaseDn = config.getString("ldap-user-base-dn"); // create connection Properties adminEnv = new Properties(); adminEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); adminEnv.setProperty(Context.PROVIDER_URL, url); adminEnv.setProperty(Context.SECURITY_AUTHENTICATION, auth); adminEnv.setProperty(Context.SECURITY_PRINCIPAL, admin); adminEnv.setProperty(Context.SECURITY_CREDENTIALS, password); m_adminContext = new InitialDirContext(adminEnv); // create objectClass attribute m_objClassAttr = new BasicAttribute(OBJ_CLASS, false); m_objClassAttr.add("javaObject"); m_objClassAttr.add("top"); m_log.info("LDAP user manager opened."); } catch (FtpException ex) { throw ex; } catch (Exception ex) { m_log.fatal("LdapUserManager.configure()", ex); throw new FtpException("LdapUserManager.configure()", ex); } }
From source file:security.AuthenticationManager.java
public static Map<String, String> getUserAttributes(DirContext ctx, String searchBase, String userName, String principalDomain, String... attributeNames) throws NamingException { if (StringUtils.isBlank(userName)) { throw new IllegalArgumentException("Username and password can not be blank."); }//from www . j a v a 2 s .c om if (attributeNames.length == 0) { return Collections.emptyMap(); } Attributes matchAttr = new BasicAttributes(true); BasicAttribute basicAttr = new BasicAttribute("userPrincipalName", userName + principalDomain); matchAttr.put(basicAttr); NamingEnumeration<? extends SearchResult> searchResult = ctx.search(searchBase, matchAttr, attributeNames); if (ctx != null) { ctx.close(); } Map<String, String> result = new HashMap<>(); if (searchResult.hasMore()) { NamingEnumeration<? extends Attribute> attributes = searchResult.next().getAttributes().getAll(); while (attributes.hasMore()) { Attribute attr = attributes.next(); String attrId = attr.getID(); String attrValue = (String) attr.get(); result.put(attrId, attrValue); } } return result; }
From source file:org.swordess.ldap.util.ModUtils.java
public static <T> ModificationItem create(int operationMod, String id, Object value, Evaluator<T> evaluator) { if (null == value) { return null; }/* www . j a v a 2s . c o m*/ if (null == evaluator) { return new ModificationItem(operationMod, new BasicAttribute(id, value)); } else { T evaled = evaluator.eval(value); return null != evaled ? new ModificationItem(operationMod, new BasicAttribute(id, evaled)) : null; } }
From source file:org.apache.ftpserver.usermanager.LdapUserManager.java
/** * Get all user names./* w w w. j a va2s . c om*/ */ public synchronized Collection getAllUserNames() throws FtpException { try { // search ldap Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(m_objClassAttr); matchAttrs.put(new BasicAttribute(CLASS_NAME, BaseUser.class.getName())); NamingEnumeration answers = m_adminContext.search(m_userBaseDn, matchAttrs, CN_ATTRS); m_log.info("Getting all users under " + m_userBaseDn); // populate list ArrayList allUsers = new ArrayList(); while (answers.hasMore()) { SearchResult sr = (SearchResult) answers.next(); String cn = sr.getAttributes().get(CN).get().toString(); allUsers.add(cn); } Collections.sort(allUsers); return allUsers; } catch (NamingException ex) { m_log.error("LdapUserManager.getAllUserNames()", ex); throw new FtpException("LdapUserManager.getAllUserNames()", ex); } }
From source file:org.lsc.beans.LscBean.java
@Deprecated public final Attribute getAttributeById(final String id) { LOGGER.warn(/*from www . jav a 2 s.c o m*/ "The method getAttributeById() is deprecated and will be removed in a future version of LSC. Please use getDatasetById() instead."); Set<Object> values = getDatasetById(id); return (values != null ? new BasicAttribute(id, values) : null); }
From source file:org.easy.ldap.AuthServiceImpl.java
@Override public List<String> getAssignedRoles(LdapUser user) { List<String> out = null; String uniqueMemberDn = namingFactory.createUserDn(user.getTenantId(), user.getUserId()).toString(); LdapName rolesDn = namingFactory.createRolesDn(user.getTenantId()); Attributes attributes = new BasicAttributes(); attributes.put(new BasicAttribute(RdnType.UNIQUE_MEMBER.toString(), uniqueMemberDn)); out = ldapDao.findRdnValues(rolesDn, attributes, RdnType.CN); return out;//from www . ja v a 2s .c om }