This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SECOAUTH-347 Allow custom token granters in authorization-server name…
…space configuration
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 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
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
49 changes: 49 additions & 0 deletions
49
.../org/springframework/security/oauth2/config/TestAuthorizationServerCustomGrantParser.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,49 @@ | ||
package org.springframework.security.oauth2.config; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.support.GenericXmlApplicationContext; | ||
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; | ||
import org.springframework.security.oauth2.common.OAuth2AccessToken; | ||
import org.springframework.security.oauth2.provider.AuthorizationRequest; | ||
import org.springframework.security.oauth2.provider.CompositeTokenGranter; | ||
import org.springframework.security.oauth2.provider.TokenGranter; | ||
|
||
public class TestAuthorizationServerCustomGrantParser { | ||
|
||
private static String RESOURCE_NAME = "authorization-server-custom-grant.xml"; | ||
|
||
private ConfigurableApplicationContext context; | ||
|
||
@Rule | ||
public ExpectedException expected = ExpectedException.none(); | ||
|
||
public TestAuthorizationServerCustomGrantParser() { | ||
context = new GenericXmlApplicationContext(getClass(), RESOURCE_NAME); | ||
} | ||
|
||
@Test | ||
public void testCustomGrantRegistered() { | ||
TokenGranter granter = context.getBean(CompositeTokenGranter.class); | ||
assertNotNull("Custom grant registration failed!", granter.grant("test-grant", null)); | ||
} | ||
|
||
public static class CustomTestTokenGranter implements TokenGranter { | ||
|
||
public CustomTestTokenGranter() {} | ||
|
||
public OAuth2AccessToken grant(String grantType, | ||
AuthorizationRequest authorizationRequest) { | ||
if (grantType.equals("test-grant")) { | ||
return new DefaultOAuth2AccessToken("test"); | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...esources/org/springframework/security/oauth2/config/authorization-server-custom-grant.xml
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:oauth2="http://www.springframework.org/schema/security/oauth2" | ||
xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
|
||
<bean id="tokenGranter" class="org.springframework.security.oauth2.config.TestAuthorizationServerCustomGrantParser.CustomTestTokenGranter" /> | ||
|
||
<oauth2:authorization-server client-details-service-ref="clientDetails"> | ||
<oauth2:authorization-code /> | ||
<oauth2:custom-grant token-granter-ref="tokenGranter" /> | ||
</oauth2:authorization-server> | ||
|
||
<oauth2:client-details-service id="clientDetails"> | ||
<oauth2:client client-id="foo" authorized-grant-types="password"/> | ||
</oauth2:client-details-service> | ||
|
||
</beans> |