Skip to content

Commit

Permalink
Merge pull request #12 from muralibasani/improvements_3.2
Browse files Browse the repository at this point in the history
3.2 - SSL connectivity to cluster, improvements and enhancements in UI and Backend.
  • Loading branch information
muralibasani authored Sep 25, 2019
2 parents 2579706 + 2296ee9 commit adeae7d
Show file tree
Hide file tree
Showing 37 changed files with 661 additions and 568 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Or

Pdf : https://buildmedia.readthedocs.org/media/pdf/kafkawize/latest/kafkawize.pdf

Download options : https://kafkawize.readthedocs.io/en/latest/getting_started.html#download-kafkawize-3-1
Download options : https://kafkawize.readthedocs.io/en/latest/getting_started.html#download-kafkawize


<b>Screenshots</b>
Expand Down Expand Up @@ -42,3 +42,5 @@ Download options : https://kafkawize.readthedocs.io/en/latest/getting_started.ht
![ImageFig17](https://github.com/kafkawize/kafkawize/blob/master/screenshots/ActivityLog.JPG)

![ImageFig18](https://github.com/kafkawize/kafkawize/blob/master/screenshots/ViewUsers.JPG)

![ImageFig20](https://github.com/kafkawize/kafkawize/blob/master/screenshots/ViewTeams.JPG)
2 changes: 1 addition & 1 deletion ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Kafkawize 3.1
Kafkawize 3.2

Kafkawize is a Kafka Topic management tool (A Web application) which automates the process of creating and browsing Kafka components, by introducing roles/authorizations to users of various teams of an organization

Expand Down
2 changes: 1 addition & 1 deletion kafkawize-conf/environments/local/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ server.port:9097
server.servlet.context-path=/kafkawize

# db.storetype should be "cassandra" or "rdbms"
db.storetype=rdbms
db.storetype=cassandra

# cluster api properties
clusterapi.url:http://localhost:9343
Expand Down
2 changes: 1 addition & 1 deletion kafkawize-conf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kafkawize</artifactId>
<groupId>com.kafkamgt.uiapi</groupId>
<version>3.1</version>
<version>3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion kafkawize-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kafkawize</artifactId>
<groupId>com.kafkamgt.uiapi</groupId>
<version>3.1</version>
<version>3.2</version>
</parent>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.kafkamgt.uiapi.dao.AclRequests;
import com.kafkamgt.uiapi.error.KafkawizeException;
import com.kafkamgt.uiapi.model.AclInfo;
import com.kafkamgt.uiapi.service.AclControllerService;
import org.slf4j.Logger;
Expand Down Expand Up @@ -55,18 +56,18 @@ public ResponseEntity<String> deleteAclRequests(@RequestParam("req_no") String r
}

@PostMapping(value = "/execAclRequest")
public ResponseEntity<String> approveAclRequests(@RequestParam("req_no") String req_no) {
public ResponseEntity<String> approveAclRequests(@RequestParam("req_no") String req_no) throws KafkawizeException {
return new ResponseEntity<String>(aclControllerService.approveAclRequests(req_no), HttpStatus.OK);
}

@RequestMapping(value = "/getAcls", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<AclInfo>> getAcls(@RequestParam("env") String env, @RequestParam("pageNo") String pageNo,
@RequestParam(value="topicnamesearch",required=false) String topicNameSearch) {
@RequestParam(value="topicnamesearch",required=false) String topicNameSearch) throws KafkawizeException {
return new ResponseEntity<>(aclControllerService.getAcls(env, pageNo, topicNameSearch, false), HttpStatus.OK);
}

@RequestMapping(value = "/getSyncAcls", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<AclInfo>> getSyncAcls(@RequestParam("env") String env, @RequestParam("pageNo") String pageNo) {
public ResponseEntity<List<AclInfo>> getSyncAcls(@RequestParam("env") String env, @RequestParam("pageNo") String pageNo) throws KafkawizeException {
return new ResponseEntity<>(aclControllerService.getAcls(env, pageNo, null, true), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.kafkamgt.uiapi.dao.SchemaRequest;
import com.kafkamgt.uiapi.error.KafkawizeException;
import com.kafkamgt.uiapi.service.SchemaRegstryControllerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -48,7 +49,7 @@ public ResponseEntity<String> deleteSchemaRequests(@RequestParam("topicName") St
}

@RequestMapping(value = "/execSchemaRequests", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> execSchemaRequests(@RequestParam("topicName") String topicName) {
public ResponseEntity<String> execSchemaRequests(@RequestParam("topicName") String topicName) throws KafkawizeException {

String updateTopicReqStatus = "{\"result\":\"" + schemaRegstryControllerService.execSchemaRequests(topicName) + "\"}";
return new ResponseEntity<>(updateTopicReqStatus, HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.kafkamgt.uiapi.dao.Topic;
import com.kafkamgt.uiapi.dao.TopicRequest;
import com.kafkamgt.uiapi.error.KafkawizeException;
import com.kafkamgt.uiapi.model.PCStream;
import com.kafkamgt.uiapi.model.TopicInfo;
import com.kafkamgt.uiapi.service.TopicControllerService;
Expand Down Expand Up @@ -72,7 +73,7 @@ public ResponseEntity<String> deleteTopicRequests(@RequestParam("topicName") Str
}

@RequestMapping(value = "/execTopicRequests", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> approveTopicRequests(@RequestParam("topicName") String topicName) {
public ResponseEntity<String> approveTopicRequests(@RequestParam("topicName") String topicName) throws KafkawizeException {

return new ResponseEntity<>(topicControllerService.approveTopicRequests(topicName), HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
package com.kafkamgt.uiapi.controller;

import com.kafkamgt.uiapi.dao.Team;
import com.kafkamgt.uiapi.dao.ActivityLog;
import com.kafkamgt.uiapi.dao.Env;
import com.kafkamgt.uiapi.dao.Team;
import com.kafkamgt.uiapi.dao.UserInfo;
import com.kafkamgt.uiapi.service.ManageTopics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.kafkamgt.uiapi.service.UiConfigControllerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.json.GsonJsonParser;
import org.springframework.http.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.List;


@RestController
Expand All @@ -28,230 +21,84 @@ public class UiConfigController {

//private static Logger LOG = LoggerFactory.getLogger(UiConfigController.class);

@Autowired
private UiConfigControllerService uiConfigControllerService;

@Autowired
private ManageTopics manageTopics;

@RequestMapping(value = "/getEnvs", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<Env>> getEnvs() {
return new ResponseEntity<>(manageTopics.selectAllKafkaEnvs(), HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.getEnvs(), HttpStatus.OK);
}

@RequestMapping(value = "/getSchemaRegEnvs", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<Env>> getSchemaRegEnvs() {
return new ResponseEntity<>(manageTopics.selectAllSchemaRegEnvs(), HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.getSchemaRegEnvs(), HttpStatus.OK);
}

@RequestMapping(value = "/getAllTeams", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<Team>> getAllTeams() {
return new ResponseEntity<>(manageTopics.selectAllTeamsOfUsers(getUserName()), HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.getAllTeams(), HttpStatus.OK);
}

@RequestMapping(value = "/getAllTeamsSU", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<Team>> getAllTeamsSU() {

return new ResponseEntity<>(manageTopics.selectAllTeams(), HttpStatus.OK);
}

private final InMemoryUserDetailsManager inMemoryUserDetailsManager;

@Autowired
public UiConfigController(InMemoryUserDetailsManager inMemoryUserDetailsManager) {
this.inMemoryUserDetailsManager = inMemoryUserDetailsManager;
return new ResponseEntity<>(uiConfigControllerService.getAllTeamsSU(), HttpStatus.OK);
}

@PostMapping(value = "/addNewEnv")
public ResponseEntity<String> addNewEnv(@RequestBody Env newEnv){

UserDetails userDetails = getUserDetails();

GrantedAuthority ga = userDetails.getAuthorities().iterator().next();
String authority = ga.getAuthority();
String json = "";
if(authority.equals("ROLE_SUPERUSER")){}
else{
json = "{ \"result\": \"Not Authorized\" }";
return new ResponseEntity<String>(json, HttpStatus.OK);
}

newEnv.setTrustStorePwd("");
newEnv.setKeyPwd("");
newEnv.setKeyStorePwd("");
newEnv.setTrustStoreLocation("");
newEnv.setKeyStoreLocation("");
String execRes = manageTopics.addNewEnv(newEnv);

String envAddResult = "{\"result\":\""+execRes+"\"}";
return new ResponseEntity<String>(envAddResult, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.addNewEnv(newEnv), HttpStatus.OK);
}

@PostMapping(value = "/deleteClusterRequest")
public ResponseEntity<String> deleteCluster(@RequestParam ("clusterId") String clusterId){

String execRes = manageTopics.deleteClusterRequest(clusterId);
return new ResponseEntity<>(uiConfigControllerService.deleteCluster(clusterId), HttpStatus.OK);
}

@PostMapping(value = "/deleteTeamRequest")
public ResponseEntity<String> deleteTeam(@RequestParam ("teamId") String teamId){

String envAddResult = "{\"result\":\""+execRes+"\"}";
return new ResponseEntity<>(envAddResult, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.deleteTeam(teamId), HttpStatus.OK);
}

@PostMapping(value = "/deleteUserRequest")
public ResponseEntity<String> deleteUser(@RequestParam ("userId") String userId){

String envAddResult = "{\"result\":\"User cannot be deleted\"}";

if(userId.equals("superuser") || getUserName().equals(userId))
return new ResponseEntity<>(envAddResult, HttpStatus.OK);

String execRes = manageTopics.deleteUserRequest(userId);
envAddResult = "{\"result\":\""+execRes+"\"}";

return new ResponseEntity<>(envAddResult, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.deleteUser(userId), HttpStatus.OK);
}

@PostMapping(value = "/addNewUser")
public ResponseEntity<String> addNewUser(@RequestBody UserInfo newUser){

PasswordEncoder encoder =
PasswordEncoderFactories.createDelegatingPasswordEncoder();
inMemoryUserDetailsManager.createUser(User.withUsername(newUser.getUsername()).password(encoder.encode(newUser.getPwd()))
.roles(newUser.getRole()).build());

String execRes = manageTopics.addNewUser(newUser);

String userAddResult = "{\"result\":\""+execRes+"\"}";
return new ResponseEntity<>(userAddResult, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.addNewUser(newUser), HttpStatus.OK);
}

@PostMapping(value = "/addNewTeam")
public ResponseEntity<String> addNewTeam(@RequestBody Team newTeam){

UserDetails userDetails = getUserDetails();

GrantedAuthority ga = userDetails.getAuthorities().iterator().next();
String authority = ga.getAuthority();
String json = "";
if(authority.equals("ROLE_SUPERUSER")){}
else{
json = "{ \"result\": \"Not Authorized\" }";
return new ResponseEntity<>(json, HttpStatus.OK);
}

String execRes = manageTopics.addNewTeam(newTeam);

String teamAddResult = "{\"result\":\""+execRes+"\"}";
return new ResponseEntity<>(teamAddResult, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.addNewTeam(newTeam), HttpStatus.OK);
}

@PostMapping(value = "/chPwd")
public ResponseEntity<String> changePwd(@RequestParam ("changePwd") String changePwd){

UserDetails userDetails = getUserDetails();

GsonJsonParser jsonParser = new GsonJsonParser();
Map<String, Object> pwdMap = jsonParser.parseMap(changePwd);

String pwdChange = (String)pwdMap.get("pwd");

PasswordEncoder encoder =
PasswordEncoderFactories.createDelegatingPasswordEncoder();
UserDetails ud = new UserDetails() {
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return userDetails.getAuthorities();
}

@Override
public String getPassword() {
return encoder.encode(pwdChange);
}

@Override
public String getUsername() {
return userDetails.getUsername();
}

@Override
public boolean isAccountNonExpired() {
return userDetails.isAccountNonExpired();
}

@Override
public boolean isAccountNonLocked() {
return userDetails.isAccountNonLocked();
}

@Override
public boolean isCredentialsNonExpired() {
return userDetails.isCredentialsNonExpired();
}

@Override
public boolean isEnabled() {
return userDetails.isEnabled();
}
};

inMemoryUserDetailsManager.updateUser(ud);

String execRes = manageTopics.updatePassword(userDetails.getUsername(),pwdChange);

String pwdChResult = "{\"result\":\""+execRes+"\"}";
return new ResponseEntity<>(pwdChResult, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.changePwd(changePwd), HttpStatus.OK);
}

@RequestMapping(value = "/showUserList", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<UserInfo>> showUsers(){

List<UserInfo> userList = manageTopics.selectAllUsersInfo();

return new ResponseEntity<>(userList, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.showUsers(), HttpStatus.OK);
}

@RequestMapping(value = "/getMyProfileInfo", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<UserInfo> getMyProfileInfo(){

UserInfo userList = manageTopics.getUsersInfo(getUserName());

return new ResponseEntity<>(userList, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.getMyProfileInfo(), HttpStatus.OK);
}

@RequestMapping(value = "/activityLog", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<ActivityLog>> showActivityLog(@RequestParam("env") String env, @RequestParam("pageNo") String pageNo){

List<ActivityLog> origActivityList = manageTopics.selectActivityLog(getUserName(), env);

int totalRecs = origActivityList.size();
int recsPerPage = 20;

int requestPageNo = Integer.parseInt(pageNo);
int startVar = (requestPageNo-1) * recsPerPage;
int lastVar = (requestPageNo) * (recsPerPage);

int totalPages = totalRecs/recsPerPage + (totalRecs%recsPerPage > 0 ? 1 : 0);

List<ActivityLog> newList = new ArrayList<>();

List<String> numList = new ArrayList<>();
for (int k = 1; k <= totalPages; k++) {
numList.add("" + k);
}
for(int i=0;i<totalRecs;i++){
ActivityLog activityLog = origActivityList.get(i);
if(i>=startVar && i<lastVar) {
activityLog.setAllPageNos(numList);
activityLog.setTotalNoPages("" + totalPages);

newList.add(activityLog);
}
}
return new ResponseEntity<>(newList, HttpStatus.OK);
return new ResponseEntity<>(uiConfigControllerService.showActivityLog(env,pageNo), HttpStatus.OK);
}

private String getUserName(){
UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return userDetails.getUsername();
}

private UserDetails getUserDetails(){
return (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
}
}
Loading

0 comments on commit adeae7d

Please sign in to comment.