use of io.gravitee.am.model.safe.UserProperties in project gravitee-access-management by gravitee-io.
the class IDTokenServiceImpl method createExecution.
private ExecutionContext createExecution(OAuth2Request request, Client client, User user) {
ExecutionContext simpleExecutionContext = new SimpleExecutionContext(request, null);
ExecutionContext executionContext = executionContextFactory.create(simpleExecutionContext);
executionContext.setAttribute("client", new ClientProperties(client));
if (user != null) {
executionContext.setAttribute("user", new UserProperties(user));
}
Object authFlowAttributes = request.getContext().get(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY);
if (authFlowAttributes != null) {
executionContext.setAttribute(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY, authFlowAttributes);
request.getContext().remove(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY);
}
return executionContext;
}
use of io.gravitee.am.model.safe.UserProperties in project gravitee-access-management by gravitee-io.
the class UMATokenGranter method executePolicies.
/**
* The resource owner works with the authorization server to configure policy conditions (authorization grant rules), which the authorization server executes in the process of issuing access tokens.
* The authorization process makes use of claims gathered from the requesting party and client in order to satisfy all operative operative policy conditions.
* @param oAuth2Request OAuth 2.0 Token Request
* @param client client
* @param endUser requesting party
* @return
*/
private Single<OAuth2Request> executePolicies(OAuth2Request oAuth2Request, Client client, User endUser) {
List<PermissionRequest> permissionRequests = oAuth2Request.getPermissions();
if (permissionRequests == null || permissionRequests.isEmpty()) {
return Single.just(oAuth2Request);
}
List<String> resourceIds = permissionRequests.stream().map(PermissionRequest::getResourceId).collect(Collectors.toList());
// find access policies for the given resources
return resourceService.findAccessPoliciesByResources(resourceIds).map(accessPolicy -> {
Rule rule = new DefaultRule(accessPolicy);
Optional<PermissionRequest> permission = permissionRequests.stream().filter(permissionRequest -> permissionRequest.getResourceId().equals(accessPolicy.getResource())).findFirst();
if (permission.isPresent()) {
((DefaultRule) rule).setMetadata(Collections.singletonMap("permissionRequest", permission.get()));
}
return rule;
}).toList().flatMap(rules -> {
// no policy registered, continue
if (rules.isEmpty()) {
return Single.just(oAuth2Request);
}
// prepare the execution context
ExecutionContext simpleExecutionContext = new SimpleExecutionContext(oAuth2Request, oAuth2Request.getHttpResponse());
ExecutionContext executionContext = executionContextFactory.create(simpleExecutionContext);
executionContext.setAttribute("client", new ClientProperties(client));
if (endUser != null) {
executionContext.setAttribute("user", new UserProperties(endUser));
}
// execute the policies
return rulesEngine.fire(rules, executionContext).toSingleDefault(oAuth2Request).onErrorResumeNext(ex -> Single.error(new InvalidGrantException("Policy conditions are not met for actual request parameters")));
});
}
use of io.gravitee.am.model.safe.UserProperties in project gravitee-access-management by gravitee-io.
the class EmailServiceImpl method prepareEmailParams.
private Map<String, Object> prepareEmailParams(User user, Client client, Integer expiresAfter, String redirectUri) {
// generate a JWT to store user's information and for security purpose
final Map<String, Object> claims = new HashMap<>();
claims.put(Claims.iat, new Date().getTime() / 1000);
claims.put(Claims.exp, new Date(System.currentTimeMillis() + (expiresAfter * 1000)).getTime() / 1000);
claims.put(Claims.sub, user.getId());
if (client != null) {
claims.put(Claims.aud, client.getId());
}
String token = jwtBuilder.sign(new JWT(claims));
String redirectUrl = domainService.buildUrl(domain, redirectUri + "?token=" + token);
Map<String, Object> params = new HashMap<>();
params.put("user", new UserProperties(user));
params.put("url", redirectUrl);
params.put("token", token);
params.put("expireAfterSeconds", expiresAfter);
params.put("domain", new DomainProperties(domain));
if (client != null) {
params.put("client", new ClientProperties(client));
}
return params;
}
Aggregations