Search in sources :

Example 66 with SecurityContext

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);
}
Also used : Response(javax.ws.rs.core.Response) SecurityContext(javax.ws.rs.core.SecurityContext) PasswordUpdateParam(com.emc.storageos.model.password.PasswordUpdateParam) LocalPasswordHandler(com.emc.storageos.systemservices.impl.util.LocalPasswordHandler) Test(org.junit.Test)

Example 67 with SecurityContext

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);
}
Also used : Response(javax.ws.rs.core.Response) PasswordResetParam(com.emc.storageos.model.password.PasswordResetParam) SecurityContext(javax.ws.rs.core.SecurityContext) Test(org.junit.Test)

Example 68 with SecurityContext

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());
}
Also used : Response(javax.ws.rs.core.Response) PasswordResetParam(com.emc.storageos.model.password.PasswordResetParam) SecurityContext(javax.ws.rs.core.SecurityContext) LocalPasswordHandler(com.emc.storageos.systemservices.impl.util.LocalPasswordHandler) Test(org.junit.Test)

Example 69 with SecurityContext

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);
}
Also used : Response(javax.ws.rs.core.Response) PasswordResetParam(com.emc.storageos.model.password.PasswordResetParam) SecurityContext(javax.ws.rs.core.SecurityContext) LocalPasswordHandler(com.emc.storageos.systemservices.impl.util.LocalPasswordHandler) Test(org.junit.Test)

Example 70 with SecurityContext

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");
                }
            }
        }
    }
}
Also used : SecurityContext(javax.ws.rs.core.SecurityContext) IbisContext(nl.nn.adapterframework.configuration.IbisContext) MockServletContext(org.springframework.mock.web.MockServletContext) Context(javax.ws.rs.core.Context) Field(java.lang.reflect.Field) Request(javax.ws.rs.core.Request) SecurityContext(javax.ws.rs.core.SecurityContext)

Aggregations

SecurityContext (javax.ws.rs.core.SecurityContext)77 Response (javax.ws.rs.core.Response)30 Context (javax.ws.rs.core.Context)18 Test (org.junit.Test)18 List (java.util.List)17 Principal (java.security.Principal)16 LoggerFactory (org.slf4j.LoggerFactory)16 Logger (org.slf4j.Logger)12 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)11 Path (javax.ws.rs.Path)11 IOException (java.io.IOException)10 POST (javax.ws.rs.POST)8 LocalPasswordHandler (com.emc.storageos.systemservices.impl.util.LocalPasswordHandler)6 GET (javax.ws.rs.GET)6 PathParam (javax.ws.rs.PathParam)6 Produces (javax.ws.rs.Produces)6 MediaType (javax.ws.rs.core.MediaType)6 Status (javax.ws.rs.core.Response.Status)6 UriInfo (javax.ws.rs.core.UriInfo)6