├── MailServiceJava ├── .gitattributes ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── technp │ │ │ └── mail │ │ │ └── mailservice │ │ │ ├── HelperFuctions │ │ │ ├── MailRequestDTO.java │ │ │ └── NumGenerator.java │ │ │ ├── MailServiceApplication.java │ │ │ ├── MailController.java │ │ │ ├── MailConfig.java │ │ │ └── MailService.java │ └── test │ │ └── java │ │ └── com │ │ └── technp │ │ └── mail │ │ └── mailservice │ │ ├── MailServiceApplicationTests.java │ │ └── HelperFuctions │ │ └── RandomCodeGenerator.java ├── .gitignore ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── pom.xml ├── mvnw.cmd └── mvnw ├── VerificationSystemJava ├── .gitattributes ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── techdgnep │ │ │ │ └── login │ │ │ │ ├── Service │ │ │ │ ├── UserImpl.java │ │ │ │ ├── UserRepository.java │ │ │ │ ├── GetCode.java │ │ │ │ └── Manager.java │ │ │ │ ├── test │ │ │ │ ├── RandomCodeGenerator.java │ │ │ │ └── Validation.java │ │ │ │ ├── LoginTgNepApplication.java │ │ │ │ ├── DataModel │ │ │ │ ├── External │ │ │ │ │ ├── CodeEntry.java │ │ │ │ │ └── VerificationRequest.java │ │ │ │ └── Database │ │ │ │ │ └── FinalUser.java │ │ │ │ └── Cotroller │ │ │ │ └── MailController.java │ │ └── resources │ │ │ └── application.properties │ └── test │ │ └── java │ │ └── com │ │ └── techdgnep │ │ └── login │ │ └── LoginTgNepApplicationTests.java ├── .gitignore ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── pom.xml ├── mvnw.cmd └── mvnw ├── MailServiceDotNet ├── MailServer.http ├── appsettings.Development.json ├── appsettings.json ├── Program.cs ├── MailServer.csproj ├── MailController1.cs ├── Properties │ └── launchSettings.json └── HelperFunction.cs ├── .gitignore └── README.md /MailServiceJava/.gitattributes: -------------------------------------------------------------------------------- 1 | /mvnw text eol=lf 2 | *.cmd text eol=crlf 3 | -------------------------------------------------------------------------------- /VerificationSystemJava/.gitattributes: -------------------------------------------------------------------------------- 1 | /mvnw text eol=lf 2 | *.cmd text eol=crlf 3 | -------------------------------------------------------------------------------- /MailServiceJava/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=MailService 2 | server.port=8081 3 | -------------------------------------------------------------------------------- /MailServiceDotNet/MailServer.http: -------------------------------------------------------------------------------- 1 | @MailServer_HostAddress = http://localhost:5201 2 | 3 | GET {{MailServer_HostAddress}}/weatherforecast/ 4 | Accept: application/json 5 | 6 | ### 7 | -------------------------------------------------------------------------------- /MailServiceDotNet/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MailServiceDotNet/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/Service/UserImpl.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.Service; 2 | 3 | import com.techdgnep.login.DataModel.Database.FinalUser; 4 | 5 | public interface UserImpl { 6 | public Long Save(FinalUser user); 7 | } 8 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/test/java/com/techdgnep/login/LoginTgNepApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class LoginTgNepApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /MailServiceJava/src/test/java/com/technp/mail/mailservice/MailServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.technp.mail.mailservice; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class MailServiceApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /MailServiceDotNet/Program.cs: -------------------------------------------------------------------------------- 1 | using MailServer; 2 | 3 | var builder = WebApplication.CreateBuilder(args); 4 | 5 | builder.Services.AddControllers(); 6 | builder.Services.AddEndpointsApiExplorer(); 7 | builder.Services.AddScoped(); 8 | builder.Services.AddScoped(); 9 | var app = builder.Build(); 10 | 11 | app.UseAuthorization(); 12 | app.MapControllers(); 13 | app.Run(); 14 | 15 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=LoginTGNep 2 | server.port=8081 3 | spring.datasource.url=jdbc:mysql://localhost:3306/GameBase 4 | spring.datasource.username=root 5 | spring.datasource.password=asnit123 6 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 7 | spring.jpa.database=mysql 8 | spring.jpa.show-sql=true 9 | spring.jpa.hibernate.ddl-auto=update -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/Service/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.Service; 2 | 3 | import com.techdgnep.login.DataModel.Database.FinalUser; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface UserRepository extends JpaRepository { 9 | } 10 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/test/RandomCodeGenerator.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.test; 2 | 3 | import java.util.Random; 4 | 5 | 6 | public class RandomCodeGenerator { 7 | private final Random random; 8 | 9 | public RandomCodeGenerator(){ 10 | this.random = new Random(); 11 | } 12 | 13 | public int GenerateCode(){ 14 | return random.nextInt(100000,999999); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MailServiceJava/src/test/java/com/technp/mail/mailservice/HelperFuctions/RandomCodeGenerator.java: -------------------------------------------------------------------------------- 1 | package com.technp.mail.mailservice.HelperFuctions; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.Random; 8 | 9 | @Component 10 | public class RandomCodeGenerator { 11 | 12 | @Autowired 13 | private Random random; 14 | 15 | 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/LoginTgNepApplication.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class LoginTgNepApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(LoginTgNepApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /MailServiceJava/src/main/java/com/technp/mail/mailservice/HelperFuctions/MailRequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.technp.mail.mailservice.HelperFuctions; 2 | 3 | public class MailRequestDTO { 4 | private String email; 5 | 6 | public MailRequestDTO() { 7 | } 8 | 9 | public MailRequestDTO(String email) { 10 | this.email = email; 11 | } 12 | 13 | public String getEmail() { 14 | return email; 15 | } 16 | 17 | public void setEmail(String email) { 18 | this.email = email; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MailServiceJava/src/main/java/com/technp/mail/mailservice/HelperFuctions/NumGenerator.java: -------------------------------------------------------------------------------- 1 | package com.technp.mail.mailservice.HelperFuctions; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.Random; 7 | 8 | @Component 9 | public class NumGenerator { 10 | 11 | @Autowired 12 | private Random random; 13 | 14 | public Integer generateEmailVerificationCode(){ 15 | return random.nextInt(100000,1000000); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /MailServiceJava/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | .mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /VerificationSystemJava/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | .mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /MailServiceDotNet/MailServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /MailServiceDotNet/MailController1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace MailServer; 4 | [ApiController] 5 | [Route("api/mail")] 6 | public class MailController1(HelperFunction func) : ControllerBase 7 | { 8 | [HttpGet("send")] 9 | public ActionResult SendMailAndGetCode([FromQuery]string email) 10 | { 11 | try 12 | { 13 | var code = func.SendMail(email); 14 | return Ok(code); 15 | } 16 | catch (Exception ex) 17 | { 18 | Console.WriteLine(ex.Message); 19 | return NotFound(0); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.tmp 3 | *.bak 4 | *.swp 5 | *.DS_Store 6 | Thumbs.db 7 | 8 | target/ 9 | pom.xml.tag 10 | pom.xml.releaseBackup 11 | pom.xml.versionsBackup 12 | release.properties 13 | dependency-reduced-pom.xml 14 | 15 | **/bin/ 16 | **/obj/ 17 | **/out/ 18 | 19 | .idea/ 20 | *.iml 21 | *.ipr 22 | *.iws 23 | .vscode/ 24 | *.class 25 | 26 | logs/ 27 | .env 28 | *.pid 29 | 30 | project.lock.json 31 | project.fragment.lock.json 32 | *.user 33 | *.suo 34 | *.userosscache 35 | *.sln.docstates 36 | *.vs/ 37 | 38 | wwwroot/lib/ 39 | *.db 40 | *.sqlite 41 | *.pdb 42 | 43 | ehthumbs.db 44 | Icon? 45 | Desktop.ini 46 | 47 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/Service/GetCode.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.Service; 2 | 3 | import org.springframework.stereotype.Service; 4 | import org.springframework.web.client.RestTemplate; 5 | 6 | @Service 7 | public class GetCode { 8 | private final RestTemplate restTemplate; 9 | 10 | public GetCode(){ 11 | this.restTemplate = new RestTemplate(); 12 | } 13 | 14 | public Integer GetMailCode(String email) throws Exception{ 15 | String url = "http://localhost:5201/api/mail/send?email="+email; 16 | return restTemplate.getForObject(url,Integer.class); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /MailServiceJava/src/main/java/com/technp/mail/mailservice/MailServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.technp.mail.mailservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | 7 | 8 | import java.util.Random; 9 | 10 | @SpringBootApplication 11 | public class MailServiceApplication { 12 | 13 | 14 | public static void main(String[] args) { 15 | 16 | SpringApplication.run(MailServiceApplication.class, args); 17 | } 18 | 19 | 20 | @Bean 21 | public Random random(){ 22 | return new Random(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/DataModel/External/CodeEntry.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.DataModel.External; 2 | 3 | public class CodeEntry { 4 | private final int code; 5 | private final long createdAt; 6 | private int attempts; 7 | 8 | public CodeEntry(int code) { 9 | this.code = code; 10 | this.createdAt = System.currentTimeMillis(); 11 | this.attempts = 0; 12 | } 13 | 14 | public int getCode() { 15 | return code; 16 | } 17 | 18 | public long getCreatedAt() { 19 | return createdAt; 20 | } 21 | 22 | public int getAttempts() { 23 | return attempts; 24 | } 25 | 26 | public void incrementAttempts() { 27 | this.attempts++; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/DataModel/External/VerificationRequest.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.DataModel.External; 2 | 3 | public class VerificationRequest { 4 | private String email; 5 | private int verificationCode; 6 | 7 | public VerificationRequest(){ 8 | } 9 | 10 | public VerificationRequest(String email, int verificationCode) { 11 | this.email = email; 12 | this.verificationCode = verificationCode; 13 | } 14 | 15 | public String getEmail() { 16 | return email; 17 | } 18 | 19 | public void setEmail(String email) { 20 | this.email = email; 21 | } 22 | 23 | public int getVerificationCode() { 24 | return verificationCode; 25 | } 26 | 27 | public void setVerificationCode(int verificationCode) { 28 | this.verificationCode = verificationCode; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /MailServiceJava/src/main/java/com/technp/mail/mailservice/MailController.java: -------------------------------------------------------------------------------- 1 | package com.technp.mail.mailservice; 2 | 3 | 4 | import com.technp.mail.mailservice.HelperFuctions.MailRequestDTO; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | @RequestMapping("/mindgame") 14 | public class MailController { 15 | 16 | @Autowired 17 | private MailService mailService; 18 | 19 | @PostMapping 20 | public ResponseEntity SendVerification(@RequestBody MailRequestDTO sender){ 21 | return ResponseEntity.ok(mailService.SendEmail(sender.getEmail())); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MailServiceJava/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.10/apache-maven-3.9.10-bin.zip 20 | -------------------------------------------------------------------------------- /VerificationSystemJava/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.10/apache-maven-3.9.10-bin.zip 20 | -------------------------------------------------------------------------------- /MailServiceJava/src/main/java/com/technp/mail/mailservice/MailConfig.java: -------------------------------------------------------------------------------- 1 | package com.technp.mail.mailservice; 2 | 3 | 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.mail.javamail.JavaMailSender; 7 | import org.springframework.mail.javamail.JavaMailSenderImpl; 8 | 9 | import java.util.Properties; 10 | 11 | @Configuration 12 | public class MailConfig { 13 | 14 | @Bean 15 | public JavaMailSender javaMailSender(){ 16 | JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); 17 | mailSender.setHost("smtp.gmail.com"); 18 | mailSender.setPort(587); 19 | mailSender.setUsername("your@gmail.com"); 20 | mailSender.setPassword("your app pass word"); 21 | 22 | Properties props = mailSender.getJavaMailProperties(); 23 | props.put("mail.smtp.auth", "true"); 24 | props.put("mail.smtp.starttls.enable", "true"); 25 | props.put("mail.transport.protocol", "smtp"); 26 | 27 | return mailSender; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /MailServiceDotNet/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:1756", 8 | "sslPort": 44328 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5201", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7192;http://localhost:5201", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MailServiceDotNet/HelperFunction.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using MailKit.Security; 3 | 4 | namespace MailServer; 5 | using MimeKit; 6 | using MailKit.Net.Smtp; 7 | 8 | public class HelperFunction(Random random) 9 | { 10 | private int GenerateRandomCode() 11 | { 12 | return random.Next(100000, 999999); 13 | } 14 | 15 | public int SendMail(string eMail) 16 | { 17 | try 18 | { 19 | var code = GenerateRandomCode(); 20 | 21 | var email = new MimeMessage(); 22 | email.From.Add(MailboxAddress.Parse("furnituremandu@gmail.com")); 23 | email.To.Add(MailboxAddress.Parse(eMail)); 24 | email.Subject = "Verification of Your Sign Up"; 25 | email.Body = new TextPart(MimeKit.Text.TextFormat.Plain) 26 | { 27 | Text = $"Your code is: {code}. Please do not share it with anyone." 28 | }; 29 | 30 | using var smtp = new MailKit.Net.Smtp.SmtpClient(); 31 | smtp.Connect("smtp.gmail.com", 587, MailKit.Security.SecureSocketOptions.StartTls); 32 | smtp.Authenticate("yourmailhere@gmail.com", "appPassworhere); 33 | smtp.Send(email); 34 | smtp.Disconnect(true); 35 | 36 | return code; 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.WriteLine($"Email sending failed: {ex.Message}"); 41 | return -1; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/DataModel/Database/FinalUser.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.DataModel.Database; 2 | 3 | 4 | import jakarta.persistence.*; 5 | 6 | @Entity 7 | public class FinalUser { 8 | @Id 9 | @GeneratedValue(strategy = GenerationType.IDENTITY) 10 | private Long RegisterId; 11 | @Column(nullable = false) 12 | private String userName; 13 | @Column(unique = true,nullable = false) 14 | private String email; 15 | @Column(nullable = false) 16 | private String passcode; 17 | 18 | public FinalUser(String email, String userName, String passcode,Long registerId) { 19 | this.RegisterId =registerId; 20 | this.email = email; 21 | this.userName = userName; 22 | this.passcode = passcode; 23 | } 24 | 25 | public FinalUser() { 26 | } 27 | 28 | public String getUserName() { 29 | return userName; 30 | } 31 | 32 | public void setUserName(String userName) { 33 | this.userName = userName; 34 | } 35 | 36 | public String getPasscode() { 37 | return passcode; 38 | } 39 | 40 | public void setPasscode(String passcode) { 41 | this.passcode = passcode; 42 | } 43 | 44 | public String getEmail() { 45 | return email; 46 | } 47 | 48 | public void setEmail(String email) { 49 | this.email = email; 50 | } 51 | 52 | public Long getRegisterId() { 53 | return RegisterId; 54 | } 55 | 56 | public void setRegisterId(Long registerId) { 57 | RegisterId = registerId; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /MailServiceJava/src/main/java/com/technp/mail/mailservice/MailService.java: -------------------------------------------------------------------------------- 1 | package com.technp.mail.mailservice; 2 | 3 | 4 | import com.technp.mail.mailservice.HelperFuctions.NumGenerator; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.mail.SimpleMailMessage; 9 | import org.springframework.mail.javamail.JavaMailSender; 10 | import org.springframework.stereotype.Service; 11 | 12 | @Service 13 | public class MailService { 14 | 15 | private Logger logger = LoggerFactory.getLogger(MailService.class); 16 | 17 | 18 | @Autowired 19 | private JavaMailSender javaMailSender; 20 | 21 | @Autowired 22 | private NumGenerator numGenerator; 23 | 24 | public Integer SendEmail(String email) { 25 | try { 26 | SimpleMailMessage message = new SimpleMailMessage(); 27 | message.setFrom("furnituremandu@gmail.com"); 28 | message.setTo(email); 29 | message.setSubject("Verification Code"); 30 | Integer code = numGenerator.generateEmailVerificationCode(); 31 | String body = "Your email was used to Sign up for in our website. If this was not you please secure your account." 32 | + " Your code is " + code; 33 | message.setText(body); 34 | javaMailSender.send(message); 35 | return code; 36 | 37 | 38 | } catch (Exception ex) { 39 | logger.error("Mail was not Sent :", ex.getCause()); 40 | } 41 | return -1; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /MailServiceJava/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.5.3 9 | 10 | 11 | com.technp.mail 12 | MailService 13 | 0.0.1-SNAPSHOT 14 | MailService 15 | MailService 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 21 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-mail 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-web 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/test/Validation.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.test; 2 | 3 | 4 | import java.nio.charset.StandardCharsets; 5 | import java.security.MessageDigest; 6 | import java.security.NoSuchAlgorithmException; 7 | import java.util.Scanner; 8 | import com.techdgnep.login.test.RandomCodeGenerator; 9 | 10 | public class Validation { 11 | private static RandomCodeGenerator generator; 12 | 13 | public static void main(String[] args) { 14 | Scanner Input = new Scanner(System.in); 15 | System.out.println("Enter the email : "); 16 | String email = Input.nextLine(); 17 | System.out.println("Enter the password : "); 18 | try { 19 | String password = hash(Input.nextLine()); 20 | System.out.println("Confirm Password : "); 21 | String password2 = hash(Input.nextLine()); 22 | if(password.equals(password2)){ 23 | generator = new RandomCodeGenerator(); 24 | int code = generator.GenerateCode(); 25 | System.out.println("The code "+code+" has been sent to your Email"); 26 | System.out.println("Please Enter the code for verification"); 27 | int x = Input.nextInt(); 28 | if(x==code){ 29 | System.out.println("JWT token getting generated"); 30 | } 31 | } 32 | 33 | }catch (Exception ex){ 34 | ex.printStackTrace(); 35 | } 36 | } 37 | 38 | public static String hash(String input) throws RuntimeException, NoSuchAlgorithmException { 39 | MessageDigest digest = MessageDigest.getInstance("SHA-256"); 40 | byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8)); 41 | StringBuilder hexPass = new StringBuilder(); 42 | for (byte b : hash) { 43 | String hex = Integer.toHexString(0xff & b); 44 | if(hex.length() == 1) hexPass.append('0'); 45 | hexPass.append(hex); 46 | } 47 | return hexPass.toString(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /VerificationSystemJava/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.5.3 9 | 10 | 11 | com.techdgnep 12 | LoginTGNep 13 | 0.0.1-SNAPSHOT 14 | LoginTGNep 15 | LoginTGNep 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 21 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-data-jpa 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-jdbc 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-web 45 | 46 | 47 | 48 | org.springdoc 49 | springdoc-openapi-starter-webmvc-ui 50 | 2.1.0 51 | 52 | 53 | 54 | com.mysql 55 | mysql-connector-j 56 | runtime 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-starter-test 61 | test 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/Service/Manager.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.Service; 2 | 3 | import java.nio.charset.StandardCharsets; 4 | import java.security.MessageDigest; 5 | import java.security.NoSuchAlgorithmException; 6 | import com.techdgnep.login.DataModel.External.CodeEntry; 7 | import com.techdgnep.login.DataModel.Database.FinalUser; 8 | import jakarta.transaction.Transactional; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | import java.util.concurrent.ConcurrentHashMap; 14 | 15 | @Component 16 | public class Manager implements UserImpl { 17 | private final int MAX_ENTRIES; 18 | private final long TIMEOUT_MILLI; 19 | private final ConcurrentHashMap codeMap; 20 | private final ConcurrentHashMap userMap; 21 | private final UserRepository repo; 22 | private static Logger logger = LoggerFactory.getLogger(Manager.class); 23 | 24 | @Autowired 25 | public Manager(UserRepository repo){ 26 | this.repo = repo; 27 | this.MAX_ENTRIES = 5; 28 | this.TIMEOUT_MILLI = 5*60*1000; 29 | this.codeMap = new ConcurrentHashMap<>(); 30 | this.userMap = new ConcurrentHashMap<>(); 31 | } 32 | 33 | public boolean InsertUser(FinalUser user,int code){ 34 | codeMap.put(user.getEmail(), new CodeEntry(code)); 35 | userMap.put(user.getEmail(),user); 36 | return true; 37 | } 38 | 39 | public FinalUser checkEntry(String mail,int code) throws Exception { 40 | CodeEntry systemCode = codeMap.get(mail); 41 | if(systemCode==null){ 42 | throw new Exception("User Not found"); 43 | } 44 | systemCode.incrementAttempts(); 45 | if((System.currentTimeMillis()-systemCode.getCreatedAt())>TIMEOUT_MILLI){ 46 | Remove(mail); 47 | throw new Exception("Timeout Reached"); 48 | } 49 | 50 | if(systemCode.getAttempts()>MAX_ENTRIES){ 51 | Remove(mail); 52 | throw new Exception("Max number of Entries reached"); 53 | } 54 | if(code == systemCode.getCode()){ 55 | FinalUser returnUser = userMap.get(mail); 56 | Remove(mail); 57 | return returnUser; 58 | }else return null; 59 | } 60 | 61 | private void Remove(String mail){ 62 | codeMap.remove(mail); 63 | userMap.remove(mail); 64 | } 65 | 66 | public String hash(String input) throws RuntimeException, NoSuchAlgorithmException { 67 | MessageDigest digest = MessageDigest.getInstance("SHA-256"); 68 | byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8)); 69 | StringBuilder hexPass = new StringBuilder(); 70 | for (byte b : hash) { 71 | String hex = Integer.toHexString(0xff & b); 72 | if(hex.length() == 1) hexPass.append('0'); 73 | hexPass.append(hex); 74 | } 75 | return hexPass.toString(); 76 | } 77 | 78 | @Override 79 | @Transactional 80 | public Long Save(FinalUser user){ 81 | try{ 82 | FinalUser repoUser = repo.save(user); 83 | return user.getRegisterId(); 84 | }catch (Exception ex){ 85 | logger.error("Error Saving User"+ex.getMessage()); 86 | return -1L; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /VerificationSystemJava/src/main/java/com/techdgnep/login/Cotroller/MailController.java: -------------------------------------------------------------------------------- 1 | package com.techdgnep.login.Cotroller; 2 | 3 | import com.techdgnep.login.DataModel.Database.FinalUser; 4 | import com.techdgnep.login.DataModel.External.VerificationRequest; 5 | import com.techdgnep.login.Service.GetCode; 6 | import com.techdgnep.login.Service.Manager; 7 | import io.swagger.v3.oas.annotations.Operation; 8 | import io.swagger.v3.oas.annotations.responses.ApiResponse; 9 | import io.swagger.v3.oas.annotations.responses.ApiResponses; 10 | import jakarta.validation.Valid; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.RequestBody; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | 21 | @RestController 22 | @RequestMapping("/signup") 23 | public class MailController { 24 | 25 | private final GetCode getCode; 26 | private final Manager manager; 27 | private static final Logger logger = LoggerFactory.getLogger(MailController.class); 28 | 29 | 30 | @Autowired 31 | public MailController(GetCode getCode, Manager manager) { 32 | this.getCode = getCode; 33 | this.manager = manager; 34 | } 35 | 36 | @Operation(summary = "save user",description = "Send mail code to user and also stores the user in temporarily for registration") 37 | @ApiResponses(value ={ 38 | @ApiResponse(responseCode = "200",description = "Code successfully sent and user is also stored in the server memory "), 39 | @ApiResponse(responseCode = "404",description = "There was problem while sending the mail or storing the user in the memory")}) 40 | @PostMapping("/register") 41 | public ResponseEntity registerUser(@Valid @RequestBody FinalUser newUser) { 42 | try { 43 | int verCode = getCode.GetMailCode(newUser.getEmail()); 44 | if(manager.InsertUser(newUser,verCode)) { 45 | return ResponseEntity.ok("Verification code sent to email: " + newUser.getEmail()); 46 | }else { 47 | return ResponseEntity.internalServerError().body("There was some internal Error"); 48 | } 49 | } catch (Exception ex) { 50 | System.out.println(ex.getMessage()); 51 | return ResponseEntity.badRequest().body("Request was unsuccessful"); 52 | } 53 | } 54 | 55 | @Operation(summary = "Validates verification code",description = "Stores the user in the database when the user is verified with help of code ") 56 | @ApiResponses(value = { 57 | @ApiResponse(responseCode = "200", description = "Success"), 58 | @ApiResponse(responseCode = "404", description = "Code expired or incorrect"), 59 | @ApiResponse(responseCode = "500", description = "DB error") 60 | }) 61 | @PostMapping("/verify") 62 | public ResponseEntity verifyUser(@RequestBody VerificationRequest request) { 63 | try { 64 | FinalUser user = manager.checkEntry(request.getEmail(), request.getVerificationCode()); 65 | if(user!=null){ 66 | user.setPasscode(manager.hash(user.getPasscode())); 67 | Long id = manager.Save(user); 68 | return (id!=-1)? 69 | ResponseEntity.ok(user.getUserName()+"was successfully registered with Id "+id): 70 | ResponseEntity.badRequest().body("Bad Request"); 71 | }else return ResponseEntity.notFound().build(); 72 | } catch (Exception ex) { 73 | logger.error("Error message", ex); 74 | return ResponseEntity.internalServerError().body(ex.getMessage()); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Email Verification Microservice (Spring Boot) 2 | 3 | This project implements an email verification microservice using Spring Boot. It handles user registration with email and password, sends a verification code, and only stores verified users into the database. It is designed to be stateless for unverified users, reducing unnecessary database usage. 4 | 5 | ## Features 6 | 7 | ### 1. Email Verification Flow 8 | - Accepts a registration request with user email and password. 9 | - Hashes the password using SHA-256. 10 | - Generates a random 6-digit verification code. 11 | - Sends the verification code to the user's email using SMTP. 12 | - Waits for user to enter the code. 13 | - If the entered code is correct and within timeout and allowed attempts, user is stored in the database. 14 | 15 | ### 2. No Pre-Verification Persistence 16 | - Unlike Entity Framework Core in .NET, where foreign key constraints often require early data persistence, this Spring Boot microservice does not store unverified data. 17 | - Unverified users are held in memory using in-memory storage until verification. 18 | 19 | ### 3. In-Memory Storage for Verification Process 20 | - Uses `ConcurrentHashMap` to map user emails to their verification codes. 21 | - Uses `ConcurrentHashMap` to temporarily store the user object before they are verified. 22 | - Each `CodeEntry` tracks when the code was generated and how many times the user has attempted to verify. 23 | 24 | ### 4. Expiry and Rate Limiting 25 | - Each verification code expires after a fixed timeout (e.g., 5 minutes). 26 | - Maximum number of allowed attempts to enter the verification code is limited (e.g., 5 tries). 27 | - If either the timeout is exceeded or the attempt limit is reached, both the verification code and the user data are removed from memory. 28 | 29 | ### 5. Password Hashing 30 | - Passwords are hashed using Java's built-in SHA-256 implementation (`MessageDigest`). 31 | - Hashing happens before storing any data, including in-memory data. 32 | 33 | ### 6. Email Sending 34 | - Sends email using JavaMailSender or HTTP call to another microservice (e.g., .NET-based email service). 35 | - Email body contains the verification code. 36 | 37 | ### 7. Component-Based Design 38 | - The `Manager` class acts as a central service for handling code verification, user insertion, attempt tracking, and memory cleanup. 39 | - It is annotated with `@Component` and used through dependency injection. 40 | - Spring Boot ensures a single shared instance (`singleton`) of this service across all requests. 41 | 42 | ### 8. Integration with Database 43 | - After verification succeeds, the user is saved to the database using a `UserRepository` with `save(user)`. 44 | - This is the only point at which data is persisted to the database, making the flow efficient and clean. 45 | 46 | ## Design Considerations 47 | - The entire logic avoids overloading the database by using memory for transient data. 48 | - Controllers are stateless and do not store data themselves. All logic and memory state are handled by the shared service (`Manager`). 49 | - This approach avoids complications related to entity state, foreign key constraints, and object tracking which are common in frameworks like Entity Framework in .NET. 50 | 51 | ## Code Quality Notes 52 | - Timeout and attempt limit are configurable via constants in the service class. 53 | - Clean separation of responsibilities: code generation, email sending, verification, and user saving are handled separately. 54 | - Exceptions are used to control flow when timeouts or rate limits are hit. 55 | 56 | ## Advantages Over Traditional Persistence 57 | - Avoids storing incomplete or unverified user data. 58 | - Better control over user verification lifecycle. 59 | - More suitable for production systems with heavy signup traffic. 60 | 61 | ## Comparison to .NET (Entity Framework) 62 | - In .NET, database-first designs often require early persistence for entities like `User` before `VerificationCode`, leading to unnecessary records. 63 | - Spring Boot, in this case, avoids that by holding unverified users in memory. 64 | - This design is more efficient in terms of storage and database cleanliness. 65 | 66 | ## Notes 67 | - No user is saved until they are successfully verified. 68 | - Multiple verification attempts and expiration are enforced to prevent abuse. 69 | - The system is designed to scale by adjusting timeout and attempt limits as needed. 70 | -------------------------------------------------------------------------------- /MailServiceJava/mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.2 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" 82 | if ($env:MAVEN_USER_HOME) { 83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" 84 | } 85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 87 | 88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 91 | exit $? 92 | } 93 | 94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 96 | } 97 | 98 | # prepare tmp dir 99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 102 | trap { 103 | if ($TMP_DOWNLOAD_DIR.Exists) { 104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 106 | } 107 | } 108 | 109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 110 | 111 | # Download and Install Apache Maven 112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 113 | Write-Verbose "Downloading from: $distributionUrl" 114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 115 | 116 | $webclient = New-Object System.Net.WebClient 117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 119 | } 120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 122 | 123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 125 | if ($distributionSha256Sum) { 126 | if ($USE_MVND) { 127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 128 | } 129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 132 | } 133 | } 134 | 135 | # unzip and move 136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null 138 | try { 139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 140 | } catch { 141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 142 | Write-Error "fail to move MAVEN_HOME" 143 | } 144 | } finally { 145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 147 | } 148 | 149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 150 | -------------------------------------------------------------------------------- /VerificationSystemJava/mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.2 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" 82 | if ($env:MAVEN_USER_HOME) { 83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" 84 | } 85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 87 | 88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 91 | exit $? 92 | } 93 | 94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 96 | } 97 | 98 | # prepare tmp dir 99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 102 | trap { 103 | if ($TMP_DOWNLOAD_DIR.Exists) { 104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 106 | } 107 | } 108 | 109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 110 | 111 | # Download and Install Apache Maven 112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 113 | Write-Verbose "Downloading from: $distributionUrl" 114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 115 | 116 | $webclient = New-Object System.Net.WebClient 117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 119 | } 120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 122 | 123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 125 | if ($distributionSha256Sum) { 126 | if ($USE_MVND) { 127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 128 | } 129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 132 | } 133 | } 134 | 135 | # unzip and move 136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null 138 | try { 139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 140 | } catch { 141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 142 | Write-Error "fail to move MAVEN_HOME" 143 | } 144 | } finally { 145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 147 | } 148 | 149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 150 | -------------------------------------------------------------------------------- /MailServiceJava/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.3.2 23 | # 24 | # Optional ENV vars 25 | # ----------------- 26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source 27 | # MVNW_REPOURL - repo url base for downloading maven distribution 28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output 30 | # ---------------------------------------------------------------------------- 31 | 32 | set -euf 33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x 34 | 35 | # OS specific support. 36 | native_path() { printf %s\\n "$1"; } 37 | case "$(uname)" in 38 | CYGWIN* | MINGW*) 39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" 40 | native_path() { cygpath --path --windows "$1"; } 41 | ;; 42 | esac 43 | 44 | # set JAVACMD and JAVACCMD 45 | set_java_home() { 46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched 47 | if [ -n "${JAVA_HOME-}" ]; then 48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then 49 | # IBM's JDK on AIX uses strange locations for the executables 50 | JAVACMD="$JAVA_HOME/jre/sh/java" 51 | JAVACCMD="$JAVA_HOME/jre/sh/javac" 52 | else 53 | JAVACMD="$JAVA_HOME/bin/java" 54 | JAVACCMD="$JAVA_HOME/bin/javac" 55 | 56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then 57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 59 | return 1 60 | fi 61 | fi 62 | else 63 | JAVACMD="$( 64 | 'set' +e 65 | 'unset' -f command 2>/dev/null 66 | 'command' -v java 67 | )" || : 68 | JAVACCMD="$( 69 | 'set' +e 70 | 'unset' -f command 2>/dev/null 71 | 'command' -v javac 72 | )" || : 73 | 74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then 75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 76 | return 1 77 | fi 78 | fi 79 | } 80 | 81 | # hash string like Java String::hashCode 82 | hash_string() { 83 | str="${1:-}" h=0 84 | while [ -n "$str" ]; do 85 | char="${str%"${str#?}"}" 86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) 87 | str="${str#?}" 88 | done 89 | printf %x\\n $h 90 | } 91 | 92 | verbose() { :; } 93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } 94 | 95 | die() { 96 | printf %s\\n "$1" >&2 97 | exit 1 98 | } 99 | 100 | trim() { 101 | # MWRAPPER-139: 102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. 103 | # Needed for removing poorly interpreted newline sequences when running in more 104 | # exotic environments such as mingw bash on Windows. 105 | printf "%s" "${1}" | tr -d '[:space:]' 106 | } 107 | 108 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties 109 | while IFS="=" read -r key value; do 110 | case "${key-}" in 111 | distributionUrl) distributionUrl=$(trim "${value-}") ;; 112 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; 113 | esac 114 | done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" 115 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" 116 | 117 | case "${distributionUrl##*/}" in 118 | maven-mvnd-*bin.*) 119 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ 120 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in 121 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; 122 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; 123 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; 124 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;; 125 | *) 126 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 127 | distributionPlatform=linux-amd64 128 | ;; 129 | esac 130 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" 131 | ;; 132 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; 133 | *) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; 134 | esac 135 | 136 | # apply MVNW_REPOURL and calculate MAVEN_HOME 137 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 138 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" 139 | distributionUrlName="${distributionUrl##*/}" 140 | distributionUrlNameMain="${distributionUrlName%.*}" 141 | distributionUrlNameMain="${distributionUrlNameMain%-bin}" 142 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" 143 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" 144 | 145 | exec_maven() { 146 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : 147 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" 148 | } 149 | 150 | if [ -d "$MAVEN_HOME" ]; then 151 | verbose "found existing MAVEN_HOME at $MAVEN_HOME" 152 | exec_maven "$@" 153 | fi 154 | 155 | case "${distributionUrl-}" in 156 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; 157 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; 158 | esac 159 | 160 | # prepare tmp dir 161 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then 162 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } 163 | trap clean HUP INT TERM EXIT 164 | else 165 | die "cannot create temp dir" 166 | fi 167 | 168 | mkdir -p -- "${MAVEN_HOME%/*}" 169 | 170 | # Download and Install Apache Maven 171 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 172 | verbose "Downloading from: $distributionUrl" 173 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 174 | 175 | # select .zip or .tar.gz 176 | if ! command -v unzip >/dev/null; then 177 | distributionUrl="${distributionUrl%.zip}.tar.gz" 178 | distributionUrlName="${distributionUrl##*/}" 179 | fi 180 | 181 | # verbose opt 182 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' 183 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v 184 | 185 | # normalize http auth 186 | case "${MVNW_PASSWORD:+has-password}" in 187 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;; 188 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; 189 | esac 190 | 191 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then 192 | verbose "Found wget ... using wget" 193 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" 194 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then 195 | verbose "Found curl ... using curl" 196 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" 197 | elif set_java_home; then 198 | verbose "Falling back to use Java to download" 199 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" 200 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" 201 | cat >"$javaSource" <<-END 202 | public class Downloader extends java.net.Authenticator 203 | { 204 | protected java.net.PasswordAuthentication getPasswordAuthentication() 205 | { 206 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); 207 | } 208 | public static void main( String[] args ) throws Exception 209 | { 210 | setDefault( new Downloader() ); 211 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 212 | } 213 | } 214 | END 215 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java 216 | verbose " - Compiling Downloader.java ..." 217 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" 218 | verbose " - Running Downloader.java ..." 219 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" 220 | fi 221 | 222 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 223 | if [ -n "${distributionSha256Sum-}" ]; then 224 | distributionSha256Result=false 225 | if [ "$MVN_CMD" = mvnd.sh ]; then 226 | echo "Checksum validation is not supported for maven-mvnd." >&2 227 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 228 | exit 1 229 | elif command -v sha256sum >/dev/null; then 230 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then 231 | distributionSha256Result=true 232 | fi 233 | elif command -v shasum >/dev/null; then 234 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then 235 | distributionSha256Result=true 236 | fi 237 | else 238 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 239 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 240 | exit 1 241 | fi 242 | if [ $distributionSha256Result = false ]; then 243 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 244 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 245 | exit 1 246 | fi 247 | fi 248 | 249 | # unzip and move 250 | if command -v unzip >/dev/null; then 251 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" 252 | else 253 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" 254 | fi 255 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" 256 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" 257 | 258 | clean || : 259 | exec_maven "$@" 260 | -------------------------------------------------------------------------------- /VerificationSystemJava/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.3.2 23 | # 24 | # Optional ENV vars 25 | # ----------------- 26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source 27 | # MVNW_REPOURL - repo url base for downloading maven distribution 28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output 30 | # ---------------------------------------------------------------------------- 31 | 32 | set -euf 33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x 34 | 35 | # OS specific support. 36 | native_path() { printf %s\\n "$1"; } 37 | case "$(uname)" in 38 | CYGWIN* | MINGW*) 39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" 40 | native_path() { cygpath --path --windows "$1"; } 41 | ;; 42 | esac 43 | 44 | # set JAVACMD and JAVACCMD 45 | set_java_home() { 46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched 47 | if [ -n "${JAVA_HOME-}" ]; then 48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then 49 | # IBM's JDK on AIX uses strange locations for the executables 50 | JAVACMD="$JAVA_HOME/jre/sh/java" 51 | JAVACCMD="$JAVA_HOME/jre/sh/javac" 52 | else 53 | JAVACMD="$JAVA_HOME/bin/java" 54 | JAVACCMD="$JAVA_HOME/bin/javac" 55 | 56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then 57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 59 | return 1 60 | fi 61 | fi 62 | else 63 | JAVACMD="$( 64 | 'set' +e 65 | 'unset' -f command 2>/dev/null 66 | 'command' -v java 67 | )" || : 68 | JAVACCMD="$( 69 | 'set' +e 70 | 'unset' -f command 2>/dev/null 71 | 'command' -v javac 72 | )" || : 73 | 74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then 75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 76 | return 1 77 | fi 78 | fi 79 | } 80 | 81 | # hash string like Java String::hashCode 82 | hash_string() { 83 | str="${1:-}" h=0 84 | while [ -n "$str" ]; do 85 | char="${str%"${str#?}"}" 86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) 87 | str="${str#?}" 88 | done 89 | printf %x\\n $h 90 | } 91 | 92 | verbose() { :; } 93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } 94 | 95 | die() { 96 | printf %s\\n "$1" >&2 97 | exit 1 98 | } 99 | 100 | trim() { 101 | # MWRAPPER-139: 102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. 103 | # Needed for removing poorly interpreted newline sequences when running in more 104 | # exotic environments such as mingw bash on Windows. 105 | printf "%s" "${1}" | tr -d '[:space:]' 106 | } 107 | 108 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties 109 | while IFS="=" read -r key value; do 110 | case "${key-}" in 111 | distributionUrl) distributionUrl=$(trim "${value-}") ;; 112 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; 113 | esac 114 | done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" 115 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" 116 | 117 | case "${distributionUrl##*/}" in 118 | maven-mvnd-*bin.*) 119 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ 120 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in 121 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; 122 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; 123 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; 124 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;; 125 | *) 126 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 127 | distributionPlatform=linux-amd64 128 | ;; 129 | esac 130 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" 131 | ;; 132 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; 133 | *) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; 134 | esac 135 | 136 | # apply MVNW_REPOURL and calculate MAVEN_HOME 137 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 138 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" 139 | distributionUrlName="${distributionUrl##*/}" 140 | distributionUrlNameMain="${distributionUrlName%.*}" 141 | distributionUrlNameMain="${distributionUrlNameMain%-bin}" 142 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" 143 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" 144 | 145 | exec_maven() { 146 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : 147 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" 148 | } 149 | 150 | if [ -d "$MAVEN_HOME" ]; then 151 | verbose "found existing MAVEN_HOME at $MAVEN_HOME" 152 | exec_maven "$@" 153 | fi 154 | 155 | case "${distributionUrl-}" in 156 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; 157 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; 158 | esac 159 | 160 | # prepare tmp dir 161 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then 162 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } 163 | trap clean HUP INT TERM EXIT 164 | else 165 | die "cannot create temp dir" 166 | fi 167 | 168 | mkdir -p -- "${MAVEN_HOME%/*}" 169 | 170 | # Download and Install Apache Maven 171 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 172 | verbose "Downloading from: $distributionUrl" 173 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 174 | 175 | # select .zip or .tar.gz 176 | if ! command -v unzip >/dev/null; then 177 | distributionUrl="${distributionUrl%.zip}.tar.gz" 178 | distributionUrlName="${distributionUrl##*/}" 179 | fi 180 | 181 | # verbose opt 182 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' 183 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v 184 | 185 | # normalize http auth 186 | case "${MVNW_PASSWORD:+has-password}" in 187 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;; 188 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; 189 | esac 190 | 191 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then 192 | verbose "Found wget ... using wget" 193 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" 194 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then 195 | verbose "Found curl ... using curl" 196 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" 197 | elif set_java_home; then 198 | verbose "Falling back to use Java to download" 199 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" 200 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" 201 | cat >"$javaSource" <<-END 202 | public class Downloader extends java.net.Authenticator 203 | { 204 | protected java.net.PasswordAuthentication getPasswordAuthentication() 205 | { 206 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); 207 | } 208 | public static void main( String[] args ) throws Exception 209 | { 210 | setDefault( new Downloader() ); 211 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 212 | } 213 | } 214 | END 215 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java 216 | verbose " - Compiling Downloader.java ..." 217 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" 218 | verbose " - Running Downloader.java ..." 219 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" 220 | fi 221 | 222 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 223 | if [ -n "${distributionSha256Sum-}" ]; then 224 | distributionSha256Result=false 225 | if [ "$MVN_CMD" = mvnd.sh ]; then 226 | echo "Checksum validation is not supported for maven-mvnd." >&2 227 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 228 | exit 1 229 | elif command -v sha256sum >/dev/null; then 230 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then 231 | distributionSha256Result=true 232 | fi 233 | elif command -v shasum >/dev/null; then 234 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then 235 | distributionSha256Result=true 236 | fi 237 | else 238 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 239 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 240 | exit 1 241 | fi 242 | if [ $distributionSha256Result = false ]; then 243 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 244 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 245 | exit 1 246 | fi 247 | fi 248 | 249 | # unzip and move 250 | if command -v unzip >/dev/null; then 251 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" 252 | else 253 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" 254 | fi 255 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" 256 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" 257 | 258 | clean || : 259 | exec_maven "$@" 260 | --------------------------------------------------------------------------------