-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from yanyanho/main
add aspect for authority
- Loading branch information
Showing
13 changed files
with
120 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dl/officialsite/common/exception/UnauthorizedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dl.officialsite.common.exception; | ||
|
||
public class UnauthorizedException extends Throwable { | ||
|
||
private String msg; | ||
public UnauthorizedException(String unauthorizedAccess) { | ||
this.msg = unauthorizedAccess; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.dl.officialsite.login; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Auth { | ||
String value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.dl.officialsite.login; | ||
|
||
import com.dl.officialsite.common.exception.UnauthorizedException; | ||
import com.dl.officialsite.common.utils.UserSecurityUtils; | ||
import com.dl.officialsite.login.model.UserPrincipleData; | ||
import com.dl.officialsite.member.MemberController; | ||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
@Aspect | ||
public class AuthAspect { | ||
// @Autowired | ||
// private UserSecurityUtils authService; | ||
|
||
@Pointcut("@annotation(com.dl.officialsite.login.Auth)") | ||
public void authPointcut() {} | ||
|
||
public static final Logger logger = LoggerFactory.getLogger(MemberController.class); | ||
|
||
@Before("authPointcut() && @annotation(auth)") | ||
public void authBefore(JoinPoint joinPoint, Auth auth) throws UnauthorizedException { | ||
String permission = auth.value(); | ||
UserPrincipleData userPrincipleData = UserSecurityUtils.getUserLogin(); | ||
logger.info("userPrincipleData address "+ userPrincipleData.getAddress()); | ||
logger.info("userPrincipleData team "+ userPrincipleData.getTeams()); | ||
if(permission.equals("admin")) { | ||
|
||
List team = userPrincipleData.getTeams().stream().filter(x-> x.getTeamId()==1).collect(Collectors.toList()); | ||
if(team == null || team.size()==0){ | ||
throw new UnauthorizedException("Unauthorized access"); | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
@Getter | ||
public enum UserRoleEnum { | ||
|
||
SUPERADMIN(2), | ||
|
||
ADMIN(1), | ||
|
||
NORMAL(0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters