use of org.candlepin.model.Role in project candlepin by candlepin.
the class UserResource method getUserRoles.
/*
* getUserRoles will only return roles for one user. If you want a
* full view of a role, use /roles/ instead.
*/
@ApiOperation(notes = "Retrieves a list of Roles by User", value = "getUserRoles")
@GET
@Path("/{username}/roles")
@Produces(MediaType.APPLICATION_JSON)
public List<Role> getUserRoles(@PathParam("username") @Verify(User.class) String username) {
User myUser = userService.findByLogin(username);
List<Role> roles = new LinkedList<>();
Set<User> s = new HashSet<>();
s.add(myUser);
for (Role r : myUser.getRoles()) {
// Copy onto a detached role object so we can omit users list, which could
// technically leak information here.
Role copy = new Role(r.getName());
copy.setId(r.getId());
copy.setPermissions(r.getPermissions());
copy.setUsers(s);
roles.add(copy);
}
return roles;
}
use of org.candlepin.model.Role in project candlepin by candlepin.
the class ConsumerResourceCreationTest method init.
@Before
public void init() throws Exception {
this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
this.modelTranslator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
testMigration = new GuestMigration(consumerCurator);
migrationProvider = Providers.of(testMigration);
this.config = initConfig();
this.resource = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, this.subscriptionService, this.ownerService, null, this.idCertService, null, this.i18n, this.sink, null, null, null, this.userService, null, null, this.ownerCurator, this.activationKeyCurator, null, this.complianceRules, this.deletedConsumerCurator, null, null, this.config, null, null, null, this.consumerBindUtil, null, null, new FactValidator(this.config, this.i18n), null, consumerEnricher, migrationProvider, modelTranslator);
this.system = this.initConsumerType();
this.mockConsumerType(this.system);
this.systemDto = this.modelTranslator.translate(this.system, ConsumerTypeDTO.class);
owner = new Owner("test_owner");
owner.setId(TestUtil.randomString());
user = new User(USER, "");
PermissionBlueprint p = new PermissionBlueprint(PermissionType.OWNER, owner, Access.ALL);
role = new Role();
role.addPermission(p);
role.addUser(user);
when(consumerCurator.create(any(Consumer.class))).thenAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0];
}
});
when(consumerCurator.create(any(Consumer.class), any(Boolean.class))).thenAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0];
}
});
when(userService.findByLogin(USER)).thenReturn(user);
IdentityCertificate cert = new IdentityCertificate();
cert.setKey("testKey");
cert.setCert("testCert");
cert.setId("testId");
cert.setSerial(new CertificateSerial(new Date()));
when(idCertService.generateIdentityCert(any(Consumer.class))).thenReturn(cert);
when(ownerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class), any(Boolean.class))).thenReturn(new ComplianceStatus(new Date()));
}
use of org.candlepin.model.Role in project candlepin by candlepin.
the class OwnerResourceUeberCertOperationsTest method setUp.
@Before
public void setUp() {
owner = ownerCurator.create(new Owner(OWNER_NAME));
Role ownerAdminRole = createAdminRole(owner);
roleCurator.create(ownerAdminRole);
User user = new User("testing user", "pass");
principal = new UserPrincipal("testing user", new ArrayList<>(permFactory.createPermissions(user, ownerAdminRole.getPermissions())), false);
setupPrincipal(principal);
or = new OwnerResource(ownerCurator, productCurator, null, consumerCurator, i18n, null, null, null, null, null, poolManager, null, null, null, null, consumerTypeCurator, entCertCurator, entitlementCurator, ueberCertCurator, ueberCertGenerator, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
}
Aggregations