From fe571f8c4da2364266615d07bc2543059243bcd2 Mon Sep 17 00:00:00 2001 From: Patrick Hobusch Date: Wed, 1 Nov 2023 15:50:55 +0800 Subject: [PATCH] WIP --- index.adoc | 124 +++++----- pom.xml | 4 +- .../crowd/model/util/DirectoryBeanUtil.java | 229 +++++++++++++----- .../confapi/crowd/util/AttributeUtil.java | 22 ++ .../model/util/DirectoryBeanUtilTest.java | 9 - 5 files changed, 259 insertions(+), 129 deletions(-) diff --git a/index.adoc b/index.adoc index 546d8df..3eddf78 100644 --- a/index.adoc +++ b/index.adoc @@ -3940,7 +3940,7 @@ endif::internal-generation[] | permissions | -| DirectoryInternalPermissions +| DirectoryPermissions | | @@ -4002,67 +4002,6 @@ endif::internal-generation[] |=== -[#DirectoryInternalPermissions] -=== _DirectoryInternalPermissions_ - - - -[.fields-DirectoryInternalPermissions] -[cols="2,1,2,4,1"] -|=== -| Field Name| Required| Type| Description| Format - -| addGroup -| -| Boolean -| -| - -| addUser -| -| Boolean -| -| - -| modifyGroup -| -| Boolean -| -| - -| modifyUser -| -| Boolean -| -| - -| modifyGroupAttributes -| -| Boolean -| -| - -| modifyUserAttributes -| -| Boolean -| -| - -| removeGroup -| -| Boolean -| -| - -| removeUser -| -| Boolean -| -| - -|=== - - [#DirectoryLdapBean] === _DirectoryLdapBean_ @@ -4235,6 +4174,67 @@ endif::internal-generation[] |=== +[#DirectoryPermissions] +=== _DirectoryPermissions_ + + + +[.fields-DirectoryPermissions] +[cols="2,1,2,4,1"] +|=== +| Field Name| Required| Type| Description| Format + +| addGroup +| +| Boolean +| +| + +| addUser +| +| Boolean +| +| + +| modifyGroup +| +| Boolean +| +| + +| modifyUser +| +| Boolean +| +| + +| modifyGroupAttributes +| +| Boolean +| +| + +| modifyUserAttributes +| +| Boolean +| +| + +| removeGroup +| +| Boolean +| +| + +| removeUser +| +| Boolean +| +| + +|=== + + [#ErrorCollection] === _ErrorCollection_ diff --git a/pom.xml b/pom.xml index 9d7f0ec..f208ab9 100644 --- a/pom.xml +++ b/pom.xml @@ -60,13 +60,13 @@ - 5.1.3 + 5.1.5 4.4.0 8409 8.0.2 ${project.groupId}.${project.artifactId} 2.1.5 - 0.0.34 + 0.1.0-SNAPSHOT 2.0.1 8 diff --git a/src/main/java/de/aservo/confapi/crowd/model/util/DirectoryBeanUtil.java b/src/main/java/de/aservo/confapi/crowd/model/util/DirectoryBeanUtil.java index 8620af6..35b7231 100644 --- a/src/main/java/de/aservo/confapi/crowd/model/util/DirectoryBeanUtil.java +++ b/src/main/java/de/aservo/confapi/crowd/model/util/DirectoryBeanUtil.java @@ -1,14 +1,19 @@ package de.aservo.confapi.crowd.model.util; +import com.atlassian.crowd.directory.AbstractInternalDirectory; +import com.atlassian.crowd.directory.SynchronisableDirectoryProperties; +import com.atlassian.crowd.directory.ldap.LDAPPropertiesMapper; import com.atlassian.crowd.embedded.api.Directory; import com.atlassian.crowd.embedded.api.DirectoryType; import com.atlassian.crowd.embedded.api.OperationType; import com.atlassian.crowd.model.directory.ImmutableDirectory; import de.aservo.confapi.commons.model.AbstractDirectoryBean; import de.aservo.confapi.commons.model.DirectoryCrowdBean; +import de.aservo.confapi.commons.model.DirectoryDelegatingBean; import de.aservo.confapi.commons.model.DirectoryGenericBean; import de.aservo.confapi.commons.model.DirectoryInternalBean; import de.aservo.confapi.commons.model.DirectoryLdapBean; +import de.aservo.confapi.commons.model.type.DirectoryPermissions; import javax.annotation.Nonnull; import java.util.HashMap; @@ -16,7 +21,6 @@ import java.util.Map; import java.util.Set; -import static com.atlassian.crowd.directory.AbstractInternalDirectory.*; import static de.aservo.confapi.crowd.util.AttributeUtil.*; import static java.lang.Boolean.TRUE; @@ -36,6 +40,8 @@ public static AbstractDirectoryBean toDirectoryBean( if (directory.getType().equals(DirectoryType.INTERNAL)) { return toDirectoryInternalBean(directory); + } else if (directory.getType().equals(DirectoryType.DELEGATING)) { + return toDirectoryDelegatingBean(directory); } return toDirectoryGenericBean(directory); @@ -45,37 +51,56 @@ public static DirectoryInternalBean toDirectoryInternalBean( final Directory directory) { final DirectoryInternalBean directoryBean = new DirectoryInternalBean(); - directoryBean.setId(directory.getId()); - directoryBean.setName(directory.getName()); - directoryBean.setDescription(directory.getDescription()); - directoryBean.setActive(directory.isActive()); - directoryBean.setCreatedDate(directory.getCreatedDate()); - directoryBean.setUpdatedDate(directory.getUpdatedDate()); + setDirectoryBeanDetails(directoryBean, directory); final Map attributes = new HashMap<>(directory.getAttributes()); - final Set allowedOperations = new HashSet<>(directory.getAllowedOperations()); directoryBean.setCredentialPolicy(new DirectoryInternalBean.DirectoryInternalCredentialPolicy()); - directoryBean.getCredentialPolicy().setPasswordRegex(attributes.get(ATTRIBUTE_PASSWORD_REGEX)); - directoryBean.getCredentialPolicy().setPasswordComplexityMessage(attributes.get(ATTRIBUTE_PASSWORD_COMPLEXITY_MESSAGE)); - directoryBean.getCredentialPolicy().setPasswordMaxAttempts(toLong(attributes.get(ATTRIBUTE_PASSWORD_MAX_ATTEMPTS))); - directoryBean.getCredentialPolicy().setPasswordHistoryCount(toLong(attributes.get(ATTRIBUTE_PASSWORD_HISTORY_COUNT))); - directoryBean.getCredentialPolicy().setPasswordMaxChangeTime(toLong(attributes.get(ATTRIBUTE_PASSWORD_MAX_CHANGE_TIME))); - directoryBean.getCredentialPolicy().setPasswordExpiryNotificationDays(toIntegerList(attributes.get(ATTRIBUTE_PASSWORD_EXPIRATION_NOTIFICATION_PERIODS))); - directoryBean.getCredentialPolicy().setPasswordEncryptionMethod(attributes.get(ATTRIBUTE_USER_ENCRYPTION_METHOD)); + directoryBean.getCredentialPolicy().setPasswordRegex(attributes.get(AbstractInternalDirectory.ATTRIBUTE_PASSWORD_REGEX)); + directoryBean.getCredentialPolicy().setPasswordComplexityMessage(attributes.get(AbstractInternalDirectory.ATTRIBUTE_PASSWORD_COMPLEXITY_MESSAGE)); + directoryBean.getCredentialPolicy().setPasswordMaxAttempts(toLong(attributes.get(AbstractInternalDirectory.ATTRIBUTE_PASSWORD_MAX_ATTEMPTS))); + directoryBean.getCredentialPolicy().setPasswordHistoryCount(toLong(attributes.get(AbstractInternalDirectory.ATTRIBUTE_PASSWORD_HISTORY_COUNT))); + directoryBean.getCredentialPolicy().setPasswordMaxChangeTime(toLong(attributes.get(AbstractInternalDirectory.ATTRIBUTE_PASSWORD_MAX_CHANGE_TIME))); + directoryBean.getCredentialPolicy().setPasswordExpiryNotificationDays(toIntegerList(attributes.get(AbstractInternalDirectory.ATTRIBUTE_PASSWORD_EXPIRATION_NOTIFICATION_PERIODS))); + directoryBean.getCredentialPolicy().setPasswordEncryptionMethod(attributes.get(AbstractInternalDirectory.ATTRIBUTE_USER_ENCRYPTION_METHOD)); directoryBean.setAdvanced(new DirectoryInternalBean.DirectoryInternalAdvanced()); directoryBean.getAdvanced().setEnableNestedGroups(toBoolean(attributes.getOrDefault(ATTRIBUTE_USE_NESTED_GROUPS, "false"))); - directoryBean.setPermissions(new DirectoryInternalBean.DirectoryInternalPermissions()); - directoryBean.getPermissions().setAddGroup(allowedOperations.contains(OperationType.CREATE_GROUP)); - directoryBean.getPermissions().setAddUser(allowedOperations.contains(OperationType.CREATE_USER)); - directoryBean.getPermissions().setModifyGroup(allowedOperations.contains(OperationType.UPDATE_GROUP)); - directoryBean.getPermissions().setModifyUser(allowedOperations.contains(OperationType.UPDATE_USER)); - directoryBean.getPermissions().setModifyGroupAttributes(allowedOperations.contains(OperationType.UPDATE_GROUP_ATTRIBUTE)); - directoryBean.getPermissions().setModifyUserAttributes(allowedOperations.contains(OperationType.UPDATE_USER_ATTRIBUTE)); - directoryBean.getPermissions().setRemoveGroup(allowedOperations.contains(OperationType.DELETE_GROUP)); - directoryBean.getPermissions().setRemoveUser(allowedOperations.contains(OperationType.DELETE_USER)); + setDirectoryBeanPermissions(directoryBean, directory); + + return directoryBean; + } + + public static DirectoryDelegatingBean toDirectoryDelegatingBean( + final Directory directory) { + + final DirectoryDelegatingBean directoryBean = new DirectoryDelegatingBean(); + setDirectoryBeanDetails(directoryBean, directory); + + // TODO: Implement using LdapConnectorType.from....() + // DelegatedAuthenticationDirectory.ATTRIBUTE_LDAP_DIRECTORY_CLASS + + directoryBean.setConnector(new DirectoryDelegatingBean.DirectoryDelegatingConnector()); + directoryBean.getConnector().setUrl(directory.getAttributes().get(LDAPPropertiesMapper.LDAP_URL_KEY)); + // TODO: Implement real mapping based on LdapSecureMode and LDAPPropertiesMapper.LDAP_SECURE_KEY + directoryBean.getConnector().setSsl(DirectoryDelegatingBean.DirectoryDelegatingConnector.SslType.LDAPS); + directoryBean.getConnector().setUseNodeReferrals(toBoolean(directory.getAttributes().get(LDAPPropertiesMapper.LDAP_REFERRAL_KEY))); + directoryBean.getConnector().setNestedGroupsDisabled(toBoolean(directory.getAttributes().get(LDAPPropertiesMapper.LDAP_NESTED_GROUPS_DISABLED))); + // TODO: Implement methods after figuring out how + // directoryBean.getConnector().setSynchronizeUserDetails(toBoolean(directory.getAttributes().get(LDAPPropertiesMapper.))); + // directoryBean.getConnector().setSynchronizeGroupMemberships(toBoolean(directory.getAttributes().get(LDAPPropertiesMapper.))); + directoryBean.getConnector().setUsePagedResults(toBoolean(directory.getAttributes().get(LDAPPropertiesMapper.LDAP_PAGEDRESULTS_KEY))); + directoryBean.getConnector().setPagedResultsSize(toInteger(directory.getAttributes().get(LDAPPropertiesMapper.LDAP_PAGEDRESULTS_SIZE))); + directoryBean.getConnector().setReadTimeoutInMillis(toInteger(directory.getAttributes().get(SynchronisableDirectoryProperties.READ_TIMEOUT_IN_MILLISECONDS))); + directoryBean.getConnector().setSearchTimeoutInMillis(toInteger(directory.getAttributes().get(LDAPPropertiesMapper.LDAP_SEARCH_TIMELIMIT))); + directoryBean.getConnector().setConnectionTimeoutInMillis(toInteger(directory.getAttributes().get(SynchronisableDirectoryProperties.CONNECTION_TIMEOUT_IN_MILLISECONDS))); + directoryBean.getConnector().setBaseDn(directory.getAttributes().get(LDAPPropertiesMapper.LDAP_BASEDN_KEY)); + + // TODO: Implement username (+ password) + // directoryBean.getConnector().setUsername(???); + + setDirectoryBeanPermissions(directoryBean, directory); return directoryBean; } @@ -84,10 +109,7 @@ private static DirectoryGenericBean toDirectoryGenericBean( final Directory directory) { final DirectoryGenericBean directoryBean = new DirectoryGenericBean(); - directoryBean.setId(directory.getId()); - directoryBean.setName(directory.getName()); - directoryBean.setDescription(directory.getDescription()); - directoryBean.setActive(directory.isActive()); + setDirectoryBeanDetails(directoryBean, directory); return directoryBean; } @@ -134,34 +156,12 @@ public static Directory toDirectory( if (DirectoryInternalBean.class.equals(directoryBean.getClass())) { final DirectoryInternalBean directoryInternalBean = (DirectoryInternalBean) directoryBean; - - final DirectoryInternalBean.DirectoryInternalCredentialPolicy credentialPolicy = directoryInternalBean.getCredentialPolicy(); - if (credentialPolicy != null) { - setAttributeIfNotNull(attributes, ATTRIBUTE_PASSWORD_REGEX, credentialPolicy.getPasswordRegex()); - setAttributeIfNotNull(attributes, ATTRIBUTE_PASSWORD_COMPLEXITY_MESSAGE, credentialPolicy.getPasswordComplexityMessage()); - setAttributeIfNotNull(attributes, ATTRIBUTE_PASSWORD_MAX_ATTEMPTS, fromLong(credentialPolicy.getPasswordMaxAttempts())); - setAttributeIfNotNull(attributes, ATTRIBUTE_PASSWORD_HISTORY_COUNT, fromLong(credentialPolicy.getPasswordHistoryCount())); - setAttributeIfNotNull(attributes, ATTRIBUTE_PASSWORD_MAX_CHANGE_TIME, fromLong(credentialPolicy.getPasswordMaxChangeTime())); - setAttributeIfNotNull(attributes, ATTRIBUTE_PASSWORD_EXPIRATION_NOTIFICATION_PERIODS, fromIntegerList(credentialPolicy.getPasswordExpiryNotificationDays())); - setAttributeIfNotNull(attributes, ATTRIBUTE_USER_ENCRYPTION_METHOD, credentialPolicy.getPasswordEncryptionMethod()); - } - - final DirectoryInternalBean.DirectoryInternalAdvanced advanced = directoryInternalBean.getAdvanced(); - if (advanced != null) { - setAttributeIfNotNull(attributes, ATTRIBUTE_USE_NESTED_GROUPS, fromBoolean(advanced.getEnableNestedGroups())); - } - - final DirectoryInternalBean.DirectoryInternalPermissions permissions = directoryInternalBean.getPermissions(); - if (permissions != null) { - setAllowedOperationIfNotNull(allowedOperations, OperationType.CREATE_GROUP, permissions.getAddGroup()); - setAllowedOperationIfNotNull(allowedOperations, OperationType.CREATE_USER, permissions.getAddUser()); - setAllowedOperationIfNotNull(allowedOperations, OperationType.UPDATE_GROUP, permissions.getModifyGroup()); - setAllowedOperationIfNotNull(allowedOperations, OperationType.UPDATE_USER, permissions.getModifyUser()); - setAllowedOperationIfNotNull(allowedOperations, OperationType.UPDATE_GROUP_ATTRIBUTE, permissions.getModifyGroupAttributes()); - setAllowedOperationIfNotNull(allowedOperations, OperationType.UPDATE_USER_ATTRIBUTE, permissions.getModifyUserAttributes()); - setAllowedOperationIfNotNull(allowedOperations, OperationType.DELETE_GROUP, permissions.getRemoveGroup()); - setAllowedOperationIfNotNull(allowedOperations, OperationType.DELETE_USER, permissions.getRemoveUser()); - } + setDirectoryAttributes(attributes, directoryInternalBean); + setDirectoryAllowedOperations(allowedOperations, directoryInternalBean); + } else if (DirectoryDelegatingBean.class.equals(directoryBean.getClass())) { + final DirectoryDelegatingBean directoryDelegatingBean = (DirectoryDelegatingBean) directoryBean; + setDirectoryAttributes(attributes, directoryDelegatingBean); + setDirectoryAllowedOperations(allowedOperations, directoryDelegatingBean); } return directoryBuilder @@ -195,6 +195,123 @@ private static String toDirectoryImplClass( return null; } + private static void setDirectoryAttributes( + final Map attributes, + final DirectoryInternalBean directoryInternalBean) { + + final DirectoryInternalBean.DirectoryInternalCredentialPolicy credentialPolicy = directoryInternalBean.getCredentialPolicy(); + if (credentialPolicy != null) { + setAttributeIfNotNull(attributes, AbstractInternalDirectory.ATTRIBUTE_PASSWORD_REGEX, credentialPolicy.getPasswordRegex()); + setAttributeIfNotNull(attributes, AbstractInternalDirectory.ATTRIBUTE_PASSWORD_COMPLEXITY_MESSAGE, credentialPolicy.getPasswordComplexityMessage()); + setAttributeIfNotNull(attributes, AbstractInternalDirectory.ATTRIBUTE_PASSWORD_MAX_ATTEMPTS, fromLong(credentialPolicy.getPasswordMaxAttempts())); + setAttributeIfNotNull(attributes, AbstractInternalDirectory.ATTRIBUTE_PASSWORD_HISTORY_COUNT, fromLong(credentialPolicy.getPasswordHistoryCount())); + setAttributeIfNotNull(attributes, AbstractInternalDirectory.ATTRIBUTE_PASSWORD_MAX_CHANGE_TIME, fromLong(credentialPolicy.getPasswordMaxChangeTime())); + setAttributeIfNotNull(attributes, AbstractInternalDirectory.ATTRIBUTE_PASSWORD_EXPIRATION_NOTIFICATION_PERIODS, fromIntegerList(credentialPolicy.getPasswordExpiryNotificationDays())); + setAttributeIfNotNull(attributes, AbstractInternalDirectory.ATTRIBUTE_USER_ENCRYPTION_METHOD, credentialPolicy.getPasswordEncryptionMethod()); + } + + final DirectoryInternalBean.DirectoryInternalAdvanced advanced = directoryInternalBean.getAdvanced(); + if (advanced != null) { + setAttributeIfNotNull(attributes, ATTRIBUTE_USE_NESTED_GROUPS, fromBoolean(advanced.getEnableNestedGroups())); + } + } + + private static void setDirectoryAttributes( + final Map attributes, + final DirectoryDelegatingBean directoryDelegatingBean) { + + final DirectoryDelegatingBean.DirectoryDelegatingConnector connector = directoryDelegatingBean.getConnector(); + if (connector != null) { + setAttributeIfNotNull(attributes, LDAPPropertiesMapper.LDAP_URL_KEY, connector.getUrl()); + // TODO: Implement real mapper, see above + setAttributeIfNotNull(attributes, LDAPPropertiesMapper.LDAP_SECURE_KEY, "true"); + setAttributeIfNotNull(attributes, LDAPPropertiesMapper.LDAP_REFERRAL_KEY, fromBoolean(connector.getUseNodeReferrals())); + setAttributeIfNotNull(attributes, LDAPPropertiesMapper.LDAP_NESTED_GROUPS_DISABLED, fromBoolean(connector.getNestedGroupsDisabled())); + // TODO: Implement methods after figuring out how + // setSynchronizeUserDetails + // setSynchronizeGroupMemberships + setAttributeIfNotNull(attributes, LDAPPropertiesMapper.LDAP_PAGEDRESULTS_KEY, fromBoolean(connector.getUsePagedResults())); + setAttributeIfNotNull(attributes, LDAPPropertiesMapper.LDAP_PAGEDRESULTS_SIZE, fromInteger(connector.getPagedResultsSize())); + setAttributeIfNotNull(attributes, SynchronisableDirectoryProperties.READ_TIMEOUT_IN_MILLISECONDS, fromInteger(connector.getReadTimeoutInMillis())); + setAttributeIfNotNull(attributes, LDAPPropertiesMapper.LDAP_SEARCH_TIMELIMIT, fromInteger(connector.getSearchTimeoutInMillis())); + setAttributeIfNotNull(attributes, SynchronisableDirectoryProperties.CONNECTION_TIMEOUT_IN_MILLISECONDS, fromInteger(connector.getConnectionTimeoutInMillis())); + setAttributeIfNotNull(attributes, LDAPPropertiesMapper.LDAP_BASEDN_KEY, connector.getUrl()); + // TODO: + // username + // password + } + } + + private static void setDirectoryAllowedOperations( + final Set allowedOperations, + final AbstractDirectoryBean directoryBean) { + + final DirectoryPermissions permissions; + + if (DirectoryInternalBean.class.equals(directoryBean.getClass())) { + permissions = ((DirectoryInternalBean) directoryBean).getPermissions(); + } else if (DirectoryDelegatingBean.class.equals(directoryBean.getClass())) { + permissions = ((DirectoryDelegatingBean) directoryBean).getPermissions(); + } else { + permissions = null; + } + + if (permissions != null) { + setAllowedOperationIfNotNull(allowedOperations, OperationType.CREATE_GROUP, permissions.getAddGroup()); + setAllowedOperationIfNotNull(allowedOperations, OperationType.CREATE_USER, permissions.getAddUser()); + setAllowedOperationIfNotNull(allowedOperations, OperationType.UPDATE_GROUP, permissions.getModifyGroup()); + setAllowedOperationIfNotNull(allowedOperations, OperationType.UPDATE_USER, permissions.getModifyUser()); + setAllowedOperationIfNotNull(allowedOperations, OperationType.UPDATE_GROUP_ATTRIBUTE, permissions.getModifyGroupAttributes()); + setAllowedOperationIfNotNull(allowedOperations, OperationType.UPDATE_USER_ATTRIBUTE, permissions.getModifyUserAttributes()); + setAllowedOperationIfNotNull(allowedOperations, OperationType.DELETE_GROUP, permissions.getRemoveGroup()); + setAllowedOperationIfNotNull(allowedOperations, OperationType.DELETE_USER, permissions.getRemoveUser()); + } + } + + private static void setDirectoryBeanDetails( + final AbstractDirectoryBean directoryBean, + final Directory directory) { + + directoryBean.setId(directory.getId()); + directoryBean.setName(directory.getName()); + directoryBean.setDescription(directory.getDescription()); + directoryBean.setActive(directory.isActive()); + directoryBean.setCreatedDate(directory.getCreatedDate()); + directoryBean.setUpdatedDate(directory.getUpdatedDate()); + } + + private static void setDirectoryBeanPermissions( + final AbstractDirectoryBean directoryBean, + final Directory directory) { + + final DirectoryPermissions permissions = toDirectoryPermissions(directory.getAllowedOperations()); + + if (DirectoryInternalBean.class.equals(directoryBean.getClass())) { + DirectoryInternalBean directoryInternalBean = (DirectoryInternalBean) directoryBean; + directoryInternalBean.setPermissions(permissions); + } else if (DirectoryDelegatingBean.class.equals(directoryBean.getClass())) { + DirectoryDelegatingBean directoryDelegatingBean = (DirectoryDelegatingBean) directoryBean; + directoryDelegatingBean.setPermissions(permissions); + } + } + + private static DirectoryPermissions toDirectoryPermissions( + final Set allowedOperations) { + + final DirectoryPermissions permissions = new DirectoryPermissions(); + + permissions.setAddGroup(allowedOperations.contains(OperationType.CREATE_GROUP)); + permissions.setAddUser(allowedOperations.contains(OperationType.CREATE_USER)); + permissions.setModifyGroup(allowedOperations.contains(OperationType.UPDATE_GROUP)); + permissions.setModifyUser(allowedOperations.contains(OperationType.UPDATE_USER)); + permissions.setModifyGroupAttributes(allowedOperations.contains(OperationType.UPDATE_GROUP_ATTRIBUTE)); + permissions.setModifyUserAttributes(allowedOperations.contains(OperationType.UPDATE_USER_ATTRIBUTE)); + permissions.setRemoveGroup(allowedOperations.contains(OperationType.DELETE_GROUP)); + permissions.setRemoveUser(allowedOperations.contains(OperationType.DELETE_USER)); + + return permissions; + } + private static void setAttributeIfNotNull( final Map attributes, final String attribute, diff --git a/src/main/java/de/aservo/confapi/crowd/util/AttributeUtil.java b/src/main/java/de/aservo/confapi/crowd/util/AttributeUtil.java index cc0def9..dbe733c 100644 --- a/src/main/java/de/aservo/confapi/crowd/util/AttributeUtil.java +++ b/src/main/java/de/aservo/confapi/crowd/util/AttributeUtil.java @@ -9,6 +9,17 @@ public class AttributeUtil { public static final String LIST_SEPARATOR = ","; + @Nullable + public static String fromInteger( + @Nullable final Integer value) { + + if (value == null) { + return null; + } + + return String.valueOf(value); + } + @Nullable public static String fromLong( @Nullable final Long value) { @@ -44,6 +55,17 @@ public static String fromIntegerList( .collect(Collectors.joining(LIST_SEPARATOR)); } + @Nullable + public static Integer toInteger( + @Nullable final String value) { + + if (value == null) { + return null; + } + + return Integer.valueOf(value); + } + @Nullable public static Long toLong( @Nullable final String value) { diff --git a/src/test/java/de/aservo/confapi/crowd/model/util/DirectoryBeanUtilTest.java b/src/test/java/de/aservo/confapi/crowd/model/util/DirectoryBeanUtilTest.java index 92452de..4104d39 100644 --- a/src/test/java/de/aservo/confapi/crowd/model/util/DirectoryBeanUtilTest.java +++ b/src/test/java/de/aservo/confapi/crowd/model/util/DirectoryBeanUtilTest.java @@ -60,15 +60,6 @@ public void testToDirectoryGenericBean() { @Test public void testToDirectory() { final DirectoryInternalBean directoryBean = DirectoryInternalBean.EXAMPLE_1; - directoryBean.setPermissions(new DirectoryInternalBean.DirectoryInternalPermissions()); - directoryBean.getPermissions().setAddGroup(true); - directoryBean.getPermissions().setAddUser(true); - directoryBean.getPermissions().setModifyGroup(true); - directoryBean.getPermissions().setModifyUser(true); - directoryBean.getPermissions().setModifyGroupAttributes(true); - directoryBean.getPermissions().setModifyUserAttributes(true); - directoryBean.getPermissions().setRemoveGroup(true); - directoryBean.getPermissions().setRemoveUser(true); final Directory directory = DirectoryBeanUtil.toDirectory(directoryBean); assertNotNull(directory);