-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature : add conditional Introspector settings based on application.…
…properties
- Loading branch information
1 parent
27d7cbb
commit 6722a70
Showing
10 changed files
with
104 additions
and
81 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
24 changes: 0 additions & 24 deletions
24
...atternknife/securityhelper/oauth2/client/config/securityimpl/guard/SecurityGuardUtil.java
This file was deleted.
Oops, something went wrong.
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
55 changes: 47 additions & 8 deletions
55
...client/config/securityimpl/introspector/CustomDefaultResourceServerTokenIntrospector.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
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
48 changes: 23 additions & 25 deletions
48
...faultResourceServerTokenIntrospector.java → ...faultResourceServerTokenIntrospector.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 |
---|---|---|
@@ -1,53 +1,51 @@ | ||
package io.github.patternknife.securityhelper.oauth2.api.config.security.provider.resource.introspector; | ||
package io.github.patternknife.securityhelper.oauth2.api.config.security.introspector; | ||
|
||
|
||
import io.github.patternknife.securityhelper.oauth2.api.config.security.message.DefaultSecurityUserExceptionMessage; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.message.ISecurityUserExceptionMessageService; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.exception.KnifeOauth2AuthenticationException; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.serivce.persistence.authorization.OAuth2AuthorizationServiceImpl; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.serivce.userdetail.ConditionalDetailsService; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal; | ||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization; | ||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType; | ||
import org.springframework.security.oauth2.server.resource.introspection.NimbusOpaqueTokenIntrospector; | ||
import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector; | ||
import org.springframework.security.oauth2.server.resource.introspection.SpringOpaqueTokenIntrospector; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
public class DefaultResourceServerTokenIntrospector implements OpaqueTokenIntrospector { | ||
|
||
private OpaqueTokenIntrospector delegate = | ||
new SpringOpaqueTokenIntrospector( | ||
"http://localhost:8370/oauth2/introspect", | ||
"barClient", | ||
"barClientSecret" | ||
); | ||
|
||
public DefaultResourceServerTokenIntrospector() { | ||
|
||
private final OAuth2AuthorizationServiceImpl authorizationService; | ||
private final ConditionalDetailsService conditionalDetailsService; | ||
private final ISecurityUserExceptionMessageService iSecurityUserExceptionMessageService; | ||
|
||
public DefaultResourceServerTokenIntrospector( | ||
OAuth2AuthorizationServiceImpl authorizationService, | ||
ConditionalDetailsService conditionalDetailsService, | ||
ISecurityUserExceptionMessageService iSecurityUserExceptionMessageService, | ||
@Value("${patternknife.securityhelper.oauth2.introspection.type}") String introspectionType, | ||
@Value("${patternknife.securityhelper.oauth2.introspection.uri}") String introspectionUri, | ||
@Value("${patternknife.securityhelper.oauth2.introspection.client-id}") String clientId, | ||
@Value("${patternknife.securityhelper.oauth2.introspection.client-secret}") String clientSecret) { | ||
|
||
/* | ||
* @Values will be ignored here. Check CustomResourceServerTokenIntrospector in the sample client folder. | ||
* */ | ||
this.authorizationService = authorizationService; | ||
this.conditionalDetailsService = conditionalDetailsService; | ||
this.iSecurityUserExceptionMessageService = iSecurityUserExceptionMessageService; | ||
} | ||
|
||
@Override | ||
public OAuth2AuthenticatedPrincipal introspect(String token) { | ||
|
||
/* try { | ||
OAuth2AuthenticatedPrincipal principal = delegate.introspect(token); | ||
return principal; | ||
}catch (Exception e){ | ||
//throw e; | ||
throw new KnifeOauth2AuthenticationException(e.getMessage()); | ||
}*/ | ||
return null; | ||
|
||
/*OAuth2Authorization oAuth2Authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN); | ||
OAuth2Authorization oAuth2Authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN); | ||
|
||
if(oAuth2Authorization == null || oAuth2Authorization.getAccessToken() == null || oAuth2Authorization.getAccessToken().isExpired() | ||
|| oAuth2Authorization.getRefreshToken() == null || oAuth2Authorization.getRefreshToken().isExpired()){ | ||
throw new KnifeOauth2AuthenticationException(iSecurityUserExceptionMessageService.getUserMessage(DefaultSecurityUserExceptionMessage.AUTHENTICATION_TOKEN_FAILURE)); | ||
//return null; | ||
} | ||
|
||
return (OAuth2AuthenticatedPrincipal) conditionalDetailsService.loadUserByUsername(oAuth2Authorization.getPrincipalName(), (String) oAuth2Authorization.getAttributes().get("client_id"));*/ | ||
return (OAuth2AuthenticatedPrincipal) conditionalDetailsService.loadUserByUsername(oAuth2Authorization.getPrincipalName(), (String) oAuth2Authorization.getAttributes().get("client_id")); | ||
} | ||
} |
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