Skip to content

Commit a4af49d

Browse files
authored
Merge branch 'master' into core-java-move-1
2 parents 3207ee0 + da781bf commit a4af49d

444 files changed

Lines changed: 1959 additions & 669 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

algorithms-sorting/src/main/java/com/baeldung/algorithms/radixsort/RadixSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private static void applyCountingSortOn(int[] numbers, int placeValue) {
2929
frequency[digit]++;
3030
}
3131

32-
for (int i = 1; i < 10; i++) {
32+
for (int i = 1; i < range; i++) {
3333
frequency[i] += frequency[i - 1];
3434
}
3535

algorithms-sorting/src/test/java/com/baeldung/algorithms/radixsort/RadixSortUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class RadixSortUnitTest {
88

99
@Test
10-
public void givenUnsortedArrayWhenRadixSortThenArraySorted() {
10+
public void givenUnsortedArray_whenRadixSort_thenArraySorted() {
1111
int[] numbers = { 387, 468, 134, 123, 68, 221, 769, 37, 7 };
1212
RadixSort.sort(numbers);
1313
int[] numbersSorted = { 7, 37, 68, 123, 134, 221, 387, 468, 769 };

apache-shiro/pom.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,11 @@
3838
<artifactId>jcl-over-slf4j</artifactId>
3939
<scope>runtime</scope>
4040
</dependency>
41-
<dependency>
42-
<groupId>org.slf4j</groupId>
43-
<artifactId>slf4j-log4j12</artifactId>
44-
<scope>runtime</scope>
45-
</dependency>
46-
<dependency>
47-
<groupId>log4j</groupId>
48-
<artifactId>log4j</artifactId>
49-
<version>${log4j-version}</version>
50-
<scope>runtime</scope>
51-
</dependency>
5241
</dependencies>
5342

5443
<properties>
5544
<apache-shiro-core-version>1.4.0</apache-shiro-core-version>
5645
<log4j-version>1.2.17</log4j-version>
5746
</properties>
5847

59-
</project>
48+
</project>

apache-shiro/src/main/java/com/baeldung/controllers/ShiroSpringController.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@
1818
@Controller
1919
public class ShiroSpringController {
2020

21-
22-
2321
@GetMapping("/")
2422
public String index() {
2523
return "index";
2624
}
2725

28-
2926
@RequestMapping( value = "/login", method = {RequestMethod.GET, RequestMethod.POST})
3027
public String login(HttpServletRequest req, UserCredentials cred, RedirectAttributes attr) {
3128

3229
if(req.getMethod().equals(RequestMethod.GET.toString())) {
3330
return "login";
34-
}
35-
else {
36-
31+
} else {
3732
Subject subject = SecurityUtils.getSubject();
3833

3934
if(!subject.isAuthenticated()) {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.baeldung.shiro.permissions.custom;
2+
3+
import com.baeldung.MyCustomRealm;
4+
import org.apache.shiro.SecurityUtils;
5+
import org.apache.shiro.authc.*;
6+
import org.apache.shiro.config.Ini;
7+
import org.apache.shiro.mgt.DefaultSecurityManager;
8+
import org.apache.shiro.mgt.SecurityManager;
9+
import org.apache.shiro.realm.Realm;
10+
import org.apache.shiro.realm.text.IniRealm;
11+
import org.apache.shiro.session.Session;
12+
import org.apache.shiro.subject.Subject;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
16+
public class Main {
17+
18+
private static final transient Logger log = LoggerFactory.getLogger(Main.class);
19+
20+
public static void main(String[] args) {
21+
22+
IniRealm realm = new IniRealm();
23+
Ini ini = Ini.fromResourcePath(Main.class.getResource("/com/baeldung/shiro/permissions/custom/shiro.ini").getPath());
24+
realm.setIni(ini);
25+
realm.setPermissionResolver(new PathPermissionResolver());
26+
realm.init();
27+
SecurityManager securityManager = new DefaultSecurityManager(realm);
28+
29+
SecurityUtils.setSecurityManager(securityManager);
30+
Subject currentUser = SecurityUtils.getSubject();
31+
32+
if (!currentUser.isAuthenticated()) {
33+
UsernamePasswordToken token = new UsernamePasswordToken("paul.reader", "password4");
34+
token.setRememberMe(true);
35+
try {
36+
currentUser.login(token);
37+
} catch (UnknownAccountException uae) {
38+
log.error("Username Not Found!", uae);
39+
} catch (IncorrectCredentialsException ice) {
40+
log.error("Invalid Credentials!", ice);
41+
} catch (LockedAccountException lae) {
42+
log.error("Your Account is Locked!", lae);
43+
} catch (AuthenticationException ae) {
44+
log.error("Unexpected Error!", ae);
45+
}
46+
}
47+
48+
log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");
49+
50+
if (currentUser.hasRole("admin")) {
51+
log.info("Welcome Admin");
52+
} else if(currentUser.hasRole("editor")) {
53+
log.info("Welcome, Editor!");
54+
} else if(currentUser.hasRole("author")) {
55+
log.info("Welcome, Author");
56+
} else {
57+
log.info("Welcome, Guest");
58+
}
59+
60+
if(currentUser.isPermitted("/articles/drafts/new-article")) {
61+
log.info("You can access articles");
62+
} else {
63+
log.info("You cannot access articles!");
64+
}
65+
currentUser.logout();
66+
}
67+
68+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.shiro.permissions.custom;
2+
3+
import org.apache.shiro.authz.Permission;
4+
5+
import java.nio.file.Path;
6+
7+
public class PathPermission implements Permission {
8+
9+
private final Path path;
10+
11+
public PathPermission(Path path) {
12+
this.path = path;
13+
}
14+
15+
@Override
16+
public boolean implies(Permission p) {
17+
if(p instanceof PathPermission) {
18+
return ((PathPermission) p).path.startsWith(path);
19+
}
20+
return false;
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.shiro.permissions.custom;
2+
3+
import org.apache.shiro.authz.Permission;
4+
import org.apache.shiro.authz.permission.PermissionResolver;
5+
6+
import java.nio.file.Paths;
7+
8+
public class PathPermissionResolver implements PermissionResolver {
9+
@Override
10+
public Permission resolvePermission(String permissionString) {
11+
return new PathPermission(Paths.get(permissionString));
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[users]
2+
jane.admin = password, admin
3+
john.editor = password2, editor
4+
zoe.author = password3, author
5+
paul.reader = password4
6+
7+
[roles]
8+
admin = /
9+
editor = /articles
10+
author = /articles/drafts

core-java-modules/core-java-collections-list-2/src/test/java/com/baeldung/java/listInitialization/ListInitializationUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void givenArraysAsList_whenAdd_thenUnsupportedException() {
4242
}
4343

4444
@Test
45-
public void givenArrayAsList_whenCreated_thenShareReference() {
45+
public void givenArraysAsList_whenCreated_thenShareReference() {
4646
String[] array = { "foo", "bar" };
4747
List<String> list = Arrays.asList(array);
4848
array[0] = "baz";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*.class
2+
3+
0.*
4+
5+
#folders#
6+
/target
7+
/neoDb*
8+
/data
9+
/src/main/webapp/WEB-INF/classes
10+
*/META-INF/*
11+
.resourceCache
12+
13+
# Packaged files #
14+
*.jar
15+
*.war
16+
*.ear
17+
18+
# Files generated by integration tests
19+
*.txt
20+
backup-pom.xml
21+
/bin/
22+
/temp
23+
24+
#IntelliJ specific
25+
.idea/
26+
*.iml

0 commit comments

Comments
 (0)