[ADD] CHANGES

parent 6748b4bb
......@@ -31,3 +31,4 @@ build/
### VS Code ###
.vscode/
/target/
......@@ -23,12 +23,11 @@ public class AppApi {
@PostMapping("/procedure")
public String callProcedure(@RequestBody String body) {
JSONObject json = new JSONObject(body);
if (json.has("procedure")) {
try {
JSONArray params = json.isNull("params") ? new JSONArray() : json.getJSONArray("params");
JSONObject response = procedureMysql.ProcedureExecution(json.getString("procedure"), params.toList().toArray());
return response.put("status", true).put("message", "Success").toString();
JSONObject response = procedureMysql.ProcedureExecution(json.getString("procedure"),json.getString("database"), params.toList().toArray());
return response.toString();
} catch (Exception e) {
return new JSONObject().put("data", new JSONArray()).put("message", e.getMessage()).put("status", false).toString();
}
......
......@@ -9,6 +9,9 @@ import web.multitask.app.repository.UserRespository;
import web.multitask.app.utils.JwtTokenUtil;
import java.util.Objects;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@RestController
......@@ -35,4 +38,15 @@ class JwtApi {
}
}
@PostMapping("/validate")
public String validateToken(@RequestBody String token) {
JSONObject json = new JSONObject(token);
if (jwtTokenUtil.validateToken(json.getString("token"))) {
return new JSONObject().put("message", "Valid Token").put("status", true).toString();
} else {
return new JSONObject().put("message", "Invalid Token").put("status", false).toString();
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
......@@ -16,7 +17,6 @@ import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.filter.OncePerRequestFilter;
import web.multitask.app.filter.JwtTokenFilter;
import web.multitask.app.repository.UserRespository;
import web.multitask.app.utils.JwtTokenUtil;
......@@ -34,9 +34,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
@Override
......
......@@ -53,7 +53,7 @@ public class JwtTokenFilter extends OncePerRequestFilter {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authentication);
response.setStatus(200, "OK");
response.setStatus(200);
chain.doFilter(request, response);
} else {
response.sendError(401, "Invalid Token");
......
package web.multitask.app.model;
;
import javax.persistence.*;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import javax.persistence.*;
@Entity
@Table(name = "roles")
@Data
@NoArgsConstructor
@Getter
@Setter
@Entity(name = "roles")
public class Role {
@NonNull
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
......
......@@ -7,7 +7,6 @@ import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@Service
public class ProcedureMysql {
......@@ -18,15 +17,34 @@ public class ProcedureMysql {
this.jdbcTemplate = jdbcTemplate;
}
public JSONObject ProcedureExecution(String query , Object[] params) {
public JSONObject ProcedureExecution(String procedure ,String database, Object[] params) {
try {
List<Map<String, Object>> list = jdbcTemplate.queryForList(query, params);
StringBuilder query = new StringBuilder("CALL " + database + "." + procedure);
if (params.length > 0) {
query.append("(");
for (int i = 0; i < params.length; i++) {
query.append("?");
if (i < params.length - 1) {
query.append(",");
}
}
query.append(")");
}
String checkProcedure = "SELECT COUNT(*) FROM information_schema.routines WHERE routine_schema = '" + database + "' AND routine_name = '" + procedure + "'";
List<Map<String, Object>> countProcedure = jdbcTemplate.queryForList(checkProcedure);
if (countProcedure.get(0).get("COUNT(*)").toString().equals("0")) {
return new JSONObject().put("message", "Procedure not found").put("status", false);
}
List<Map<String, Object>> list = jdbcTemplate.queryForList(query.toString(), params);
JSONObject result = new JSONObject();
result.put("data", list);
return result;
} catch (Exception e) {
Logger.getLogger("ProcedureMysql").warning(e.getMessage());
return new JSONObject().put("data", new JSONObject()).put("message", e.getMessage()).put("status", false);
}
return null;
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ spring.datasource.url=jdbc:mysql://13.59.147.125:3306/security
spring.datasource.username=server
spring.datasource.password=asd123
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
server.port=8080
server.port=8081
server.address=0.0.0.0
spring.jpa.show-sql=true
app.jwtSecret=9a4f2c8d3b7a1e6f45c8a0b3f267d8b1d4e6f3c8a9d2b5f8e3a9c8b5f6v8a3d9
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment