Skip to content

Commit c3dfa07

Browse files
Nakebenihimemario.dacosta
authored and
mario.dacosta
committed
# SPRINGBOOT SECURITY WITH HTTPBASIC WITH DATABASE AUTHENTICATION OR IN-MEMORY AUTHENTICATION
0 parents  commit c3dfa07

29 files changed

+1355
-0
lines changed

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
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+
30+
### VS Code ###
31+
.vscode/
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.util.Properties;
18+
19+
public class MavenWrapperDownloader {
20+
21+
private static final String WRAPPER_VERSION = "0.5.6";
22+
/**
23+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
24+
*/
25+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
26+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
27+
28+
/**
29+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
30+
* use instead of the default one.
31+
*/
32+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
33+
".mvn/wrapper/maven-wrapper.properties";
34+
35+
/**
36+
* Path where the maven-wrapper.jar will be saved to.
37+
*/
38+
private static final String MAVEN_WRAPPER_JAR_PATH =
39+
".mvn/wrapper/maven-wrapper.jar";
40+
41+
/**
42+
* Name of the property which should be used to override the default download url for the wrapper.
43+
*/
44+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
45+
46+
public static void main(String args[]) {
47+
System.out.println("- Downloader started");
48+
File baseDirectory = new File(args[0]);
49+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
50+
51+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
52+
// wrapperUrl parameter.
53+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
54+
String url = DEFAULT_DOWNLOAD_URL;
55+
if (mavenWrapperPropertyFile.exists()) {
56+
FileInputStream mavenWrapperPropertyFileInputStream = null;
57+
try {
58+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
59+
Properties mavenWrapperProperties = new Properties();
60+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
61+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
62+
} catch (IOException e) {
63+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
64+
} finally {
65+
try {
66+
if (mavenWrapperPropertyFileInputStream != null) {
67+
mavenWrapperPropertyFileInputStream.close();
68+
}
69+
} catch (IOException e) {
70+
// Ignore ...
71+
}
72+
}
73+
}
74+
System.out.println("- Downloading from: " + url);
75+
76+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
77+
if (!outputFile.getParentFile().exists()) {
78+
if (!outputFile.getParentFile().mkdirs()) {
79+
System.out.println(
80+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
81+
}
82+
}
83+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
84+
try {
85+
downloadFileFromURL(url, outputFile);
86+
System.out.println("Done");
87+
System.exit(0);
88+
} catch (Throwable e) {
89+
System.out.println("- Error downloading");
90+
e.printStackTrace();
91+
System.exit(1);
92+
}
93+
}
94+
95+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
96+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
97+
String username = System.getenv("MVNW_USERNAME");
98+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
99+
Authenticator.setDefault(new Authenticator() {
100+
@Override
101+
protected PasswordAuthentication getPasswordAuthentication() {
102+
return new PasswordAuthentication(username, password);
103+
}
104+
});
105+
}
106+
URL website = new URL(urlString);
107+
ReadableByteChannel rbc;
108+
rbc = Channels.newChannel(website.openStream());
109+
FileOutputStream fos = new FileOutputStream(destination);
110+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
111+
fos.close();
112+
rbc.close();
113+
}
114+
115+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.

.mvn/wrapper/maven-wrapper.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

0 commit comments

Comments
 (0)