Skip to content

Commit

Permalink
Merge pull request #9 from Pardus-LiderAhenk/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
tncyclk authored Mar 22, 2023
2 parents 59df266 + b7daf73 commit 2b49baf
Show file tree
Hide file tree
Showing 20 changed files with 2,069 additions and 594 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>
<groupId>tr.com.lider</groupId>
<artifactId>Lider3</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
<name>Lider V3 Beta</name>
<packaging>war</packaging>
<description>Lider(V3) Merkezi Yonetim Sistemi</description>
Expand Down
1,035 changes: 504 additions & 531 deletions src/main/java/tr/org/lider/controllers/AdController.java

Large diffs are not rendered by default.

113 changes: 110 additions & 3 deletions src/main/java/tr/org/lider/controllers/ComputerGroupsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public ResponseEntity<?> createNewAgentGroup(@RequestBody Map<String, String> pa
List<LdapEntry> directories = new ArrayList<>();

for (LdapEntry ldapEntry : entries) {
if(ldapEntry.getType().equals(DNType.AHENK)) {
if(ldapEntry.getType().equals(DNType.AHENK) || ldapEntry.getType().equals(DNType.GROUP)) {
agents.add(ldapEntry);
}
}
Expand Down Expand Up @@ -372,9 +372,33 @@ public ResponseEntity<?> addAgentsToExistingGroup(@RequestBody Map<String, Strin
}
List<LdapEntry> agents = new ArrayList<>();
List<LdapEntry> directories = new ArrayList<>();
List <String> memberDn = new ArrayList<>();
List <String> memberOfDn = new ArrayList<>();
for (LdapEntry ldapMember : entries){

if(ldapMember.getType().equals(DNType.GROUP)){
memberDn.addAll(Arrays.asList(ldapMember.getAttributesMultiValues().get("member")));
memberOfDn.addAll(Arrays.asList(ldapMember.getAttributesMultiValues().get("member")));
}
}
System.out.println(memberDn);

for (LdapEntry ldapEntry : entries) {
if(ldapEntry.getType().equals(DNType.AHENK)) {
if(ldapEntry.getType().equals(DNType.AHENK) || ldapEntry.getType().equals(DNType.GROUP)) {
if(ldapEntry.getType().equals(DNType.GROUP)) {
if (ldapEntry.getAttributesMultiValues().get("member").equals(null)) {
continue;
}
else {
System.out.println(ldapEntry.getAttributesMultiValues().get("member"));
// for (LdapEntry groupLdapEntry : ldapEntry.getAttributesMultiValues().get("member")) {
// if (groupLdapEntry.getDistinguishedName() == ldapEntry.getDistinguishedName()) {
// System.err.println("AYNI GRUP");
// break;
// }
// }
}
}
agents.add(ldapEntry);
}
}
Expand Down Expand Up @@ -604,7 +628,7 @@ public ResponseEntity<LdapEntry> renameEntry(@RequestParam(value="oldDN", requir
public List<LdapEntry> getAhenksUnderOUs(List<LdapEntry> directories, List<LdapEntry> ahenks) {
for (LdapEntry ldapEntry : directories) {
try {
List<LdapEntry> retList = ldapService.findSubEntries(ldapEntry.getDistinguishedName(), "(objectclass=pardusDevice)", new String[] { "*" }, SearchScope.SUBTREE);
List<LdapEntry> retList = ldapService.findSubEntries(ldapEntry.getDistinguishedName(), "(|(objectclass=pardusDevice)(objectclass=groupOfNames))" , new String[] { "*" }, SearchScope.SUBTREE);
for (LdapEntry ldapEntry2 : retList) {
boolean isExist=false;
for (LdapEntry ldapEntryAhenk : ahenks) {
Expand Down Expand Up @@ -797,4 +821,87 @@ public ResponseEntity<LdapEntry> addClientToExistGroup(
.status(HttpStatus.OK)
.body(entry);
}


// //add agents to existing group from agent info page
// @Operation(summary = "Add agent to existing group", description = "", tags = { "computer-groups" })
// @ApiResponses(value = {
// @ApiResponse(responseCode = "200", description = "Added agent to existing group"),
// @ApiResponse(responseCode = "417", description = "Could not add agent to existing group. Unexpected error occured",
// content = @Content(schema = @Schema(implementation = String.class))) })
// @PostMapping(value = "/group/existing", produces = MediaType.APPLICATION_JSON_VALUE)
// public ResponseEntity<?> addAgentsToExistingGroupp(@RequestBody Map<String, String> params) {
// LdapEntry entry;
// ObjectMapper mapper = new ObjectMapper();
// List<LdapEntry> entries = new ArrayList<>();
// try {
// entries = Arrays.asList(mapper.readValue(params.get("checkedEntries"), LdapEntry[].class));
// } catch (JsonProcessingException e) {
// logger.error("Error occured while mapping checked entry list to object");
// }
// List<LdapEntry> agents = new ArrayList<>();
// List<LdapEntry> directories = new ArrayList<>();
//
// for (LdapEntry ldapEntry : entries) {
// if(ldapEntry.getType().equals(DNType.AHENK)) {
// agents.add(ldapEntry);
// }
// }
//
// for (LdapEntry ldapEntry : entries) {
// Boolean hasParentChecked = false;
// for (LdapEntry entryTemp : entries) {
// if(ldapEntry.getType().equals(DNType.ORGANIZATIONAL_UNIT) && entryTemp.getType().equals(DNType.ORGANIZATIONAL_UNIT)) {
// if(!ldapEntry.getDistinguishedName().equals(entryTemp.getDistinguishedName())
// && ldapEntry.getDistinguishedName().contains(entryTemp.getDistinguishedName())) {
// hasParentChecked = true;
// break;
// }
// }
// }
// if(ldapEntry.getType().equals(DNType.ORGANIZATIONAL_UNIT) && !hasParentChecked) {
// directories.add(ldapEntry);
// }
// }
//
// List<LdapEntry> allAgents = getAhenksUnderOUs(directories, agents);
// if(allAgents.size() == 0) {
// return new ResponseEntity<String>("Seçili klasörlerde istemci bulunamadı. Lütfen en az bir istemci seçiniz.", HttpStatus.NOT_ACCEPTABLE);
// }
// try {
// String [] allAgentDNs = allAgents.stream().map(LdapEntry::getDistinguishedName).toArray(String[]::new);
// for (int i = 0; i < allAgentDNs.length; i++) {
// ldapService.updateEntryAddAtribute(params.get("groupDN"), "member", allAgentDNs[i]);
// }
// entry = ldapService.getEntryDetail(params.get("groupDN"));
// } catch (LdapException e) {
// logger.error("Error occured while adding new group.");
// HttpHeaders headers = new HttpHeaders();
// return ResponseEntity.
// status(HttpStatus.EXPECTATION_FAILED).
// headers(headers)
// .build();
// }
//
// Map<String, Object> requestData = new HashMap<String, Object>();
// List<String> computerAdded = new ArrayList<>();
//
// for (LdapEntry computer : entries) {
// if (computer.getUid() != null) {
// computerAdded.add(computer.getUid());
// }
// }
// requestData.put("uid",computerAdded);
// ObjectMapper dataMapper = new ObjectMapper();
// String jsonString = null;
// try {
// jsonString = dataMapper.writeValueAsString(requestData);
// } catch (JsonProcessingException e1) {
// logger.error("Error occured while mapping request data to json. Error: " + e1.getMessage());
// }
// String log = "Computers has been added to " + entry.getDistinguishedName();
// operationLogService.saveOperationLog(OperationType.UPDATE, log, jsonString.getBytes(), null, null, null);
//
// return new ResponseEntity<LdapEntry>(entry, HttpStatus.OK);
// }
}
9 changes: 6 additions & 3 deletions src/main/java/tr/org/lider/controllers/PolicyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -28,9 +27,9 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import tr.org.lider.entities.CommandImpl;
import tr.org.lider.entities.PolicyImpl;
import tr.org.lider.ldap.LdapEntry;
import tr.org.lider.models.PolicyExecutionRequestImpl;
import tr.org.lider.models.PolicyResponse;
import tr.org.lider.services.PolicyExceptionService;
import tr.org.lider.services.PolicyService;

/**
Expand All @@ -49,6 +48,9 @@ public class PolicyController {

@Autowired
private PolicyService policyService;

@Autowired
private PolicyExceptionService policyExceptionService;

// return policies if deleted is false

Expand Down Expand Up @@ -109,6 +111,8 @@ public ResponseEntity<PolicyImpl> policyAdd(@RequestBody PolicyImpl params) {
@DeleteMapping(value = "/delete/id/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PolicyImpl> policyDelete(@PathVariable Long id) {
try {

policyExceptionService.deletePolicyExceptionByPolicy(policyService.findPolicyByID(id));
return ResponseEntity
.status(HttpStatus.OK)
.body(policyService.delete(id));
Expand Down Expand Up @@ -232,7 +236,6 @@ public ResponseEntity<CommandImpl> unassignmentPolicyOfUser(@RequestBody Command
return ResponseEntity
.status(HttpStatus.OK)
.body(policyService.unassignmentCommandForUserPolicy(id));

}

@Operation(summary = "Returns active policies", description = "", tags = { "policy" })
Expand Down
Loading

0 comments on commit 2b49baf

Please sign in to comment.