forked from longfeizheng/security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
198 additions
and
47 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
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
17 changes: 17 additions & 0 deletions
17
...security-core/src/main/java/com/imooc/security/core/authorize/AuthorizeConfigManager.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,17 @@ | ||
/** | ||
* | ||
*/ | ||
package com.imooc.security.core.authorize; | ||
|
||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | ||
|
||
/** | ||
* @author zhailiang | ||
* | ||
*/ | ||
public interface AuthorizeConfigManager { | ||
|
||
void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...ecurity-core/src/main/java/com/imooc/security/core/authorize/AuthorizeConfigProvider.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,17 @@ | ||
/** | ||
* | ||
*/ | ||
package com.imooc.security.core.authorize; | ||
|
||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | ||
|
||
/** | ||
* @author zhailiang | ||
* | ||
*/ | ||
public interface AuthorizeConfigProvider { | ||
|
||
void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...ity-core/src/main/java/com/imooc/security/core/authorize/ImoocAuthorizeConfigManager.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,31 @@ | ||
/** | ||
* | ||
*/ | ||
package com.imooc.security.core.authorize; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author zhailiang | ||
* | ||
*/ | ||
@Component | ||
public class ImoocAuthorizeConfigManager implements AuthorizeConfigManager { | ||
|
||
@Autowired | ||
private List<AuthorizeConfigProvider> authorizeConfigProviders; | ||
|
||
@Override | ||
public void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) { | ||
for (AuthorizeConfigProvider authorizeConfigProvider : authorizeConfigProviders) { | ||
authorizeConfigProvider.config(config); | ||
} | ||
// config.anyRequest().authenticated(); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...ty-core/src/main/java/com/imooc/security/core/authorize/ImoocAuthorizeConfigProvider.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,40 @@ | ||
/** | ||
* | ||
*/ | ||
package com.imooc.security.core.authorize; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.imooc.security.core.properties.SecurityConstants; | ||
import com.imooc.security.core.properties.SecurityProperties; | ||
|
||
/** | ||
* @author zhailiang | ||
* | ||
*/ | ||
@Component | ||
@Order(Integer.MIN_VALUE) | ||
public class ImoocAuthorizeConfigProvider implements AuthorizeConfigProvider { | ||
|
||
@Autowired | ||
private SecurityProperties securityProperties; | ||
|
||
@Override | ||
public void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) { | ||
config.antMatchers( | ||
SecurityConstants.DEFAULT_UNAUTHENTICATION_URL, | ||
SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_MOBILE, | ||
SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_OPENID, | ||
securityProperties.getBrowser().getLoginPage(), | ||
SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX+"/*", | ||
securityProperties.getBrowser().getSignUpUrl(), | ||
securityProperties.getBrowser().getSession().getSessionInvalidUrl(), | ||
securityProperties.getBrowser().getSignOutUrl()) | ||
.permitAll(); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
imooc-security-core/src/main/java/com/imooc/security/core/authorize/package-info.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,8 @@ | ||
/** | ||
* | ||
*/ | ||
/** | ||
* @author zhailiang | ||
* | ||
*/ | ||
package com.imooc.security.core.authorize; |
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
30 changes: 30 additions & 0 deletions
30
imooc-security-demo/src/main/java/com/imooc/security/DemoAuthorizeConifgProvider.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,30 @@ | ||
/** | ||
* | ||
*/ | ||
package com.imooc.security; | ||
|
||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.imooc.security.core.authorize.AuthorizeConfigProvider; | ||
|
||
/** | ||
* @author zhailiang | ||
* | ||
*/ | ||
@Component | ||
@Order(Integer.MAX_VALUE) | ||
public class DemoAuthorizeConifgProvider implements AuthorizeConfigProvider { | ||
|
||
/* (non-Javadoc) | ||
* @see com.imooc.security.core.authorize.AuthorizeConfigProvider#config(org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry) | ||
*/ | ||
@Override | ||
public void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) { | ||
|
||
config.anyRequest().access("@rbacService.hasPermission(request, authentication)"); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -25,5 +25,7 @@ | |
Class<?>[] groups() default { }; | ||
|
||
Class<? extends Payload>[] payload() default { }; | ||
|
||
String field() default ""; | ||
|
||
} |
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
10 changes: 10 additions & 0 deletions
10
imooc-security-demo/src/main/resources/resources/demo.html
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,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Insert title here</title> | ||
</head> | ||
<body> | ||
DEMO | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
imooc-security-demo/src/main/resources/resources/error/403.html
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,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>403</title> | ||
</head> | ||
<body> | ||
您无权访问此页面 | ||
</body> | ||
</html> |