use of org.cloudfoundry.identity.uaa.oauth.token.RevocableTokenProvisioning in project uaa by cloudfoundry.
the class TokenValidationTest method nonRevocableToken.
@Test
public void nonRevocableToken() {
revocableTokenProvisioning = mock(RevocableTokenProvisioning.class);
when(revocableTokenProvisioning.retrieve("8b14f193-8212-4af2-9927-e3ae903f94a6", IdentityZoneHolder.get().getId())).thenThrow(// should not occur
new EmptyResultDataAccessException(1));
content.remove("revocable");
buildAccessTokenValidator(getToken(), new KeyInfoService("https://localhost")).checkRevocableTokenStore(revocableTokenProvisioning);
verifyZeroInteractions(revocableTokenProvisioning);
}
use of org.cloudfoundry.identity.uaa.oauth.token.RevocableTokenProvisioning in project uaa by cloudfoundry.
the class TokenValidationTest method tokenIsRevoked.
@Test
public void tokenIsRevoked() {
RevocableTokenProvisioning revocableTokenProvisioning = mock(RevocableTokenProvisioning.class);
when(revocableTokenProvisioning.retrieve("8b14f193-8212-4af2-9927-e3ae903f94a6", IdentityZoneHolder.get().getId())).thenThrow(new EmptyResultDataAccessException(1));
expectedException.expect(InvalidTokenException.class);
buildAccessTokenValidator(getToken(), new KeyInfoService("https://localhost")).checkRevocableTokenStore(revocableTokenProvisioning);
}
use of org.cloudfoundry.identity.uaa.oauth.token.RevocableTokenProvisioning in project uaa by cloudfoundry.
the class TokenValidationServiceTest method setup.
@Before
public void setup() {
header = map(entry("alg", "RSA"), entry("kid", "key1"), entry("typ", "JWT"));
content = map(entry(USER_ID, userId), entry(JTI, "abcdefg"), entry(CID, clientId), entry(SCOPE, Lists.newArrayList("foo.bar")));
signer = new RsaSigner(PRIVATE_KEY);
IdentityZoneHolder.get().getConfig().getTokenPolicy().setKeys(Collections.singletonMap("key1", PRIVATE_KEY));
userDatabase = mock(UaaUserDatabase.class);
tokenEndpointBuilder = mock(TokenEndpointBuilder.class);
mockMultitenantClientServices = mock(MultitenantClientServices.class);
revocableTokenProvisioning = mock(RevocableTokenProvisioning.class);
when(mockMultitenantClientServices.loadClientByClientId(clientId, IdentityZoneHolder.get().getId())).thenReturn(new BaseClientDetails(clientId, null, "foo.bar", null, null));
UaaUser user = new UaaUser(userId, "marrisa", "koala", "marissa@gmail.com", buildGrantedAuthorities("foo.bar"), "Marissa", "Bloggs", null, null, null, null, true, null, null, null);
when(userDatabase.retrieveUserById(userId)).thenReturn(user);
tokenValidationService = new TokenValidationService(revocableTokenProvisioning, tokenEndpointBuilder, userDatabase, mockMultitenantClientServices, new KeyInfoService("http://localhost:8080/uaa"));
}
use of org.cloudfoundry.identity.uaa.oauth.token.RevocableTokenProvisioning in project uaa by cloudfoundry.
the class TokenValidationTest method setup.
@Before
public void setup() {
String defaultKeyId = "some-key-id";
IdentityZone uaaZone = IdentityZone.getUaa();
uaaZone.getConfig().getTokenPolicy().setKeys(map(entry(defaultKeyId, macSigningKeySecret)));
IdentityZoneProvisioning identityZoneProvisioning = mock(IdentityZoneProvisioning.class);
when(identityZoneProvisioning.retrieve(anyString())).thenReturn(uaaZone);
IdentityZoneHolder.setProvisioning(identityZoneProvisioning);
header = map(entry("alg", "HS256"), entry("kid", defaultKeyId));
content = map(entry("jti", "8b14f193-8212-4af2-9927-e3ae903f94a6"), entry("nonce", "04e2e934200b4b9fbe5d4e70ae18ba8e"), entry("sub", "a7f07bf6-e720-4652-8999-e980189cef54"), entry("scope", Collections.singletonList("acme.dev")), entry("client_id", "app"), entry("cid", "app"), entry("azp", "app"), entry("grant_type", GRANT_TYPE_AUTHORIZATION_CODE), entry("user_id", "a7f07bf6-e720-4652-8999-e980189cef54"), entry("origin", "uaa"), entry("user_name", "marissa"), entry("email", "marissa@test.org"), entry("auth_time", 1458953554), entry("rev_sig", "fa1c787d"), entry("iat", 1458953932), entry("exp", 1458997132), entry("iss", "http://localhost:8080/uaa/oauth/token"), entry("zid", "uaa"), entry("aud", Arrays.asList("app", "acme")), entry("revocable", true));
signer = new MacSigner(macSigningKeySecret);
IdentityZoneManager mockIdentityZoneManager = mock(IdentityZoneManager.class);
when(mockIdentityZoneManager.getCurrentIdentityZoneId()).thenReturn(IdentityZone.getUaaZoneId());
inMemoryMultitenantClientServices = new InMemoryMultitenantClientServices(mockIdentityZoneManager);
uaaClient = new BaseClientDetails("app", "acme", "acme.dev", GRANT_TYPE_AUTHORIZATION_CODE, "");
uaaClient.addAdditionalInformation(REQUIRED_USER_GROUPS, Collections.emptyList());
inMemoryMultitenantClientServices.setClientDetailsStore(IdentityZone.getUaaZoneId(), Collections.singletonMap(CLIENT_ID, uaaClient));
revocableTokenProvisioning = mock(RevocableTokenProvisioning.class);
when(revocableTokenProvisioning.retrieve("8b14f193-8212-4af2-9927-e3ae903f94a6", IdentityZoneHolder.get().getId())).thenReturn(new RevocableToken().setValue(UaaTokenUtils.constructToken(header, content, signer)));
userDb = new MockUaaUserDatabase(u -> u.withUsername("marissa").withId(USER_ID).withEmail("marissa@test.org").withAuthorities(Collections.singletonList(new SimpleGrantedAuthority("acme.dev"))));
uaaUser = userDb.retrieveUserById(USER_ID);
uaaUserGroups = uaaUser.getAuthorities().stream().map(a -> a.getAuthority()).collect(Collectors.toList());
}
Aggregations