use of org.apereo.cas.uma.ticket.resource.ResourceSet in project cas by apereo.
the class DefaultUmaResourceSetClaimPermissionExaminerTests method verifyUnmatchedOperation.
@Test
public void verifyUnmatchedOperation() {
val ticketId = UUID.randomUUID().toString();
val permissionTicket = mock(UmaPermissionTicket.class);
when(permissionTicket.getId()).thenReturn(ticketId);
when(permissionTicket.isExpired()).thenReturn(Boolean.FALSE);
when(permissionTicket.getClaims()).thenReturn(Map.of("c1", "v1", "c2", "v2"));
when(permissionTicket.getScopes()).thenReturn(Set.of("s1", "s2", "s3"));
val id = UUID.randomUUID().toString();
val resourceSet = new ResourceSet();
resourceSet.setClientId(id);
resourceSet.setScopes(CollectionUtils.wrapHashSet("s2"));
val policy = new ResourceSetPolicy();
val permission = new ResourceSetPolicyPermission();
permission.setId(1000);
permission.setSubject("casuser");
permission.setClaims(new LinkedHashMap<>(Map.of("c10", "v10")));
permission.setScopes(CollectionUtils.wrapHashSet("s1", "s2"));
policy.setPermissions(CollectionUtils.wrapHashSet(permission));
resourceSet.setPolicies(CollectionUtils.wrapHashSet(policy));
val result = umaResourceSetClaimPermissionExaminer.examine(resourceSet, permissionTicket);
assertNotNull(result);
assertTrue(result.getDetails().containsKey(permission.getId()));
}
use of org.apereo.cas.uma.ticket.resource.ResourceSet in project cas by apereo.
the class DefaultUmaResourceSetClaimPermissionExaminerTests method verifyMatchedOperation.
@Test
public void verifyMatchedOperation() {
val ticketId = UUID.randomUUID().toString();
val permissionTicket = mock(UmaPermissionTicket.class);
when(permissionTicket.getId()).thenReturn(ticketId);
when(permissionTicket.isExpired()).thenReturn(Boolean.FALSE);
when(permissionTicket.getClaims()).thenReturn(Map.of("c1", "v1"));
when(permissionTicket.getScopes()).thenReturn(Set.of("s1", "s2"));
val id = UUID.randomUUID().toString();
val resourceSet = new ResourceSet();
resourceSet.setClientId(id);
val policy = new ResourceSetPolicy();
val permission = new ResourceSetPolicyPermission();
permission.setId(1000);
permission.setSubject("casuser");
permission.setClaims(new LinkedHashMap<>(Map.of("c1", "v1")));
permission.setScopes(CollectionUtils.wrapHashSet("s1", "s2"));
policy.setPermissions(CollectionUtils.wrapHashSet(permission));
resourceSet.setPolicies(CollectionUtils.wrapHashSet(policy));
val result = umaResourceSetClaimPermissionExaminer.examine(resourceSet, permissionTicket);
assertNotNull(result);
assertFalse(result.getDetails().containsKey(permission.getId()));
}
use of org.apereo.cas.uma.ticket.resource.ResourceSet in project cas by apereo.
the class UmaResourceRegistrationRequest method asResourceSet.
/**
* As resource set.
*
* @param profileResult the profile result
* @return the resource set
*/
@JsonIgnore
public ResourceSet asResourceSet(final UserProfile profileResult) {
val resourceSet = new ResourceSet();
resourceSet.setIconUri(getIconUri());
resourceSet.setId(getId());
resourceSet.setName(getName());
resourceSet.setScopes(new HashSet<>(getScopes()));
resourceSet.setUri(getUri());
resourceSet.setType(getType());
resourceSet.setOwner(profileResult.getId());
resourceSet.setClientId(OAuth20Utils.getClientIdFromAuthenticatedProfile(profileResult));
return resourceSet;
}
use of org.apereo.cas.uma.ticket.resource.ResourceSet in project cas by apereo.
the class UmaAuthorizationRequestEndpointController method generateRequestingPartyToken.
/**
* Generate requesting party token response entity.
*
* @param request the request
* @param response the response
* @param profileResult the profile result
* @param umaRequest the uma request
* @param permissionTicket the permission ticket
* @param resourceSet the resource set
* @return the response entity
* @throws Exception the exception
*/
protected ResponseEntity generateRequestingPartyToken(final HttpServletRequest request, final HttpServletResponse response, final UserProfile profileResult, final UmaAuthorizationRequest umaRequest, final UmaPermissionTicket permissionTicket, final ResourceSet resourceSet) throws Exception {
val currentAat = (OAuth20AccessToken) profileResult.getAttribute(OAuth20AccessToken.class.getName());
val registeredService = OAuth20Utils.getRegisteredOAuthServiceByClientId(getUmaConfigurationContext().getServicesManager(), OAuth20Utils.getClientIdFromAuthenticatedProfile(profileResult));
val scopes = new LinkedHashSet<>(permissionTicket.getScopes());
scopes.add(OAuth20Constants.UMA_AUTHORIZATION_SCOPE);
scopes.addAll(resourceSet.getScopes());
val holder = AccessTokenRequestContext.builder().authentication(currentAat.getAuthentication()).ticketGrantingTicket(currentAat.getTicketGrantingTicket()).grantType(OAuth20GrantTypes.UMA_TICKET).responseType(OAuth20ResponseTypes.NONE).registeredService(registeredService).generateRefreshToken(false).scopes(scopes).service(currentAat.getService()).build();
val result = getUmaConfigurationContext().getAccessTokenGenerator().generate(holder);
val accessToken = result.getAccessToken().get();
val encodedAccessToken = OAuth20JwtAccessTokenEncoder.builder().accessToken(accessToken).registeredService(holder.getRegisteredService()).service(holder.getService()).accessTokenJwtBuilder(getUmaConfigurationContext().getAccessTokenJwtBuilder()).casProperties(getUmaConfigurationContext().getCasProperties()).build().encode();
val timeout = Beans.newDuration(getUmaConfigurationContext().getCasProperties().getAuthn().getOauth().getUma().getRequestingPartyToken().getMaxTimeToLiveInSeconds()).getSeconds();
val userProfile = OAuth20Utils.getAuthenticatedUserProfile(new JEEContext(request, response), getUmaConfigurationContext().getSessionStore());
userProfile.addAttribute(UmaPermissionTicket.class.getName(), permissionTicket);
userProfile.addAttribute(ResourceSet.class.getName(), resourceSet);
val idToken = getUmaConfigurationContext().getRequestingPartyTokenGenerator().generate(accessToken, timeout, userProfile, OAuth20ResponseTypes.CODE, OAuth20GrantTypes.UMA_TICKET, registeredService);
accessToken.setIdToken(idToken);
getUmaConfigurationContext().getCentralAuthenticationService().updateTicket(accessToken);
if (StringUtils.isNotBlank(umaRequest.getRpt())) {
getUmaConfigurationContext().getCentralAuthenticationService().deleteTicket(umaRequest.getRpt());
}
val model = CollectionUtils.wrap("rpt", encodedAccessToken, "code", HttpStatus.CREATED);
return new ResponseEntity<>(model, HttpStatus.OK);
}
use of org.apereo.cas.uma.ticket.resource.ResourceSet in project cas by apereo.
the class JpaResourceSetRepositoryTests method buildTestResource.
private static ResourceSet buildTestResource() {
val r = new ResourceSet();
r.setClientId("clientid");
r.setIconUri("https://www.example.com/icon");
r.setName("resource");
r.setOwner("cas");
r.setScopes(CollectionUtils.wrapHashSet("read", "write"));
r.setType("CAS-UMA");
r.setUri("https://www.example.com/cas");
return r;
}
Aggregations