Skip to content

Commit e450ff0

Browse files
author
noobandy
committed
ACL
1 parent 0b669b0 commit e450ff0

File tree

7 files changed

+280
-0
lines changed

7 files changed

+280
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
*
3+
*/
4+
package in.anandm.apps.template.application.impl;
5+
6+
import in.anandm.apps.template.domain.model.permission.IPermissionRepository;
7+
import in.anandm.apps.template.domain.model.permission.ModulePermissionConstants;
8+
import in.anandm.apps.template.domain.model.permission.Permission;
9+
import in.anandm.apps.template.domain.service.IPermissionService;
10+
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.stereotype.Service;
13+
import org.springframework.transaction.annotation.Transactional;
14+
15+
/**
16+
* @author anandm
17+
*
18+
*/
19+
@Service
20+
public class PermissionService implements IPermissionService {
21+
22+
private IPermissionRepository permissionRepository;
23+
24+
25+
26+
/**
27+
* @param permissionRepository
28+
*/
29+
@Autowired
30+
public PermissionService(IPermissionRepository permissionRepository) {
31+
super();
32+
this.permissionRepository = permissionRepository;
33+
}
34+
35+
36+
@Transactional
37+
@Override
38+
public void generatePermissions() {
39+
40+
for (ModulePermissionConstants modulePermissionConstants : ModulePermissionConstants.values()) {
41+
String moduleName = modulePermissionConstants.getModule();
42+
String permissionName = modulePermissionConstants.getPermission();
43+
44+
Permission permission = permissionRepository.getPermission(moduleName, permissionName);
45+
46+
if(permission == null){
47+
permissionRepository.savePermission(modulePermissionConstants.asPermission());
48+
}
49+
50+
}
51+
}
52+
53+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
*
3+
*/
4+
package in.anandm.apps.template.domain.model.user;
5+
6+
/**
7+
* @author anandm
8+
*
9+
*/
10+
public interface ILoginAttemptRepository {
11+
12+
void saveLoginAttempt(LoginAttempt loginAttempt);
13+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
*
3+
*/
4+
package in.anandm.apps.template.domain.model.user;
5+
6+
import in.anandm.apps.template.domain.shared.entity.BaseEntity;
7+
8+
import javax.persistence.Entity;
9+
import javax.persistence.ManyToOne;
10+
11+
/**
12+
* @author anandm
13+
*
14+
*/
15+
@Entity
16+
public class LoginAttempt extends BaseEntity{
17+
18+
/**
19+
*
20+
*/
21+
private static final long serialVersionUID = 1L;
22+
23+
@ManyToOne
24+
private User user;
25+
26+
private HostAddress hostAddress;
27+
private Long attemptedOn;
28+
private boolean success;
29+
30+
/**
31+
* @param user
32+
* @param hostAddress
33+
* @param attemptedOn
34+
* @param success
35+
*/
36+
public LoginAttempt(User user, HostAddress hostAddress, Long attemptedOn,
37+
boolean success) {
38+
super();
39+
this.user = user;
40+
this.hostAddress = hostAddress;
41+
this.attemptedOn = attemptedOn;
42+
this.success = success;
43+
}
44+
45+
public HostAddress getHostAddress() {
46+
return hostAddress;
47+
}
48+
49+
public Long getAttemptedOn() {
50+
return attemptedOn;
51+
}
52+
53+
public boolean isSuccess() {
54+
return success;
55+
}
56+
57+
public User getUser() {
58+
return user;
59+
}
60+
61+
/**
62+
*
63+
*/
64+
LoginAttempt() {
65+
super();
66+
67+
}
68+
69+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
*
3+
*/
4+
package in.anandm.apps.template.domain.service;
5+
6+
/**
7+
* @author anandm
8+
*
9+
*/
10+
public interface IPermissionService {
11+
12+
void generatePermissions();
13+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
*
3+
*/
4+
package in.anandm.apps.template.domain.shared.entity;
5+
6+
import java.io.Serializable;
7+
8+
import javax.persistence.GeneratedValue;
9+
import javax.persistence.GenerationType;
10+
import javax.persistence.Id;
11+
import javax.persistence.Inheritance;
12+
import javax.persistence.InheritanceType;
13+
import javax.persistence.MappedSuperclass;
14+
15+
/**
16+
* @author anandm
17+
*
18+
*/
19+
@MappedSuperclass
20+
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
21+
public abstract class BaseEntity implements Serializable {
22+
23+
/**
24+
*
25+
*/
26+
private static final long serialVersionUID = 1L;
27+
28+
@Id
29+
@GeneratedValue(strategy=GenerationType.AUTO)
30+
private Long id;
31+
32+
/**
33+
*
34+
*/
35+
public BaseEntity() {
36+
super();
37+
38+
}
39+
40+
public Long getId() {
41+
return id;
42+
}
43+
44+
public void setId(Long id) {
45+
this.id = id;
46+
}
47+
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
*
3+
*/
4+
package in.anandm.apps.template.infrastructure.persistence.jpa;
5+
6+
import in.anandm.apps.template.domain.model.user.ILoginAttemptRepository;
7+
import in.anandm.apps.template.domain.model.user.LoginAttempt;
8+
9+
import org.springframework.stereotype.Repository;
10+
11+
/**
12+
* @author anandm
13+
*
14+
*/
15+
@Repository
16+
public class LoginAttemptRepository extends BaseRepository<LoginAttempt, Long> implements ILoginAttemptRepository {
17+
18+
public void saveLoginAttempt(LoginAttempt loginAttempt){
19+
save(loginAttempt);
20+
}
21+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
*
3+
*/
4+
package in.anandm.apps.template.infrastructure.persistence.jpa;
5+
6+
import in.anandm.apps.template.domain.model.permission.IPermissionRepository;
7+
import in.anandm.apps.template.domain.model.permission.Permission;
8+
import in.anandm.apps.template.interfaces.web.facade.dto.DataTable;
9+
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
import org.springframework.stereotype.Repository;
14+
15+
import com.googlecode.genericdao.search.Filter;
16+
import com.googlecode.genericdao.search.Search;
17+
18+
/**
19+
* @author anandm
20+
*
21+
*/
22+
@Repository
23+
public class PermissionRepository extends BaseRepository<Permission, Long> implements
24+
IPermissionRepository {
25+
26+
27+
public void savePermission(Permission permission){
28+
29+
save(permission);
30+
}
31+
32+
@Override
33+
public List<Permission> getPermissionsOfModule(String moduleName) {
34+
35+
Search search = new Search(Permission.class);
36+
search.addFilter(Filter.equal("moduleName", moduleName));
37+
search.setResultMode(Search.RESULT_LIST);
38+
39+
return search(search);
40+
}
41+
42+
@Override
43+
public Permission getPermission(String moduleName, String permission) {
44+
45+
Search search = new Search(Permission.class);
46+
Filter moduleNameFilter = Filter.equal("moduleName", moduleName);
47+
Filter permissionNameFilter = Filter.equal("permissionName", permission);
48+
Filter permissionFilter = Filter.and(moduleNameFilter,permissionNameFilter);
49+
search.addFilter(permissionFilter);
50+
51+
search.setResultMode(Search.RESULT_SINGLE);
52+
53+
return searchUnique(search);
54+
}
55+
56+
@Override
57+
public DataTable<Permission> getDataTable(Map<String, String> params) {
58+
59+
return getDataTable(params);
60+
}
61+
62+
63+
}

0 commit comments

Comments
 (0)