List of usage examples for javax.naming.directory BasicAttribute BasicAttribute
public BasicAttribute(String id)
From source file:egovframework.com.ext.ldapumt.service.impl.DeptManageLdapDAO.java
/** * ./*from ww w . j a v a 2s . c om*/ * @param vo vo */ public void insertDeptManage(UcorgVO vo) throws Exception { BasicAttribute ocattr = new BasicAttribute("objectclass"); ocattr.add("top"); ocattr.add("ucorg2"); insertOrgManage(vo, ocattr); }
From source file:org.kitodo.production.ldap.LdapUser.java
private void prepareAttributes(LdapGroup ldapGroup, User user, String inUidNumber) { Attribute oc = new BasicAttribute("objectclass"); StringTokenizer tokenizer = new StringTokenizer(ldapGroup.getObjectClasses(), ","); while (tokenizer.hasMoreTokens()) { oc.add(tokenizer.nextToken());/*from w w w . j a va 2 s.com*/ } this.attributes.put(oc); this.attributes.put("uid", replaceVariables(ldapGroup.getUid(), user, inUidNumber)); this.attributes.put("cn", replaceVariables(ldapGroup.getUid(), user, inUidNumber)); this.attributes.put("displayName", replaceVariables(ldapGroup.getDisplayName(), user, inUidNumber)); this.attributes.put("description", replaceVariables(ldapGroup.getDescription(), user, inUidNumber)); this.attributes.put("gecos", replaceVariables(ldapGroup.getGecos(), user, inUidNumber)); this.attributes.put("loginShell", replaceVariables(ldapGroup.getLoginShell(), user, inUidNumber)); this.attributes.put("sn", replaceVariables(ldapGroup.getSn(), user, inUidNumber)); this.attributes.put("homeDirectory", replaceVariables(ldapGroup.getHomeDirectory(), user, inUidNumber)); this.attributes.put("sambaAcctFlags", replaceVariables(ldapGroup.getSambaAcctFlags(), user, inUidNumber)); this.attributes.put("sambaLogonScript", replaceVariables(ldapGroup.getSambaLogonScript(), user, inUidNumber)); this.attributes.put("sambaPrimaryGroupSID", replaceVariables(ldapGroup.getSambaPrimaryGroupSID(), user, inUidNumber)); this.attributes.put("sambaSID", replaceVariables(ldapGroup.getSambaSID(), user, inUidNumber)); this.attributes.put("sambaPwdMustChange", replaceVariables(ldapGroup.getSambaPwdMustChange(), user, inUidNumber)); this.attributes.put("sambaPasswordHistory", replaceVariables(ldapGroup.getSambaPasswordHistory(), user, inUidNumber)); this.attributes.put("sambaLogonHours", replaceVariables(ldapGroup.getSambaLogonHours(), user, inUidNumber)); this.attributes.put("sambaKickoffTime", replaceVariables(ldapGroup.getSambaKickoffTime(), user, inUidNumber)); this.attributes.put("sambaPwdLastSet", String.valueOf(System.currentTimeMillis() / 1000L)); this.attributes.put("uidNumber", inUidNumber); this.attributes.put("gidNumber", replaceVariables(ldapGroup.getGidNumber(), user, inUidNumber)); }
From source file:ldap.Entry.java
/** * Utility method - useful for creating a multi valued attribute for the Entry constructor * @param ID//from w w w. j a va 2s . c o m * @param vals * @return a newly created multi valued attribute */ public static BasicAttribute makeAtt(String ID, String[] vals) { BasicAttribute att = new BasicAttribute(ID); for (String val : vals) att.add(val); return att; }
From source file:org.easy.ldap.NamingFactory.java
public static Attribute getRoleObjectClasses() { Attribute objClasses = new BasicAttribute(LdapClasseNames.OBJECT_CLASS.toString()); objClasses.add(LdapClasseNames.TOP.toString()); objClasses.add(LdapClasseNames.GROUP_OF_UNIQUE_NAMES.toString()); return objClasses; }
From source file:org.nuxeo.ecm.directory.ldap.MockLdapServer.java
public void createOu(String name) { Attributes ou = new BasicAttributes("ou", name); Attribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("organizationalUnit"); ou.put(objectClass);//from www. ja v a 2 s . c o m try { serverContext.createSubcontext("ou=" + name, ou); } catch (NameAlreadyBoundException ignore) { log.warn("ou " + name + " already exists."); } catch (NamingException ne) { log.error("Failed to create ou: ", ne); } }
From source file:gov.medicaid.dao.impl.LDAPIdentityProviderDAOBean.java
/** * Asks the identity provider to provision a new user with the given profile and password. * * @param user the user to be provisioned * @param password the password for the user * @throws PortalServiceException for any errors encountered *//* w w w. j a va2 s. c o m*/ public void provisionUser(CMSUser user, String password) throws PortalServiceException { DirContext ctx = null; try { ctx = new InitialDirContext(env); List<Attribute> profileAttributes = mapAttributes(user); // set type Attribute oc = new BasicAttribute("objectClass"); oc.add("top"); oc.add("person"); oc.add("organizationalPerson"); oc.add("inetOrgPerson"); // build the entry BasicAttributes entry = new BasicAttributes(); for (Attribute attribute : profileAttributes) { entry.put(attribute); } // initial password entry.put(new BasicAttribute("userPassword", hash(password))); entry.put(oc); ctx.createSubcontext(MessageFormat.format(userDNPattern, user.getUsername()), entry); synchRoles(user.getUsername(), user.getRole()); } catch (NamingException e) { throw new PortalServiceException("Error while provisioning user.", e); } finally { closeContext(ctx); } }
From source file:org.apache.archiva.redback.rbac.ldap.LdapRbacManagerTest.java
private void createGroup(DirContext context, String groupName, String dn, List<String> users) throws Exception { Attributes attributes = new BasicAttributes(true); BasicAttribute objectClass = new BasicAttribute("objectClass"); objectClass.add("top"); objectClass.add("groupOfUniqueNames"); attributes.put(objectClass);//from w w w. ja v a 2s . c om attributes.put("cn", groupName); if (!users.isEmpty()) { BasicAttribute basicAttribute = new BasicAttribute("uniquemember"); for (String user : users) { basicAttribute.add("uid=" + user + "," + suffix);// dc=archiva,dc=apache,dc=org" ); } attributes.put(basicAttribute); } context.createSubcontext(dn, attributes); }
From source file:org.wso2.carbon.user.core.ldap.ActiveDirectoryUserStoreManager.java
/** * *///from w ww .j a v a 2 s. c o m public void doAddUser(String userName, Object credential, String[] roleList, Map<String, String> claims, String profileName, boolean requirePasswordChange) throws UserStoreException { boolean isUserBinded = false; /* getting search base directory context */ DirContext dirContext = getSearchBaseDirectoryContext(); /* getting add user basic attributes */ BasicAttributes basicAttributes = getAddUserBasicAttributes(userName); if (!isADLDSRole) { // creating a disabled user account in AD DS BasicAttribute userAccountControl = new BasicAttribute( LDAPConstants.ACTIVE_DIRECTORY_USER_ACCOUNT_CONTROL); userAccountControl.add(LDAPConstants.ACTIVE_DIRECTORY_DISABLED_NORMAL_ACCOUNT); basicAttributes.put(userAccountControl); } /* setting claims */ setUserClaims(claims, basicAttributes, userName); Name compoundName = null; try { NameParser ldapParser = dirContext.getNameParser(""); compoundName = ldapParser.parse("cn=" + escapeSpecialCharactersForDN(userName)); /* bind the user. A disabled user account with no password */ dirContext.bind(compoundName, null, basicAttributes); isUserBinded = true; /* update the user roles */ doUpdateRoleListOfUser(userName, null, roleList); /* reset the password and enable the account */ if (!isSSLConnection) { logger.warn("Unsecured connection is being used. Enabling user account operation will fail"); } ModificationItem[] mods = new ModificationItem[2]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(LDAPConstants.ACTIVE_DIRECTORY_UNICODE_PASSWORD_ATTRIBUTE, createUnicodePassword((String) credential))); if (isADLDSRole) { mods[1] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(LDAPConstants.ACTIVE_DIRECTORY_MSDS_USER_ACCOUNT_DISSABLED, "FALSE")); } else { mods[1] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute( LDAPConstants.ACTIVE_DIRECTORY_USER_ACCOUNT_CONTROL, userAccountControl)); } dirContext.modifyAttributes(compoundName, mods); } catch (NamingException e) { String errorMessage = "Error while adding the user to the Active Directory for user : " + userName; if (isUserBinded) { try { dirContext.unbind(compoundName); } catch (NamingException e1) { errorMessage = "Error while accessing the Active Directory for user : " + userName; throw new UserStoreException(errorMessage, e); } errorMessage = "Error while enabling the user account. Please check password policy at DC for user : " + userName; } throw new UserStoreException(errorMessage, e); } finally { JNDIUtil.closeContext(dirContext); } }
From source file:org.swordess.ldap.util.ModUtils.java
public static <T> ModificationItem create(int operationMod, String id, Object[] values, Evaluator<T> evaluator) {//from w ww . j a v a 2s. c o m if (ArrayUtils.isEmpty(values)) { return null; } boolean hasOneNotNullAtLeast = false; Attribute attr = new BasicAttribute(id); if (null == evaluator) { for (Object value : values) { if (null != value) { hasOneNotNullAtLeast = true; attr.add(value); } } } else { for (Object value : values) { if (null == value) { continue; } T evaled = evaluator.eval(value); if (null != evaled) { hasOneNotNullAtLeast = true; attr.add(evaled); } } } return hasOneNotNullAtLeast ? new ModificationItem(operationMod, attr) : null; }
From source file:edu.kit.scc.ldap.LdapPosixGroupDao.java
/** * Updates a POSIX group in the LDAP directory. * //from w ww. jav a 2 s .c om * @param group the {@link PosixGroup} to update * @return the {@link PosixGroup} updated */ public PosixGroup updateGroup(PosixGroup group) { BasicAttribute posixGroupBasicAttribute = new BasicAttribute("objectclass"); posixGroupBasicAttribute.add("posixGroup"); Attributes posixGroupAttributes = new BasicAttributes(); posixGroupAttributes.put(posixGroupBasicAttribute); if (group.getCommonName() != null) { posixGroupAttributes.put("cn", group.getCommonName()); } if (group.getGidNumber() != null) { posixGroupAttributes.put("gidNumber", String.valueOf(group.getGidNumber())); } if (group.getUserPassword() != null) { posixGroupAttributes.put("userPassword", group.getUserPassword()); } if (group.getDescription() != null) { posixGroupAttributes.put("description", group.getDescription()); } LdapName groupDn = LdapUtils.emptyLdapName(); try { groupDn = new LdapName(groupBase); groupDn.add("cn=" + group.getCommonName()); log.debug("Update {}", groupDn.toString()); ldapTemplate.bind(groupDn, null, posixGroupAttributes); return group; } catch (InvalidNameException ex) { log.error("ERROR {}", ex.toString()); } return null; }