use of org.gluu.oxauth.model.uma.persistence.UmaPermission in project oxAuth by GluuFederation.
the class UmaPermissionService method changeTicket.
public String changeTicket(List<UmaPermission> permissions, Map<String, String> attributes) {
String newTicket = generateNewTicket();
for (UmaPermission permission : permissions) {
ldapEntryManager.remove(permission);
String dn = String.format("oxTicket=%s,%s", newTicket, StringUtils.substringAfter(permission.getDn(), ","));
permission.setTicket(newTicket);
permission.setDn(dn);
permission.setAttributes(attributes);
ldapEntryManager.persist(permission);
log.trace("New ticket: " + newTicket + ", old permission: " + dn);
}
return newTicket;
}
use of org.gluu.oxauth.model.uma.persistence.UmaPermission in project oxAuth by GluuFederation.
the class CleanerTimerTest method umaPermission_whichIsExpiredAndDeletable_MustBeRemoved.
@Test
public void umaPermission_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
final Client client = createClient();
clientService.persist(client);
final String ticket = UUID.randomUUID().toString();
// 1. create permission
UmaPermission permission = new UmaPermission();
permission.setTicket(ticket);
permission.setConfigurationCode(UUID.randomUUID().toString());
permission.setResourceId(UUID.randomUUID().toString());
umaPermissionService.addPermission(permission, client.getDn());
// 2. permission exists
assertNotNull(umaPermissionService.getPermissionsByTicket(ticket).get(0));
// 3. clean up
cleanerTimer.processImpl();
cacheService.clear();
// 4. permission exists
assertNotNull(umaPermissionService.getPermissionsByTicket(ticket).get(0));
final Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, -10);
permission.setExpirationDate(calendar.getTime());
umaPermissionService.merge(permission);
// 5. clean up
cleanerTimer.processImpl();
cacheService.clear();
// 6. no permission in persistence
final List<UmaPermission> permissionsByTicket = umaPermissionService.getPermissionsByTicket(ticket);
assertTrue(permissionsByTicket.isEmpty());
}
use of org.gluu.oxauth.model.uma.persistence.UmaPermission in project oxAuth by GluuFederation.
the class UmaTokenService method addPctToPermissions.
private void addPctToPermissions(List<UmaPermission> permissions, UmaPCT pct) {
for (UmaPermission p : permissions) {
p.getAttributes().put(UmaPermission.PCT, pct.getCode());
permissionService.mergeSilently(p);
}
}
use of org.gluu.oxauth.model.uma.persistence.UmaPermission in project oxAuth by GluuFederation.
the class UmaTokenService method updatePermissionsWithClientRequestedScope.
private void updatePermissionsWithClientRequestedScope(List<UmaPermission> permissions, Map<Scope, Boolean> scopes) {
log.trace("Updating permissions with requested scopes ...");
for (UmaPermission permission : permissions) {
Set<String> scopeDns = new HashSet<>(permission.getScopeDns());
for (Map.Entry<Scope, Boolean> entry : scopes.entrySet()) {
log.trace("Updating permissions with scope: " + entry.getKey().getId() + ", isRequestedScope: " + entry.getValue() + ", permisson: " + permission.getDn());
scopeDns.add(entry.getKey().getDn());
}
permission.setScopeDns(new ArrayList<>(scopeDns));
}
}
use of org.gluu.oxauth.model.uma.persistence.UmaPermission in project oxAuth by GluuFederation.
the class UmaRptService method buildPermissionsJSONObject.
public JSONArray buildPermissionsJSONObject(List<UmaPermission> permissions) throws IOException, JSONException {
List<org.gluu.oxauth.model.uma.UmaPermission> result = new ArrayList<>();
for (UmaPermission permission : permissions) {
permission.checkExpired();
permission.isValid();
if (permission.isValid()) {
final org.gluu.oxauth.model.uma.UmaPermission toAdd = ServerUtil.convert(permission, umaScopeService);
if (toAdd != null) {
result.add(toAdd);
}
} else {
log.debug("Ignore permission, skip it in response because permission is not valid. Permission dn: {}", permission.getDn());
}
}
final String json = ServerUtil.asJson(result);
return new JSONArray(json);
}
Aggregations