List of usage examples for javax.naming.directory Attribute add
boolean add(Object attrVal);
From source file:com.liferay.portal.security.ldap.BasePortalToLDAPConverter.java
public Attributes getLDAPGroupAttributes(long ldapServerId, UserGroup userGroup, User user, Properties groupMappings, Properties userMappings) throws Exception { Attributes attributes = new BasicAttributes(true); Attribute objectClass = new BasicAttribute(_OBJECT_CLASS); String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId); String[] defaultObjectClasses = PrefsPropsUtil.getStringArray(userGroup.getCompanyId(), PropsKeys.LDAP_GROUP_DEFAULT_OBJECT_CLASSES + postfix, StringPool.COMMA); for (int i = 0; i < defaultObjectClasses.length; i++) { objectClass.add(defaultObjectClasses[i]); }// w w w. j a v a 2 s . c o m attributes.put(objectClass); addAttributeMapping(groupMappings.getProperty(GroupConverterKeys.GROUP_NAME), userGroup.getName(), attributes); addAttributeMapping(groupMappings.getProperty(GroupConverterKeys.DESCRIPTION), userGroup.getDescription(), attributes); addAttributeMapping(groupMappings.getProperty(GroupConverterKeys.USER), getUserDNName(ldapServerId, user, userMappings), attributes); return attributes; }
From source file:com.liferay.portal.security.ldap.BasePortalToLDAPConverter.java
public Attributes getLDAPUserAttributes(long ldapServerId, User user, Properties userMappings) throws SystemException { Attributes attributes = new BasicAttributes(true); Attribute objectClass = new BasicAttribute(_OBJECT_CLASS); String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId); String[] defaultObjectClasses = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.LDAP_USER_DEFAULT_OBJECT_CLASSES + postfix, StringPool.COMMA); for (int i = 0; i < defaultObjectClasses.length; i++) { objectClass.add(defaultObjectClasses[i]); }// ww w . ja v a 2 s . com attributes.put(objectClass); addAttributeMapping(userMappings.getProperty(UserConverterKeys.SCREEN_NAME), user.getScreenName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.PASSWORD), user.getPasswordUnencrypted(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.EMAIL_ADDRESS), user.getEmailAddress(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.FULL_NAME), user.getFullName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.FIRST_NAME), user.getFirstName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.MIDDLE_NAME), user.getMiddleName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.LAST_NAME), user.getLastName(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.JOB_TITLE), user.getJobTitle(), attributes); addAttributeMapping(userMappings.getProperty(UserConverterKeys.PORTRAIT), getUserPortrait(user), attributes); return attributes; }
From source file:de.sub.goobi.helper.ldap.LdapUser.java
/** * configure LdapUser with Userdetails.//from www.jav a 2 s. c o m * * @param inUser * User object * @param inPassword * String * @param inUidNumber * String */ public void configure(User inUser, String inPassword, String inUidNumber) throws NamingException, NoSuchAlgorithmException { MD4 digester = new MD4(); if (!ConfigCore.getBooleanParameter("ldap_readonly", false)) { this.type = inUser.getLogin(); LdapGroup lp = inUser.getLdapGroup(); if (lp.getObjectClasses() == null) { throw new NamingException("no objectclass defined"); } /* ObjectClasses */ Attribute oc = new BasicAttribute("objectclass"); StringTokenizer tokenizer = new StringTokenizer(lp.getObjectClasses(), ","); while (tokenizer.hasMoreTokens()) { oc.add(tokenizer.nextToken()); } this.myAttrs.put(oc); this.myAttrs.put("uid", ReplaceVariables(lp.getUid(), inUser, inUidNumber)); this.myAttrs.put("cn", ReplaceVariables(lp.getUid(), inUser, inUidNumber)); this.myAttrs.put("displayName", ReplaceVariables(lp.getDisplayName(), inUser, inUidNumber)); this.myAttrs.put("description", ReplaceVariables(lp.getDescription(), inUser, inUidNumber)); this.myAttrs.put("gecos", ReplaceVariables(lp.getGecos(), inUser, inUidNumber)); this.myAttrs.put("loginShell", ReplaceVariables(lp.getLoginShell(), inUser, inUidNumber)); this.myAttrs.put("sn", ReplaceVariables(lp.getSn(), inUser, inUidNumber)); this.myAttrs.put("homeDirectory", ReplaceVariables(lp.getHomeDirectory(), inUser, inUidNumber)); this.myAttrs.put("sambaAcctFlags", ReplaceVariables(lp.getSambaAcctFlags(), inUser, inUidNumber)); this.myAttrs.put("sambaLogonScript", ReplaceVariables(lp.getSambaLogonScript(), inUser, inUidNumber)); this.myAttrs.put("sambaPrimaryGroupSID", ReplaceVariables(lp.getSambaPrimaryGroupSID(), inUser, inUidNumber)); this.myAttrs.put("sambaSID", ReplaceVariables(lp.getSambaSID(), inUser, inUidNumber)); this.myAttrs.put("sambaPwdMustChange", ReplaceVariables(lp.getSambaPwdMustChange(), inUser, inUidNumber)); this.myAttrs.put("sambaPasswordHistory", ReplaceVariables(lp.getSambaPasswordHistory(), inUser, inUidNumber)); this.myAttrs.put("sambaLogonHours", ReplaceVariables(lp.getSambaLogonHours(), inUser, inUidNumber)); this.myAttrs.put("sambaKickoffTime", ReplaceVariables(lp.getSambaKickoffTime(), inUser, inUidNumber)); this.myAttrs.put("sambaPwdLastSet", String.valueOf(System.currentTimeMillis() / 1000l)); this.myAttrs.put("uidNumber", inUidNumber); this.myAttrs.put("gidNumber", ReplaceVariables(lp.getGidNumber(), inUser, inUidNumber)); /* * Samba passwords */ /* LanMgr */ try { this.myAttrs.put("sambaLMPassword", toHexString(lmHash(inPassword))); } catch (Exception e) { logger.error(e); } /* NTLM */ try { byte hmm[] = digester.digest(inPassword.getBytes("UnicodeLittleUnmarked")); this.myAttrs.put("sambaNTPassword", toHexString(hmm)); } catch (UnsupportedEncodingException e) { logger.error(e); } /* * Encryption of password und Base64-Enconding */ MessageDigest md = MessageDigest.getInstance(ConfigCore.getParameter("ldap_encryption", "SHA")); md.update(inPassword.getBytes(StandardCharsets.UTF_8)); String digestBase64 = new String(Base64.encodeBase64(md.digest()), StandardCharsets.UTF_8); this.myAttrs.put("userPassword", "{" + ConfigCore.getParameter("ldap_encryption", "SHA") + "}" + digestBase64); } }
From source file:org.wso2.carbon.directory.server.manager.internal.LDAPServerStoreManager.java
private Attribute getChangePasswordAttribute(Attribute oldPasswordAttribute, Object oldCredential, Object newPassword) throws DirectoryServerManagerException { String passwordHashMethod = null; // when admin changes other user passwords he do not have to provide // the old password. if (oldCredential != null) { // here it is only possible to have one password, if there are more // every one should match with the given old password try {/*from w w w .j av a 2 s . c om*/ NamingEnumeration passwords = oldPasswordAttribute.getAll(); if (passwords.hasMore()) { byte[] byteArray = (byte[]) passwords.next(); String password = new String(byteArray, StandardCharsets.UTF_8); if (password.startsWith("{")) { passwordHashMethod = password.substring(password.indexOf("{") + 1, password.indexOf("}")); } if (!password.equals(getPasswordToStore((String) oldCredential, passwordHashMethod))) { throw new DirectoryServerManagerException("Old password does not match"); } } } catch (NamingException e) { log.error("Unable to retrieve old password details.", e); throw new DirectoryServerManagerException("Could not find old password details"); } } Attribute passwordAttribute = new BasicAttribute(LDAPServerManagerConstants.LDAP_PASSWORD); passwordAttribute.add(getPasswordToStore((String) newPassword, passwordHashMethod)); return passwordAttribute; }
From source file:org.apache.ambari.server.serveraction.kerberos.ADKerberosOperationHandler.java
/** * Creates a new principal in a previously configured KDC * <p/>/*from w ww . j a v a 2 s. c o m*/ * The implementation is specific to a particular type of KDC. * * @param principal a String containing the principal to add * @param password a String containing the password to use when creating the principal * @param service a boolean value indicating whether the principal is to be created as a service principal or not * @return an Integer declaring the generated key number * @throws KerberosOperationException */ @Override public Integer createPrincipal(String principal, String password, boolean service) throws KerberosOperationException { if (!isOpen()) { throw new KerberosOperationException("This operation handler has not been opened"); } if (principal == null) { throw new KerberosOperationException("principal is null"); } if (password == null) { throw new KerberosOperationException("principal password is null"); } DeconstructedPrincipal deconstructedPrincipal = createDeconstructPrincipal(principal); String realm = deconstructedPrincipal.getRealm(); if (realm == null) { realm = ""; } Map<String, Object> context = new HashMap<String, Object>(); context.put("normalized_principal", deconstructedPrincipal.getNormalizedPrincipal()); context.put("principal_name", deconstructedPrincipal.getPrincipalName()); context.put("principal_primary", deconstructedPrincipal.getPrimary()); context.put("principal_instance", deconstructedPrincipal.getInstance()); context.put("realm", realm); context.put("realm_lowercase", realm.toLowerCase()); context.put("password", password); context.put("is_service", service); context.put("container_dn", this.principalContainerDn); context.put("principal_digest", DigestUtils.sha1Hex(deconstructedPrincipal.getNormalizedPrincipal())); Map<String, Object> data = processCreateTemplate(context); Attributes attributes = new BasicAttributes(); String cn = null; if (data != null) { for (Map.Entry<String, Object> entry : data.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if ("unicodePwd".equals(key)) { if (value instanceof String) { try { attributes.put(new BasicAttribute("unicodePwd", String.format("\"%s\"", password).getBytes("UTF-16LE"))); } catch (UnsupportedEncodingException ue) { throw new KerberosOperationException("Can not encode password with UTF-16LE", ue); } } } else { Attribute attribute = new BasicAttribute(key); if (value instanceof Collection) { for (Object object : (Collection) value) { attribute.add(object); } } else { attribute.add(value); if ("cn".equals(key) && (value != null)) { cn = value.toString(); } } attributes.put(attribute); } } } if (cn == null) { cn = deconstructedPrincipal.getNormalizedPrincipal(); } try { Name name = new CompositeName().add(String.format("cn=%s,%s", cn, principalContainerDn)); ldapContext.createSubcontext(name, attributes); } catch (NamingException ne) { throw new KerberosOperationException("Can not create principal : " + principal, ne); } return 0; }
From source file:CreateJavaSchema.java
/** * Inserts object class definitions from RFC 2713 into the schema. * //ww w.j a va2 s . c o m * This method maps the LDAP schema definitions in RFC 2713 onto the * proprietary attributes required by the Active Directory schema. * * The resulting object class definitions differ from those of RFC 2713 in the * following ways: * - Abstract and auxiliary classes are now defined as structural. - The * javaObject class now inherits from javaContainer. - The * javaNamingReference, javaSerializedObject and javaMarshalledObject now * inherit from javaObject. * * The effect of these differences is that Java objects cannot be mixed-in * with other directory entries, they may only be stored as stand-alone * entries. * * The reason for these differences is due to the way auxiliary classes are * supported the Active Directory. Only the names of structural classes (not * auxiliary) may appear in the object class attribute of an entry. Therefore, * the abstract and auxiliary classes in the Java schema definition are * re-defined as structural. */ protected void insertADObjectClasses(DirContext rootCtx, DirContext schemaCtx) throws NamingException { System.out.println(" [inserting new object class definitions ...]"); String dn = schemaCtx.getNameInNamespace(); String attrID; attrID = new String("javaContainer"); Attributes attrs1 = new BasicAttributes(); attrs1.put(new BasicAttribute("objectClass", "classSchema")); attrs1.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs1.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.1")); attrs1.put(new BasicAttribute("lDAPDisplayName", attrID)); attrs1.put(new BasicAttribute("mustContain", "cn")); attrs1.put(new BasicAttribute("objectClassCategory", "1")); attrs1.put(new BasicAttribute("systemOnly", "FALSE")); attrs1.put(new BasicAttribute("subclassOf", "top")); attrs1.put(new BasicAttribute("possSuperiors", "top")); // any superior attrs1.put(new BasicAttribute("description", "Container for a Java object")); schemaCtx.createSubcontext("CN=" + attrID, attrs1); System.out.println(" [" + attrID + "]"); flushADSchemaMods(rootCtx); // because javaObject relys on javaContainer attrID = new String("javaObject"); Attributes attrs2 = new BasicAttributes(); attrs2.put(new BasicAttribute("objectClass", "classSchema")); attrs2.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs2.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.4")); attrs2.put(new BasicAttribute("lDAPDisplayName", attrID)); attrs2.put(new BasicAttribute("mustContain", "javaClassName")); Attribute joMay = new BasicAttribute("mayContain"); joMay.add("javaClassNames"); joMay.add("javaCodeBase"); joMay.add("javaDoc"); joMay.add("description"); attrs2.put(joMay); attrs2.put(new BasicAttribute("objectClassCategory", "1")); attrs2.put(new BasicAttribute("systemOnly", "FALSE")); attrs2.put(new BasicAttribute("subclassOf", "javaContainer")); attrs2.put(new BasicAttribute("description", "Java object representation")); schemaCtx.createSubcontext("CN=" + attrID, attrs2); System.out.println(" [" + attrID + "]"); flushADSchemaMods(rootCtx); // because next 3 rely on javaObject attrID = new String("javaSerializedObject"); Attributes attrs3 = new BasicAttributes(); attrs3.put(new BasicAttribute("objectClass", "classSchema")); attrs3.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs3.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.5")); attrs3.put(new BasicAttribute("lDAPDisplayName", attrID)); attrs3.put(new BasicAttribute("mustContain", "javaSerializedData")); attrs3.put(new BasicAttribute("objectClassCategory", "1")); attrs3.put(new BasicAttribute("systemOnly", "FALSE")); attrs3.put(new BasicAttribute("subclassOf", "javaObject")); attrs3.put(new BasicAttribute("description", "Java serialized object")); schemaCtx.createSubcontext("CN=" + attrID, attrs3); System.out.println(" [" + attrID + "]"); attrID = new String("javaNamingReference"); Attributes attrs4 = new BasicAttributes(); attrs4.put(new BasicAttribute("objectClass", "classSchema")); attrs4.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs4.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.7")); attrs4.put(new BasicAttribute("lDAPDisplayName", attrID)); Attribute jnrMay = new BasicAttribute("mayContain"); jnrMay.add("javaReferenceAddress"); jnrMay.add("javaFactory"); attrs4.put(jnrMay); attrs4.put(new BasicAttribute("objectClassCategory", "1")); attrs4.put(new BasicAttribute("systemOnly", "FALSE")); attrs4.put(new BasicAttribute("subclassOf", "javaObject")); attrs4.put(new BasicAttribute("description", "JNDI reference")); schemaCtx.createSubcontext("CN=" + attrID, attrs4); System.out.println(" [" + attrID + "]"); attrID = new String("javaMarshalledObject"); Attributes attrs5 = new BasicAttributes(); attrs5.put(new BasicAttribute("objectClass", "classSchema")); attrs5.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs5.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.8")); attrs5.put(new BasicAttribute("lDAPDisplayName", attrID)); attrs5.put(new BasicAttribute("mustContain", "javaSerializedData")); attrs5.put(new BasicAttribute("objectClassCategory", "1")); attrs5.put(new BasicAttribute("systemOnly", "FALSE")); attrs5.put(new BasicAttribute("subclassOf", "javaObject")); attrs5.put(new BasicAttribute("description", "Java marshalled object")); schemaCtx.createSubcontext("CN=" + attrID, attrs5); System.out.println(" [" + attrID + "]"); flushADSchemaMods(rootCtx); // finally }
From source file:CreateJavaSchema.java
/** * Inserts object class definitions from RFC 2713 into the schema. * * This method maps the LDAP schema definitions in RFC 2713 onto the * proprietary attributes required by the Active Directory schema. * * The resulting object class definitions differ from those of RFC 2713 * in the following ways:/*from w w w.j a v a 2 s. c om*/ * * - Abstract and auxiliary classes are now defined as structural. * - The javaObject class now inherits from javaContainer. * - The javaNamingReference, javaSerializedObject and * javaMarshalledObject now inherit from javaObject. * * The effect of these differences is that Java objects cannot be * mixed-in with other directory entries, they may only be stored as * stand-alone entries. * * The reason for these differences is due to the way auxiliary classes * are supported the Active Directory. Only the names of structural * classes (not auxiliary) may appear in the object class attribute of * an entry. Therefore, the abstract and auxiliary classes in the Java * schema definition are re-defined as structural. */ protected void insertADObjectClasses(DirContext rootCtx, DirContext schemaCtx) throws NamingException { System.out.println(" [inserting new object class definitions ...]"); String dn = schemaCtx.getNameInNamespace(); String attrID; attrID = new String("javaContainer"); Attributes attrs1 = new BasicAttributes(); attrs1.put(new BasicAttribute("objectClass", "classSchema")); attrs1.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs1.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.1")); attrs1.put(new BasicAttribute("lDAPDisplayName", attrID)); attrs1.put(new BasicAttribute("mustContain", "cn")); attrs1.put(new BasicAttribute("objectClassCategory", "1")); attrs1.put(new BasicAttribute("systemOnly", "FALSE")); attrs1.put(new BasicAttribute("subclassOf", "top")); attrs1.put(new BasicAttribute("possSuperiors", "top")); //any superior attrs1.put(new BasicAttribute("description", "Container for a Java object")); schemaCtx.createSubcontext("CN=" + attrID, attrs1); System.out.println(" [" + attrID + "]"); flushADSchemaMods(rootCtx); // because javaObject relys on javaContainer attrID = new String("javaObject"); Attributes attrs2 = new BasicAttributes(); attrs2.put(new BasicAttribute("objectClass", "classSchema")); attrs2.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs2.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.4")); attrs2.put(new BasicAttribute("lDAPDisplayName", attrID)); attrs2.put(new BasicAttribute("mustContain", "javaClassName")); Attribute joMay = new BasicAttribute("mayContain"); joMay.add("javaClassNames"); joMay.add("javaCodeBase"); joMay.add("javaDoc"); joMay.add("description"); attrs2.put(joMay); attrs2.put(new BasicAttribute("objectClassCategory", "1")); attrs2.put(new BasicAttribute("systemOnly", "FALSE")); attrs2.put(new BasicAttribute("subclassOf", "javaContainer")); attrs2.put(new BasicAttribute("description", "Java object representation")); schemaCtx.createSubcontext("CN=" + attrID, attrs2); System.out.println(" [" + attrID + "]"); flushADSchemaMods(rootCtx); // because next 3 rely on javaObject attrID = new String("javaSerializedObject"); Attributes attrs3 = new BasicAttributes(); attrs3.put(new BasicAttribute("objectClass", "classSchema")); attrs3.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs3.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.5")); attrs3.put(new BasicAttribute("lDAPDisplayName", attrID)); attrs3.put(new BasicAttribute("mustContain", "javaSerializedData")); attrs3.put(new BasicAttribute("objectClassCategory", "1")); attrs3.put(new BasicAttribute("systemOnly", "FALSE")); attrs3.put(new BasicAttribute("subclassOf", "javaObject")); attrs3.put(new BasicAttribute("description", "Java serialized object")); schemaCtx.createSubcontext("CN=" + attrID, attrs3); System.out.println(" [" + attrID + "]"); attrID = new String("javaNamingReference"); Attributes attrs4 = new BasicAttributes(); attrs4.put(new BasicAttribute("objectClass", "classSchema")); attrs4.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs4.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.7")); attrs4.put(new BasicAttribute("lDAPDisplayName", attrID)); Attribute jnrMay = new BasicAttribute("mayContain"); jnrMay.add("javaReferenceAddress"); jnrMay.add("javaFactory"); attrs4.put(jnrMay); attrs4.put(new BasicAttribute("objectClassCategory", "1")); attrs4.put(new BasicAttribute("systemOnly", "FALSE")); attrs4.put(new BasicAttribute("subclassOf", "javaObject")); attrs4.put(new BasicAttribute("description", "JNDI reference")); schemaCtx.createSubcontext("CN=" + attrID, attrs4); System.out.println(" [" + attrID + "]"); attrID = new String("javaMarshalledObject"); Attributes attrs5 = new BasicAttributes(); attrs5.put(new BasicAttribute("objectClass", "classSchema")); attrs5.put(new BasicAttribute("defaultHidingValue", "FALSE")); attrs5.put(new BasicAttribute("governsID", "1.3.6.1.4.1.42.2.27.4.2.8")); attrs5.put(new BasicAttribute("lDAPDisplayName", attrID)); attrs5.put(new BasicAttribute("mustContain", "javaSerializedData")); attrs5.put(new BasicAttribute("objectClassCategory", "1")); attrs5.put(new BasicAttribute("systemOnly", "FALSE")); attrs5.put(new BasicAttribute("subclassOf", "javaObject")); attrs5.put(new BasicAttribute("description", "Java marshalled object")); schemaCtx.createSubcontext("CN=" + attrID, attrs5); System.out.println(" [" + attrID + "]"); flushADSchemaMods(rootCtx); // finally }
From source file:org.openiam.spml2.spi.example.ShellConnectorImpl.java
private BasicAttributes getBasicAttributes(List<ExtensibleObject> requestAttribute, String idField) { BasicAttributes attrs = new BasicAttributes(); // add the object class Attribute oc = new BasicAttribute("objectclass"); oc.add("top"); // add the ou for this record Attribute ouSet = new BasicAttribute("ou"); String ou = getOU(requestAttribute); log.debug("GetAttributes() - ou=" + ou); if (ou != null && ou.length() > 0) { ouSet.add(ou);/*from w w w .ja va2 s . c o m*/ } // add the structural classes attrs.put(oc); attrs.put(ouSet); // add the identifier // add the attributes for (ExtensibleObject obj : requestAttribute) { List<ExtensibleAttribute> attrList = obj.getAttributes(); for (ExtensibleAttribute att : attrList) { log.debug("Attr Name=" + att.getName() + " " + att.getValue()); if (att.getName() != idField) { attrs.put(att.getName(), att.getValue()); } } } return attrs; }
From source file:CreateJavaSchema.java
protected void updateObjectClasses(DirContext ocRoot, String[] ocIDs) throws NamingException { /* Get rid of old OCs - reverse order */ for (int i = ocIDs.length - 1; i >= 0; i--) { ocRoot.destroySubcontext(ocIDs[i]); }//from www.j av a2 s. co m // javaContainer Attributes attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.1"); attrs.put("NAME", "javaContainer"); attrs.put("DESC", "Container for a Java object"); attrs.put("SUP", "top"); attrs.put("STRUCTURAL", "true"); Attribute jcMust = new BasicAttribute("MUST", "cn"); if (netscape41bug) { jcMust.add("objectClass"); } attrs.put(jcMust); ocRoot.createSubcontext("javaContainer", attrs); System.out.println("Created javaContainer object class"); // javaObject attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.4"); attrs.put("NAME", "javaObject"); attrs.put("DESC", "Java object representation"); attrs.put("SUP", "top"); attrs.put("ABSTRACT", "true"); Attribute joMust = new BasicAttribute("MUST", "javaClassName"); if (netscape41bug) { joMust.add("objectClass"); } attrs.put(joMust); Attribute optional = new BasicAttribute("MAY", "javaCodebase"); optional.add("javaClassNames"); optional.add("javaDoc"); optional.add("description"); attrs.put(optional); ocRoot.createSubcontext("javaObject", attrs); System.out.println("Created javaObject object class"); // javaSerializedObject attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.5"); attrs.put("NAME", "javaSerializedObject"); attrs.put("DESC", "Java serialized object"); attrs.put("SUP", "javaObject"); attrs.put("AUXILIARY", "true"); Attribute jsoMust = new BasicAttribute("MUST", "javaSerializedData"); if (netscape41bug) { jsoMust.add("objectClass"); } if (netscapebug) { // Netscape ignores 'SUP' so we must add explicitly attrs.put(optional); jsoMust.add("javaClassName"); } attrs.put(jsoMust); ocRoot.createSubcontext("javaSerializedObject", attrs); System.out.println("Created javaSerializedObject object class"); // javaMarshalledObject attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.8"); attrs.put("NAME", "javaMarshalledObject"); attrs.put("DESC", "Java marshalled object"); attrs.put("SUP", "javaObject"); attrs.put("AUXILIARY", "true"); if (netscapebug) { // Netscape ignores 'SUP' so we must add explicitly attrs.put(optional); } attrs.put(jsoMust); // re-use the MUST from javaSerializedObject ocRoot.createSubcontext("javaMarshalledObject", attrs); System.out.println("Created javaMarshalledObject object class"); // javaNamingReference attrs = new BasicAttributes(true); attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.7"); attrs.put("NAME", "javaNamingReference"); attrs.put("DESC", "JNDI reference"); attrs.put("SUP", "javaObject"); attrs.put("AUXILIARY", "true"); if (netscapebug) { // Netscape ignores 'SUP' so we must add explicitly attrs.put("MUST", "javaClassName"); } else { optional = new BasicAttribute("MAY"); } optional.add("javaReferenceAddress"); optional.add("javaFactory"); attrs.put(optional); ocRoot.createSubcontext("javaNamingReference", attrs); System.out.println("Created javaNamingReference object class"); }
From source file:openscim.restful.server.resources.user.ldap.LdapUserResource.java
@Override public Response updateUser(UriInfo uriInfo, String uid, User user) { // check the ldap template has been setup correctly if (ldapTemplate != null) { // create the mapper if it doesn't already exists if (mapper == null) mapper = new UserAttributesMapper(properties); // build the user dn String dn = user.getId(); if (properties .getProperty(UserAttributesMapper.CONCEAL_ACCOUNT_DNS, UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS) .equalsIgnoreCase(UserAttributesMapper.DEFAULT_CONCEAL_ACCOUNT_DNS)) { // utilise ldap formated dn dn = properties.getProperty(UserAttributesMapper.UID_ATTRIBUTE, UserAttributesMapper.DEFAULT_UID_ATTRIBUTE) + "=" + user.getId() + "," + properties.getProperty(UserAttributesMapper.ACCOUNT_BASEDN, UserAttributesMapper.DEFAULT_ACCOUNT_BASEDN); }//from w w w. ja v a 2 s .com try { // retrieve the user User lookedupUser = (User) ldapTemplate.lookup(dn, mapper); // check if the user was found if (lookedupUser == null) { logger.debug("Resource " + dn + " not found"); // user not found, return an error message return ResourceUtilities.buildErrorResponse(HttpStatus.NOT_FOUND, "Resource " + uid + " not found"); } List<ModificationItem> items = new ArrayList<ModificationItem>(); // get the uid attribute name //String uidAtttributeName = properties.getProperty(UserAttributesMapper.UID_ATTRIBUTE, UserAttributesMapper.DEFAULT_UID_ATTRIBUTE); // build a uid modification //if(user.getId() != null) //{ // Attribute uidAttribute = new BasicAttribute(uidAtttributeName, user.getId()); // ModificationItem uidItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, uidAttribute); // items.add(uidItem); //} // get the display name attribute name String displayAtttributeName = properties.getProperty(UserAttributesMapper.DISPLAYNAME_ATTRIBUTE, UserAttributesMapper.DEFAULT_DISPLAYNAME_ATTRIBUTE); // build a cn modification if (user.getDisplayName() != null) { Attribute cnAttribute = new BasicAttribute(displayAtttributeName, user.getDisplayName()); ModificationItem cnItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, cnAttribute); items.add(cnItem); } // build names modification if (user.getName() != null) { // get the surname attribute name String surnameAtttributeName = properties.getProperty(UserAttributesMapper.FAMILYNAME_ATTRIBUTE, UserAttributesMapper.DEFAULT_FAMILYNAME_ATTRIBUTE); // get the given name attribute name String givenAtttributeName = properties.getProperty(UserAttributesMapper.GIVENNAME_ATTRIBUTE, UserAttributesMapper.DEFAULT_GIVENNAME_ATTRIBUTE); if (user.getName().getFamilyName() != null) { Attribute snAttribute = new BasicAttribute(surnameAtttributeName, user.getName().getFamilyName()); ModificationItem snItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, snAttribute); items.add(snItem); } if (user.getName().getGivenName() != null) { Attribute gnAttribute = new BasicAttribute(givenAtttributeName, user.getName().getGivenName()); ModificationItem gnItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, gnAttribute); items.add(gnItem); } } // set the emails if (user.getEmails() != null) { // get the email attribute name String mailAtttributeName = properties.getProperty(UserAttributesMapper.MAIL_ATTRIBUTE, UserAttributesMapper.DEFAULT_MAIL_ATTRIBUTE); Attribute emailAttribute = new BasicAttribute(mailAtttributeName); List<PluralAttribute> emails = user.getEmails().getEmail(); for (PluralAttribute email : emails) { emailAttribute.add(email.getValue()); } ModificationItem emailItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, emailAttribute); items.add(emailItem); } // set the telephones if (user.getPhoneNumbers() != null) { // get the telephone attribute name String telephoneAtttributeName = properties.getProperty( UserAttributesMapper.TELEPHONE_ATTRIBUTE, UserAttributesMapper.DEFAULT_TELEPHONE_ATTRIBUTE); Attribute telephoneAttribute = new BasicAttribute(telephoneAtttributeName); List<PluralAttribute> telephones = user.getPhoneNumbers().getPhoneNumber(); for (PluralAttribute telephone : telephones) { telephoneAttribute.add(telephone.getValue()); } ModificationItem telephoneItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, telephoneAttribute); items.add(telephoneItem); } // build a password modification if (user.getPassword() != null) { // get the password attribute name String passwordAtttributeName = properties.getProperty(UserAttributesMapper.PASSWORD_ATTRIBUTE, UserAttributesMapper.DEFAULT_PASSWORD_ATTRIBUTE); Attribute passwordAttribute = new BasicAttribute(passwordAtttributeName, user.getPassword()); ModificationItem passwordItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, passwordAttribute); items.add(passwordItem); } // update the user password ModificationItem[] itemsArray = items.toArray(new ModificationItem[items.size()]); ldapTemplate.modifyAttributes(dn, itemsArray); // password changed successfully return Response.status(HttpStatus.NO_CONTENT.getCode()).build(); } catch (Exception nException) { logger.debug("Resource " + dn + " not found"); logger.debug(nException); // user not found, return an error message return ResourceUtilities.buildErrorResponse(HttpStatus.NOT_FOUND, "Resource " + uid + " not found"); } } else { // ldap not configured logger.error("ldap not configured"); // return a server error return ResourceUtilities.buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.NOT_IMPLEMENTED.getMessage() + ": Service Provider user ldap repository not configured"); } }