Search in sources :

Example 6 with PermitAll

use of javax.annotation.security.PermitAll in project traccar by tananaev.

the class SessionResource method add.

@PermitAll
@POST
public User add(@FormParam("email") String email, @FormParam("password") String password) throws StorageException {
    User user = Context.getPermissionsManager().login(email, password);
    if (user != null) {
        request.getSession().setAttribute(USER_ID_KEY, user.getId());
        LogAction.login(user.getId());
        return user;
    } else {
        LogAction.failedLogin(ServletHelper.retrieveRemoteAddress(request));
        throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
    }
}
Also used : User(org.traccar.model.User) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 7 with PermitAll

use of javax.annotation.security.PermitAll in project irontest by zheng-wang.

the class FolderResource method importTestcase.

@POST
@Path("{folderId}/importTestcase")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@PermitAll
public Testcase importTestcase(@PathParam("folderId") long folderId, @FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    Testcase testcase = objectMapper.readValue(inputStream, Testcase.class);
    long testcaseId = testcaseDAO.createByImport(testcase, folderId);
    Testcase result = new Testcase();
    result.setId(testcaseId);
    return result;
}
Also used : Testcase(io.irontest.models.Testcase) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PermitAll(javax.annotation.security.PermitAll)

Example 8 with PermitAll

use of javax.annotation.security.PermitAll in project irontest by zheng-wang.

the class TeststepResource method run.

/**
 * Run a test step individually (not as part of test case running).
 * This is a stateless operation, i.e. not persisting anything in database.
 * @param teststep
 * @return
 */
@POST
@Path("{teststepId}/run")
@PermitAll
public BasicTeststepRun run(Teststep teststep) throws Exception {
    // fetch request binary if its type is file
    if (teststep.getRequestType() == TeststepRequestType.FILE) {
        teststep.setRequest(teststepDAO.getBinaryRequestById(teststep.getId()));
    }
    // fetch API request binary if its type is file
    if (Teststep.TYPE_FTP.equals(teststep.getType()) && teststep.getApiRequest() instanceof FtpPutRequestFileFromFile) {
        teststep.setApiRequest(teststepDAO.getAPIRequestById(teststep.getId()));
    }
    // gather referenceable string properties and endpoint properties
    List<UserDefinedProperty> testcaseUDPs = udpDAO.findByTestcaseId(teststep.getTestcaseId());
    Map<String, String> referenceableStringProperties = IronTestUtils.udpListToMap(testcaseUDPs);
    referenceableStringProperties.put(IMPLICIT_PROPERTY_NAME_TEST_STEP_START_TIME, IMPLICIT_PROPERTY_DATE_TIME_FORMAT.format(new Date()));
    DataTable dataTable = dataTableDAO.getTestcaseDataTable(teststep.getTestcaseId(), true);
    Map<String, Endpoint> referenceableEndpointProperties = new HashMap<>();
    if (dataTable.getRows().size() > 0) {
        IronTestUtils.checkDuplicatePropertyNameBetweenDataTableAndUPDs(referenceableStringProperties.keySet(), dataTable);
        referenceableStringProperties.putAll(dataTable.getStringPropertiesInRow(0));
        referenceableEndpointProperties.putAll(dataTable.getEndpointPropertiesInRow(0));
    }
    // run the test step
    TeststepRunner teststepRunner = TeststepRunnerFactory.getInstance().newTeststepRunner(teststep, utilsDAO, referenceableStringProperties, referenceableEndpointProperties, null);
    BasicTeststepRun basicTeststepRun = teststepRunner.run();
    // for better display in browser, transform JSON/XML response to be pretty-printed
    switch(teststep.getType()) {
        case Teststep.TYPE_SOAP:
            HTTPAPIResponse soapAPIResponse = (HTTPAPIResponse) basicTeststepRun.getResponse();
            soapAPIResponse.setHttpBody(XMLUtils.prettyPrintXML(soapAPIResponse.getHttpBody()));
            break;
        case Teststep.TYPE_HTTP:
            HTTPAPIResponse httpAPIResponse = (HTTPAPIResponse) basicTeststepRun.getResponse();
            httpAPIResponse.setHttpBody(IronTestUtils.prettyPrintJSONOrXML(httpAPIResponse.getHttpBody()));
            break;
        case Teststep.TYPE_MQ:
            if (Teststep.ACTION_DEQUEUE.equals(teststep.getAction())) {
                MQDequeueResponse mqDequeueResponse = (MQDequeueResponse) basicTeststepRun.getResponse();
                if (mqDequeueResponse != null) {
                    mqDequeueResponse.setBodyAsText(IronTestUtils.prettyPrintJSONOrXML(mqDequeueResponse.getBodyAsText()));
                    if (mqDequeueResponse.getMqrfh2Header() != null) {
                        for (MQRFH2Folder mqrfh2Folder : mqDequeueResponse.getMqrfh2Header().getFolders()) {
                            mqrfh2Folder.setString(IronTestUtils.prettyPrintJSONOrXML(mqrfh2Folder.getString()));
                        }
                    }
                }
            }
            break;
        default:
            break;
    }
    return basicTeststepRun;
}
Also used : DataTable(io.irontest.models.DataTable) UserDefinedProperty(io.irontest.models.UserDefinedProperty) HashMap(java.util.HashMap) Date(java.util.Date) Endpoint(io.irontest.models.endpoint.Endpoint) PermitAll(javax.annotation.security.PermitAll)

