Skip to content

Commit 1e38046

Browse files
committed
Unresolved security bugs.
1 parent a8959dd commit 1e38046

File tree

11 files changed

+109
-56
lines changed

11 files changed

+109
-56
lines changed
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Wed Jun 20 18:50:19 SAST 2018
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip

src/main/java/io/home/pi/domain/Authority.java src/main/java/io/home/pi/domain/Auth.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@
1515
@Setter
1616
@Getter
1717
@Entity
18-
@Table(schema = "rpi", name = "authority")
19-
public class Authority {
18+
@Table(schema = "rpi", name = "auth")
19+
public class Auth {
2020
@Id
2121
@GeneratedValue(strategy = GenerationType.IDENTITY)
2222
@Column(name = "id")
2323
private Integer id;
24-
@Enumerated(EnumType.STRING)
25-
@Column(name = "level")
26-
private Enum level;
24+
25+
// @Enumerated(EnumType.STRING)
26+
@Column(name = "level", nullable = false, length = 50)
27+
private String level;
28+
29+
@ManyToOne(fetch = FetchType.EAGER)
30+
@JoinColumn(name = "id", insertable = false, updatable = false)
31+
private GrpAuth grpAuth;
2732

2833
@Override
2934
public String toString() {
30-
return "Authority{" +
35+
return "Auth{" +
3136
"id=" + id +
3237
", level='" + level + '\'' +
3338
'}';

src/main/java/io/home/pi/domain/Grp.java

100755100644
+9-16
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import lombok.Setter;
55

66
import javax.persistence.*;
7-
import java.util.Set;
87

98
/**
10-
* PROJECT :pi
11-
* PACKAGE :io.home.pi.domain
12-
* USER :Sean
13-
* DATE :2018/06/14
14-
* TIME :21:40
9+
* PROJECT : pi
10+
* PACKAGE : io.home.pi.domain
11+
* USER : sean
12+
* DATE : 25-June-2018
13+
* TIME : 20:38
1514
*/
1615
@Setter
1716
@Getter
@@ -22,22 +21,16 @@ public class Grp {
2221
@GeneratedValue(strategy = GenerationType.IDENTITY)
2322
@Column(name = "id")
2423
private Integer id;
25-
@Column(name = "name")
26-
private String name;
27-
28-
@OneToMany(cascade = CascadeType.ALL, targetEntity = User.class, fetch = FetchType.LAZY)
29-
private Set<User> users;
3024

31-
@OneToOne(cascade = CascadeType.ALL)
32-
private GrpAuthority grpAuthority;
25+
// @Enumerated(EnumType.STRING)
26+
@Column(name = "name", nullable = false, length = 50)
27+
private String name;
3328

3429
@Override
3530
public String toString() {
3631
return "Grp{" +
3732
"id=" + id +
38-
", name='" + name + '\'' +
39-
", users=" + users +
40-
", grpAuthority=" + grpAuthority +
33+
", name=" + name +
4134
'}';
4235
}
4336
}

src/main/java/io/home/pi/domain/GrpAuthority.java src/main/java/io/home/pi/domain/GrpAuth.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,22 @@
1616
@Setter
1717
@Getter
1818
@Entity
19-
@Table(schema = "rpi", name = "grp_authority")
20-
public class GrpAuthority {
19+
@Table(schema = "rpi", name = "g_auth")
20+
public class GrpAuth {
2121
@Id
2222
@GeneratedValue(strategy = GenerationType.IDENTITY)
2323
@Column(name = "id")
2424
private Integer id;
2525

26-
@OneToOne(cascade = CascadeType.ALL)
27-
private Grp grp;
28-
2926
// @OneToMany(cascade = CascadeType.ALL, mappedBy = "grp_authority")
30-
@OneToMany(cascade = CascadeType.ALL)
31-
private Set<Authority> authorities;
27+
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = Auth.class)
28+
@JoinColumn(name = "id")
29+
private Set<Auth> authorities;
3230

3331
@Override
3432
public String toString() {
35-
return "GrpAuthority{" +
33+
return "GrpAuth{" +
3634
"id=" + id +
37-
", grp=" + grp +
3835
", authorities=" + authorities +
3936
'}';
4037
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.home.pi.domain;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import javax.persistence.*;
7+
import java.util.Set;
8+
9+
/**
10+
* PROJECT :pi
11+
* PACKAGE :io.home.pi.domain
12+
* USER :Sean
13+
* DATE :2018/06/14
14+
* TIME :21:40
15+
*/
16+
@Setter
17+
@Getter
18+
@Entity
19+
@Table(schema = "rpi", name = "team")
20+
public class Team {
21+
@Id
22+
@GeneratedValue(strategy = GenerationType.IDENTITY)
23+
@Column(name = "id")
24+
private Integer id;
25+
26+
@OneToOne(cascade = CascadeType.DETACH)
27+
private Grp grp;
28+
29+
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
30+
private GrpAuth grpAuth;
31+
32+
@OneToMany(cascade = CascadeType.ALL, targetEntity = User.class, fetch = FetchType.LAZY)
33+
private Set<User> users;
34+
35+
@Override
36+
public String toString() {
37+
return "Team{" +
38+
"id=" + id +
39+
", grp=" + grp +
40+
", grpAuth=" + grpAuth +
41+
'}';
42+
}
43+
}

src/main/java/io/home/pi/domain/User.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import lombok.Setter;
55

66
import javax.persistence.*;
7-
import java.util.Set;
87

98
/**
109
* PROJECT :pi
@@ -33,8 +32,8 @@ public class User {
3332
@Transient
3433
private String token;
3534

36-
@ManyToOne(targetEntity = Grp.class, fetch = FetchType.LAZY)
37-
private Set<Grp> grps;
35+
@ManyToOne(targetEntity = Team.class, fetch = FetchType.EAGER)
36+
private Team team;
3837

3938
@Override
4039
public String toString() {
@@ -44,7 +43,7 @@ public String toString() {
4443
", password='" + password + '\'' +
4544
", enabled=" + enabled +
4645
", token='" + token + '\'' +
47-
", grp=" + grps +
46+
", teams=" + team +
4847
'}';
4948
}
5049
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.home.pi.repo;
22

3-
import io.home.pi.domain.Authority;
3+
import io.home.pi.domain.Auth;
44
import org.springframework.data.repository.CrudRepository;
55

66
/**
@@ -10,6 +10,6 @@
1010
* DATE : 19-June-2018
1111
* TIME : 23:38
1212
*/
13-
public interface AuthorityRepo extends CrudRepository<Authority, Integer> {
13+
public interface AuthorityRepo extends CrudRepository<Auth, Integer> {
1414

1515
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.home.pi.repo;
22

3-
import io.home.pi.domain.GrpAuthority;
3+
import io.home.pi.domain.GrpAuth;
44
import org.springframework.data.repository.CrudRepository;
55

66
/**
@@ -10,6 +10,6 @@
1010
* DATE : 19-June-2018
1111
* TIME : 23:24
1212
*/
13-
public interface GroupAuthorityRepo extends CrudRepository<GrpAuthority, Integer> {
13+
public interface GroupAuthorityRepo extends CrudRepository<GrpAuth, Integer> {
1414

1515
}

src/main/java/io/home/pi/repo/GroupRepo.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.home.pi.repo;
22

3-
import io.home.pi.domain.Grp;
3+
import io.home.pi.domain.Team;
44
import org.springframework.data.repository.CrudRepository;
55
import org.springframework.stereotype.Repository;
66

@@ -12,6 +12,6 @@
1212
* TIME : 20:16
1313
*/
1414
@Repository
15-
public interface GroupRepo extends CrudRepository<Grp, Integer> {
15+
public interface GroupRepo extends CrudRepository<Team, Integer> {
1616

1717
}

src/main/java/io/home/pi/service/impl/LoginServiceImpl.java

+11-13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import com.fasterxml.jackson.core.type.TypeReference;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import io.home.pi.domain.Grp;
6-
import io.home.pi.domain.GrpAuthority;
5+
import io.home.pi.domain.GrpAuth;
76
import io.home.pi.domain.User;
87
import io.home.pi.service.UserService;
98
import org.slf4j.Logger;
@@ -67,15 +66,14 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
6766
private List<GrantedAuthority> getGrantedAuthorities(User user) {
6867
List<GrantedAuthority> authorities = new ArrayList<>();
6968
try {
70-
List<GrpAuthority> groupAuthorities = new ArrayList<>();
69+
List<GrpAuth> groupAuthorities = new ArrayList<>();
70+
71+
groupAuthorities.add(user.getTeam().getGrpAuth());
7172

72-
for (Grp grp : user.getGrps()) {
73-
groupAuthorities.add(grp.getGrpAuthority());
74-
}
7573

76-
for (GrpAuthority userAuth : decodeHashMap(groupAuthorities)) {
77-
LOGGER.info("User Authority: " + userAuth.toString());
78-
authorities.add(new SimpleGrantedAuthority(USER_ROLE_PREFIX + userAuth.getAuthorities()));
74+
for (GrpAuth userAuth : groupAuthorities) {
75+
LOGGER.info("User Auth: " + userAuth.toString());
76+
authorities.add(new SimpleGrantedAuthority(USER_ROLE_PREFIX + userAuth.getAuthorities().iterator().next().getLevel()));
7977
}
8078
} catch (Exception e) {
8179
LOGGER.error(e.getMessage(), e);
@@ -90,13 +88,13 @@ private List<GrantedAuthority> getGrantedAuthorities(User user) {
9088
}
9189

9290

93-
private List<GrpAuthority> decodeHashMap(List<GrpAuthority> authorities) {
94-
List<GrpAuthority> authoritiesArrayList = new ArrayList<>();
91+
private List<GrpAuth> decodeHashMap(List<GrpAuth> authorities) {
92+
List<GrpAuth> authoritiesArrayList = new ArrayList<>();
9593
ObjectMapper mapper = new ObjectMapper();
9694

9795
try {
98-
List<GrpAuthority> groupAuthorities = mapper.convertValue(authorities,
99-
new TypeReference<List<GrpAuthority>>() {
96+
List<GrpAuth> groupAuthorities = mapper.convertValue(authorities,
97+
new TypeReference<List<GrpAuth>>() {
10098
});
10199

102100
authoritiesArrayList.addAll(groupAuthorities);

src/main/resources/data.sql

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
insert into rpi.g_auth (id) values (1);
2+
insert into rpi.g_auth (id) values (2);
3+
insert into rpi.g_auth (id) values (3);
4+
insert into rpi.g_auth (id) values (4);
5+
6+
insert into rpi.auth (id, level) values (1, 'USER');
7+
insert into rpi.auth (id, level) values (2, 'ADMIN');
8+
insert into rpi.auth (id, level) values (3, 'SUPER');
9+
insert into rpi.auth (id, level) values (4, 'ANONYMOUS');
10+
11+
insert into rpi.grp (name) values ('GREEN');
12+
insert into rpi.grp (name) values ('ORANGE');
13+
insert into rpi.grp (name) values ('RED');
14+
insert into rpi.grp (name) values ('YELLOW');
15+
16+
insert into rpi.team (grp_id, grp_auth_id) values (1, 1);
17+
18+
insert into rpi.user (username, password, enabled, team_id)
19+
values ('demo@email.com', 'ebde6e599feaa84afdf86ab799964e60', true, 1)

0 commit comments

Comments
 (0)