use of com.sap.cloud.security.xsuaa.test.JwtGenerator in project cloud-security-xsuaa-integration by SAP.
the class TokenAuthenticationConverterTest method extractAuthoritiesIgnoresForeignScopes.
@Test
public void extractAuthoritiesIgnoresForeignScopes() {
Jwt jwt = new JwtGenerator().addScopes(scopeAdmin, scopeOther, scopeRead).getToken();
AbstractAuthenticationToken authenticationToken = tokenConverterLocalScopesOnly.convert(jwt);
assertThat(authenticationToken.getAuthorities().size(), is(2));
assertThat(authenticationToken.getAuthorities(), not(hasItem(new SimpleGrantedAuthority("Other"))));
}
use of com.sap.cloud.security.xsuaa.test.JwtGenerator in project cloud-security-xsuaa-integration by SAP.
the class TokenAuthenticationConverterTest method authoritiesHaveLocalScopesWithoutAppIdPrefix.
@Test
public void authoritiesHaveLocalScopesWithoutAppIdPrefix() {
String scopeWithNamespace = xsAppName + ".iot.Delete";
String scopeWithOtherAppId = "anyAppId!t200." + xsAppName + ".Delete";
Jwt jwt = new JwtGenerator().addScopes(xsAppName + "." + scopeAdmin, scopeRead, scopeWithNamespace, scopeWithOtherAppId).getToken();
AbstractAuthenticationToken authenticationToken = tokenConverterLocalScopesOnly.convert(jwt);
assertThat(authenticationToken.getAuthorities().size(), is(3));
assertThat(authenticationToken.getAuthorities(), hasItem(new SimpleGrantedAuthority(scopeAdmin)));
assertThat(authenticationToken.getAuthorities(), hasItem(new SimpleGrantedAuthority("iot.Delete")));
assertThat(authenticationToken.getAuthorities(), hasItem(new SimpleGrantedAuthority("Read")));
}
use of com.sap.cloud.security.xsuaa.test.JwtGenerator in project cloud-security-xsuaa-integration by SAP.
the class TokenAuthenticationConverterTest method extractAuthoritiesWithScopes.
@Test
public void extractAuthoritiesWithScopes() {
Jwt jwt = new JwtGenerator().addScopes(scopeAdmin, scopeRead, scopeOther).getToken();
AbstractAuthenticationToken authenticationToken = tokenConverterDefault.convert(jwt);
assertThat(authenticationToken.getAuthorities().size(), is(3));
assertThat(authenticationToken.getAuthorities(), hasItem(new SimpleGrantedAuthority(scopeRead)));
assertThat(authenticationToken.getAuthorities(), hasItem(new SimpleGrantedAuthority(scopeAdmin)));
assertThat(authenticationToken.getAuthorities(), hasItem(new SimpleGrantedAuthority(scopeOther)));
}
use of com.sap.cloud.security.xsuaa.test.JwtGenerator in project cloud-security-xsuaa-integration by SAP.
the class XsuaaAudienceValidatorTest method setup.
@Before
public void setup() throws IOException {
serviceConfigurationSameClientId = new DummyXsuaaServiceConfiguration("sb-test1!t1", "test1!t1");
serviceConfigurationOtherGrantedClientId = new DummyXsuaaServiceConfiguration("sb-test2!t1", "test2!t1");
serviceConfigurationUnGrantedClientId = new DummyXsuaaServiceConfiguration("sb-test3!t1", "test3!t1");
serviceConfigurationBrokerPlan = new DummyXsuaaServiceConfiguration("sb-test3!b1", "test3!b1");
tokenWithAudience = new JwtGenerator().createFromTemplate("/audience_1.txt");
tokenWithoutAudience = new JwtGenerator().createFromTemplate("/audience_2.txt");
cloneTokenWithAudience = new JwtGenerator().createFromTemplate("/audience_3.txt");
claimsBuilder = new JWTClaimsSet.Builder().issueTime(new Date()).expirationTime(JwtGenerator.NO_EXPIRE_DATE);
claimsBuilder.claim(TokenClaims.CLAIM_CLIENT_ID, "sb-test1!t1");
}
use of com.sap.cloud.security.xsuaa.test.JwtGenerator in project cloud-security-xsuaa-integration by SAP.
the class TestControllerTest method unauthorizedRequest.
@Test
public void unauthorizedRequest() {
JwtGenerator jwtGenerator = new JwtGenerator("WrongClientId");
webClient.method(HttpMethod.GET).uri("/v1/sayHello").contentType(MediaType.APPLICATION_JSON_UTF8).header(HttpHeaders.AUTHORIZATION, jwtGenerator.getTokenForAuthorizationHeader()).exchange().expectStatus().isUnauthorized();
}
Aggregations