Example 9 with PermitAll

use of javax.annotation.security.PermitAll in project irontest by zheng-wang.

the class TeststepResource method update.

@PUT
@Path("{teststepId}")
@PermitAll
@JsonView(ResourceJsonViews.TeststepEdit.class)
public TeststepWrapper update(Teststep teststep) throws Exception {
    // Restore otherProperties from system database for existing JSONValidAgainstJSONSchema or XMLValidAgainstXSD
    // assertions, as they are not supposed to be updated through this API (currently used for UI only).
    // Without this code, whenever a new JSONValidAgainstJSONSchema or XMLValidAgainstXSD assertion is added, or an
    // existing JSONValidAgainstJSONSchema or XMLValidAgainstXSD assertion is deleted, all existing
    // JSONValidAgainstJSONSchema or XMLValidAgainstXSD assertions in the same test step will see their
    // otherProperties.fileBytes set to null in system database.
    List<Assertion> assertions = teststep.getAssertions();
    for (Assertion assertion : assertions) {
        if (assertion.getId() != null && (Assertion.TYPE_JSON_VALID_AGAINST_JSON_SCHEMA.endsWith(assertion.getType()) || Assertion.TYPE_XML_VALID_AGAINST_XSD.endsWith(assertion.getType()))) {
            assertion.setOtherProperties(assertionDAO.findById(assertion.getId()).getOtherProperties());
        }
    }
    teststepDAO.update(teststep);
    TeststepWrapper wrapper = new TeststepWrapper();
    Teststep newTeststep = teststep.getRequestType() == TeststepRequestType.FILE ? teststepDAO.findById_NoRequest(teststep.getId()) : teststepDAO.findById_Complete(teststep.getId());
    wrapper.setTeststep(newTeststep);
    populateParametersInWrapper(wrapper);
    return wrapper;
}
Also used : Assertion(io.irontest.models.assertion.Assertion) JsonView(com.fasterxml.jackson.annotation.JsonView) PermitAll(javax.annotation.security.PermitAll)

Example 10 with PermitAll

use of javax.annotation.security.PermitAll in project irontest by zheng-wang.

the class EnvironmentResource method create.

@POST
@Path("environments")
@PermitAll
public Environment create() {
    Environment result = new Environment();
    result.setId(environmentDAO.insert());
    return result;
}
Also used : Environment(io.irontest.models.Environment) PermitAll(javax.annotation.security.PermitAll)

Aggregations

PermitAll (javax.annotation.security.PermitAll)36 ArrayList (java.util.ArrayList)8 User (org.traccar.model.User)8 POST (javax.ws.rs.POST)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 HashMap (java.util.HashMap)5 RolesAllowed (javax.annotation.security.RolesAllowed)5 DataTable (io.irontest.models.DataTable)4 UserDefinedProperty (io.irontest.models.UserDefinedProperty)4 Date (java.util.Date)4 Produces (javax.ws.rs.Produces)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Catalog (org.rembx.jeeshop.catalog.model.Catalog)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Testcase (io.irontest.models.Testcase)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 JsonView (com.fasterxml.jackson.annotation.JsonView)2 Environment (io.irontest.models.Environment)2