Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
fdaugan committed May 7, 2024
1 parent 4a302c5 commit 79a1875
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 220 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.ligoj.api</groupId>
<artifactId>plugin-parent</artifactId>
<version>4.1.7</version>
<version>4.1.8-SNAPSHOT</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,6 @@ public Map<String, UserOrg> findAllNoCache(final Map<String, GroupOrg> groups) {
return result;
}

@Override
public void updateMembership(final Collection<String> groups, final UserOrg user) {
// Add new groups
addUserToGroups(user, CollectionUtils.subtract(groups, user.getGroups()));

// Remove old groups
removeUserFromGroups(user, CollectionUtils.subtract(user.getGroups(), groups));
}

/**
* Update the membership of given group. All users are checked.
*/
Expand Down Expand Up @@ -582,26 +573,6 @@ private boolean matchPattern(final UserOrg userLdap, final String criteria) {
&& StringUtils.containsIgnoreCase(userLdap.getMails().getFirst(), criteria);
}

/**
* Add the user from the given groups. Cache is also updated.
*
* @param user The user to add to the given groups.
* @param groups the groups to add, normalized.
*/
protected void addUserToGroups(final UserOrg user, final Collection<String> groups) {
groups.forEach(g -> groupLdapRepository.addUser(user, g));
}

/**
* Remove the user from the given groups.Cache is also updated.
*
* @param user The user to remove from the given groups.
* @param groups the groups to remove, normalized.
*/
protected void removeUserFromGroups(final UserOrg user, final Collection<String> groups) {
groups.forEach(g -> groupLdapRepository.removeUser(user, g));
}

@Override
public void updateUser(final UserOrg user) {
final var context = template
Expand Down Expand Up @@ -711,7 +682,6 @@ public void unlock(final UserOrg user) {
}
}


