use of javax.ws.rs.core.SecurityContext in project coprhd-controller by CoprHD.
the class PasswordServiceTest method testUpdatePasswordTooManyParams.
@Test(expected = BadRequestException.class)
public void testUpdatePasswordTooManyParams() {
PasswordService passwordResource = new PasswordService();
passwordResource.setPropertiesMetadata(_propertiesMetadata);
passwordResource.setAuditLogManager(new DummyAuditLogManager());
PasswordUpdateParam passwordUpdate = getDummyPasswordUpdate("clearTextPwd", "HashedPassword");
LocalPasswordHandler ph = getPasswordHandler();
ph.setLocalUsers(createLocalUsers());
passwordResource.setPasswordHandler(ph);
SecurityContext sc = new DummySecurityContext(LOCAL_ROOT);
passwordResource.setSecurityContext(sc);
Response res = passwordResource.updatePassword(null, null, passwordUpdate, false);
}
use of javax.ws.rs.core.SecurityContext in project coprhd-controller by CoprHD.
the class PasswordServiceTest method testUpdateUserPasswordNoPrincipal.
@Test(expected = ForbiddenException.class)
public void testUpdateUserPasswordNoPrincipal() {
PasswordService passwordResource = new PasswordService();
passwordResource.setPropertiesMetadata(_propertiesMetadata);
passwordResource.setAuditLogManager(new DummyAuditLogManager());
PasswordResetParam passwordUpdate = getDummyPasswordReset("user123", "!changeme", "");
SecurityContext sc = new DummySecurityContext("noprincipal");
passwordResource.setSecurityContext(sc);
Response res = passwordResource.updateUserPassword(passwordUpdate, false);
Assert.assertTrue("Should throw exception, but returned " + res.getStatus(), false);
}
use of javax.ws.rs.core.SecurityContext in project coprhd-controller by CoprHD.
the class PasswordServiceTest method testUpdateUserPassword.
@Test
public void testUpdateUserPassword() {
PasswordService passwordResource = new PasswordService();
passwordResource.setPropertiesMetadata(_propertiesMetadata);
passwordResource.setAuditLogManager(new DummyAuditLogManager());
PasswordResetParam passwordUpdate = getDummyPasswordReset(LOCAL_ROOT, "!changeMe3", "");
LocalPasswordHandler ph = getDummyLocalPasswordHandler();
ph.setLocalUsers(createLocalUsers());
passwordResource.setPasswordHandler(ph);
SecurityContext sc = new DummySecurityContext(LOCAL_ROOT);
passwordResource.setSecurityContext(sc);
Response res = passwordResource.updateUserPassword(passwordUpdate, false);
int statusCode = res.getStatus();
Assert.assertTrue("updatePassword failed with code " + statusCode + ": " + res.getEntity().toString(), statusCode == Status.OK.getStatusCode());
sc = new DummySecurityContext(LOCAL_PROXYUSER);
passwordResource.setSecurityContext(sc);
passwordUpdate.setUsername(LOCAL_PROXYUSER);
res = passwordResource.updateUserPassword(passwordUpdate, false);
statusCode = res.getStatus();
Assert.assertTrue("updatePassword failed with code " + statusCode + ": " + res.getEntity().toString(), statusCode == Status.OK.getStatusCode());
}
use of javax.ws.rs.core.SecurityContext in project coprhd-controller by CoprHD.
the class PasswordServiceTest method testUpdateUserPasswordEmptyParams.
@Test(expected = BadRequestException.class)
public void testUpdateUserPasswordEmptyParams() {
PasswordService passwordResource = new PasswordService();
passwordResource.setPropertiesMetadata(_propertiesMetadata);
passwordResource.setAuditLogManager(new DummyAuditLogManager());
PasswordResetParam passwordUpdate = getDummyPasswordReset(LOCAL_ROOT, "", "");
LocalPasswordHandler ph = getPasswordHandler();
ph.setLocalUsers(createLocalUsers());
passwordResource.setPasswordHandler(ph);
SecurityContext sc = new DummySecurityContext(LOCAL_ROOT);
passwordResource.setSecurityContext(sc);
Response res = passwordResource.updateUserPassword(passwordUpdate, false);
}
use of javax.ws.rs.core.SecurityContext in project iaf by ibissource.
the class ApiTestBase method checkContextFields.
// This has to happen before it's proxied by Mockito (spy method)
public void checkContextFields(M resource) {
for (Field field : resource.getClass().getDeclaredFields()) {
// Injected JAX-WS Resources
Context context = AnnotationUtils.findAnnotation(field, Context.class);
if (context != null) {
field.setAccessible(true);
if (field.getType().isAssignableFrom(Request.class)) {
Request request = new MockHttpRequest();
try {
field.set(resource, request);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
fail("unable to inject Request");
}
} else if (field.getType().isAssignableFrom(SecurityContext.class)) {
try {
field.set(resource, securityContext);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
fail("unable to inject Request");
}
}
}
}
}
Aggregations