@Getter
static final class CaptureAuthenticatedLdapEntryContextCallback implements AuthenticatedLdapEntryContextCallback, AuthenticatedLdapEntryContextMapper<Object> {

Expand All @@ -733,7 +703,7 @@ public UserOrg authenticate(final String name, final String password) {
log.info("Authenticating {} ...", name);
final var property = getAuthenticateProperty(name);
UserOrg user = null;
boolean authResult = false;
var authResult = false;
String reason;
try {
if (selfSearch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void writeUserData(final Writer writer, final UserOrg user) throws IOExc
writer.write(";");
writer.write(user.getLastName());
writer.write(";");
writer.write(user.getMails().isEmpty() ? "" : user.getMails().get(0));
writer.write(user.getMails().isEmpty() ? "" : user.getMails().getFirst());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@
*/
package org.apache.directory.server.core.avltree;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Comparator;

import org.apache.directory.shared.ldap.util.StringTools;

import java.io.*;
import java.util.Comparator;

/**
* Class to serialize the Array data. Only there for Java11 compliance.
*
Expand Down Expand Up @@ -68,7 +64,7 @@ public ArrayMarshaller(Comparator<E> comparator) {

@Override
public byte[] serialize(ArrayTree<E> tree) {
if ((tree == null) || (tree.size() == 0)) {
if (tree == null || tree.isEmpty()) {
return EMPTY_TREE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void findAllFewVisible() {
Assertions.assertEquals(2, result.getRecordsTotal());

// someone;group;dig rha;false;false;cn=dig rha,cn=dig as,cn=dig,ou=fonction,ou=groups,dc=sample,dc=com
DelegateOrgLightVo entity = result.getData().get(0);
DelegateOrgLightVo entity = result.getData().getFirst();
Assertions.assertEquals("DIG RHA", entity.getName());
Assertions.assertEquals(DelegateType.GROUP, entity.getType());
Assertions.assertNotNull(entity.getCreatedDate());
Expand Down Expand Up @@ -116,7 +116,7 @@ void findAllSelf() {

// mlavoine;tree;cn=Biz Agency,ou=tools;false;false;cn=Biz
// Agency,ou=tools,dc=sample,dc=com
final DelegateOrgLightVo entity = result.getData().get(0);
final DelegateOrgLightVo entity = result.getData().getFirst();
Assertions.assertEquals("cn=biz agency,ou=tools,dc=sample,dc=com", entity.getName());
Assertions.assertEquals(DelegateType.TREE, entity.getType());
Assertions.assertNotNull(entity.getCreatedDate());
Expand All @@ -134,8 +134,8 @@ void findAllSelf() {
Assertions.assertEquals("ing", result.getData().get(2).getName());

// mlavoine;tree;cn=biz agency,ou=tools,dc=sample,dc=com
Assertions.assertEquals(DelegateType.TREE, result.getData().get(0).getType());
Assertions.assertEquals("cn=biz agency,ou=tools,dc=sample,dc=com", result.getData().get(0).getName());
Assertions.assertEquals(DelegateType.TREE, result.getData().getFirst().getType());
Assertions.assertEquals("cn=biz agency,ou=tools,dc=sample,dc=com", result.getData().getFirst().getName());
}

@Test
Expand Down Expand Up @@ -166,7 +166,7 @@ void findAllReceiverGroup() {
Assertions.assertEquals(1, result.getData().size());
Assertions.assertEquals(1, result.getRecordsTotal());

final DelegateOrgLightVo vo = result.getData().get(0);
final DelegateOrgLightVo vo = result.getData().getFirst();
Assertions.assertEquals("ing", vo.getName());
Assertions.assertEquals(DelegateType.COMPANY, vo.getType());
Assertions.assertEquals("ligoj-jupiter", vo.getReceiver().getId());
Expand All @@ -182,7 +182,7 @@ void findAllReceiverCompany() {
Assertions.assertEquals(1, result.getData().size());
Assertions.assertEquals(1, result.getRecordsTotal());

final DelegateOrgLightVo entity = result.getData().get(0);
final DelegateOrgLightVo entity = result.getData().getFirst();
Assertions.assertEquals("Business Solution", entity.getName());
Assertions.assertEquals(DelegateType.GROUP, entity.getType());
Assertions.assertEquals("ing", entity.getReceiver().getId());
Expand Down Expand Up @@ -374,9 +374,7 @@ void createOnTreePartialDn() {
vo.setName("cn=myDn");
vo.setReceiver("fdaugan");
vo.setType(DelegateType.TREE);
Assertions.assertThrows(ForbiddenException.class, () -> {
resource.create(vo);
});
Assertions.assertThrows(ForbiddenException.class, () -> resource.create(vo));
}

@Test
Expand All @@ -386,20 +384,16 @@ void createInvalidDn() {
vo.setName("myDn*Partial");
vo.setReceiver("fdaugan");
vo.setType(DelegateType.TREE);
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> {
resource.create(vo);
}), "tree", "DistinguishName");
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> resource.create(vo)), "tree", "DistinguishName");
}

@Test
void createOnUnkownCompany() {
void createOnUnknownCompany() {
final DelegateOrgEditionVo vo = new DelegateOrgEditionVo();
vo.setName("any");
vo.setType(DelegateType.COMPANY);
vo.setReceiver("fdaugan");
Assertions.assertThrows(ForbiddenException.class, () -> {
resource.create(vo);
});
Assertions.assertThrows(ForbiddenException.class, () -> resource.create(vo));
}

@Test
Expand Down Expand Up @@ -429,9 +423,7 @@ void createOnSubTreeInvalidDn() {
vo.setName("myDn,dc=sample,dc=com");
vo.setReceiver("fdaugan");
vo.setType(DelegateType.TREE);
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> {
resource.create(vo);
}), "tree", "DistinguishName");
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> resource.create(vo)), "tree", "DistinguishName");
}

@Test
Expand All @@ -442,9 +434,7 @@ void updateForbiddenNotAdminDn() {
vo.setName("Biz Agency");
vo.setReceiver("mlavoine");
vo.setType(DelegateType.GROUP);
Assertions.assertThrows(ForbiddenException.class, () -> {
resource.update(vo);
});
Assertions.assertThrows(ForbiddenException.class, () -> resource.update(vo));
}

@Test
Expand All @@ -455,9 +445,7 @@ void updateInvisibleDelegateUser() {
vo.setName("Biz Agency");
vo.setReceiver("any");
vo.setType(DelegateType.GROUP);
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> {
resource.update(vo);
}), "id", "unknown-id");
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> resource.update(vo)), "id", "unknown-id");
}

@Test
Expand All @@ -470,9 +458,7 @@ void updateInvisibleDelegateCompany() {
vo.setName("socygan");
vo.setReceiver("mtuyer");
vo.setType(DelegateType.COMPANY);
Assertions.assertThrows(ForbiddenException.class, () -> {
resource.update(vo);
});
Assertions.assertThrows(ForbiddenException.class, () -> resource.update(vo));
}

@Test
Expand All @@ -483,9 +469,7 @@ void updateInvisibleReceiverUser() {
vo.setName("ing");
vo.setReceiver("fdaugan");
vo.setType(DelegateType.COMPANY);
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> {
resource.update(vo);
}), "id", "unknown-id");
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> resource.update(vo)), "id", "unknown-id");
}

@Test
Expand All @@ -497,9 +481,7 @@ void updateInvisibleReceiverCompany() {
vo.setReceiver("socygan");
vo.setReceiverType(ReceiverType.COMPANY);
vo.setType(DelegateType.COMPANY);
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> {
resource.update(vo);
}), "company", "unknown-id");
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> resource.update(vo)), "company", "unknown-id");
}

@Test
Expand All @@ -511,9 +493,7 @@ void updateInvisibleReceiverGroup() {
vo.setReceiver("biz agency");
vo.setReceiverType(ReceiverType.GROUP);
vo.setType(DelegateType.COMPANY);
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> {
resource.update(vo);
}), "group", "unknown-id");
MatcherUtil.assertThrows(Assertions.assertThrows(ValidationJsonException.class, () -> resource.update(vo)), "group", "unknown-id");
}

@Test
Expand All @@ -524,9 +504,7 @@ void updateForbiddenInvalidDelegateType() {
vo.setName("ing");
vo.setReceiver("mtuyer");
vo.setType(DelegateType.GROUP);
Assertions.assertThrows(ForbiddenException.class, () -> {
resource.update(vo);
});
Assertions.assertThrows(ForbiddenException.class, () -> resource.update(vo));
}

@Test
Expand All @@ -539,9 +517,7 @@ void updateForbiddenInvalidDelegateTree() {
vo.setName("ou=z,ou=groups,dc=sample,dc=com");
vo.setReceiver("mtuyer");
vo.setType(DelegateType.TREE);
Assertions.assertThrows(ForbiddenException.class, () -> {
resource.update(vo);
});
Assertions.assertThrows(ForbiddenException.class, () -> resource.update(vo));
}

@Test
Expand Down Expand Up @@ -581,9 +557,7 @@ void updateNotExist() {
vo.setName("ing");
vo.setReceiver("mtuyer");
vo.setType(DelegateType.COMPANY);
Assertions.assertThrows(ObjectRetrievalFailureException.class, () -> {
resource.update(vo);
});
Assertions.assertThrows(ObjectRetrievalFailureException.class, () -> resource.update(vo));
}

@Test
Expand Down Expand Up @@ -679,15 +653,11 @@ void deleteNotAdmin() {
initSpringSecurityContext("someone");
final int id = em.createQuery("SELECT id FROM DelegateOrg WHERE receiver=:user AND name=:name", Integer.class)
.setParameter("user", "someone").setParameter("name", "dig rha").getSingleResult();
Assertions.assertThrows(ForbiddenException.class, () -> {
resource.delete(id);
});
Assertions.assertThrows(ForbiddenException.class, () -> resource.delete(id));
}

@Test
void deleteUnknown() {
Assertions.assertThrows(ObjectRetrievalFailureException.class, () -> {
resource.delete(-5);
});
Assertions.assertThrows(ObjectRetrievalFailureException.class, () -> resource.delete(-5));
}
}
Loading

0 comments on commit 79a1875

Please sign in to comment.