Search in sources :

Example 26 with PermitAll

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

the class PasswordResource method reset.

@Path("reset")
@PermitAll
@POST
public Response reset(@FormParam("email") String email) throws StorageException, MessagingException {
    for (long userId : Context.getUsersManager().getAllItems()) {
        User user = Context.getUsersManager().getById(userId);
        if (email.equals(user.getEmail())) {
            String token = UUID.randomUUID().toString().replaceAll("-", "");
            user.set(PASSWORD_RESET_TOKEN, token);
            Context.getUsersManager().updateItem(user);
            VelocityContext velocityContext = TextTemplateFormatter.prepareContext(null);
            velocityContext.put("token", token);
            NotificationMessage fullMessage = TextTemplateFormatter.formatMessage(velocityContext, "passwordReset", "full");
            Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody());
            break;
        }
    }
    return Response.ok().build();
}
Also used : User(org.traccar.model.User) NotificationMessage(org.traccar.notification.NotificationMessage) VelocityContext(org.apache.velocity.VelocityContext) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 27 with PermitAll

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

the class HTTPStubResource method loadAll.

@POST
@Path("testcases/{testcaseId}/httpstubs/loadAll")
@PermitAll
public void loadAll(@PathParam("testcaseId") long testcaseId) throws IOException {
    // gather referenceable string properties
    List<UserDefinedProperty> testcaseUDPs = udpDAO.findByTestcaseId(testcaseId);
    Map<String, String> referenceableStringProperties = IronTestUtils.udpListToMap(testcaseUDPs);
    DataTable dataTable = dataTableDAO.getTestcaseDataTable(testcaseId, true);
    if (dataTable.getRows().size() > 0) {
        IronTestUtils.checkDuplicatePropertyNameBetweenDataTableAndUPDs(referenceableStringProperties.keySet(), dataTable);
        referenceableStringProperties.putAll(dataTable.getStringPropertiesInRow(0));
    }
    List<HTTPStubMapping> stubs = httpStubMappingDAO.findByTestcaseId(testcaseId);
    // resolve string property references in HTTPStubMapping objects
    List<String> undefinedStringProperties = new ArrayList<>();
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
    IronTestUtils.addMixInsForWireMock(objectMapper);
    String httpStubMappingsJSON = objectMapper.writeValueAsString(stubs);
    MapValueLookup propertyReferenceResolver = new MapValueLookup(referenceableStringProperties, true);
    String resolvedHttpStubMappingsJSON = new StrSubstitutor(propertyReferenceResolver).replace(httpStubMappingsJSON);
    stubs = objectMapper.readValue(resolvedHttpStubMappingsJSON, new TypeReference<List<HTTPStubMapping>>() {
    });
    undefinedStringProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
    if (!undefinedStringProperties.isEmpty()) {
        throw new RuntimeException("String properties " + undefinedStringProperties + " not defined.");
    }
    IronTestUtils.substituteRequestBodyMainPatternValue(stubs);
    // load stubs
    final List<HTTPStubMapping> finalStubs = stubs;
    wireMockServer.loadMappingsUsing(stubMappings -> {
        for (HTTPStubMapping stub : finalStubs) {
            // delete old instances if exist
            List<StubMapping> existingInstances = wireMockServer.findStubMappingsByMetadata(matchingJsonPath("$." + WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_ID, equalTo(Long.toString(stub.getId()))));
            for (StubMapping existingInstance : existingInstances) {
                wireMockServer.removeStubMapping(existingInstance);
            }
            StubMapping stubInstance = IronTestUtils.createStubInstance(stub.getId(), stub.getNumber(), stub.getSpec());
            stubMappings.addMapping(stubInstance);
        }
    });
}
Also used : DataTable(io.irontest.models.DataTable) UserDefinedProperty(io.irontest.models.UserDefinedProperty) ArrayList(java.util.ArrayList) HTTPStubMapping(io.irontest.models.HTTPStubMapping) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) HTTPStubMapping(io.irontest.models.HTTPStubMapping) StrSubstitutor(org.apache.commons.text.StrSubstitutor) MapValueLookup(io.irontest.core.MapValueLookup) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WireMock.matchingJsonPath(com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath) PermitAll(javax.annotation.security.PermitAll)

Example 28 with PermitAll

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

the class TestcaseResource method duplicate.

/**
 * Clone/copy test case in the same system database.
 * @param testcaseId
 * @param targetFolderId
 * @return the new test case (containing ID only)
 */
@POST
@Path("testcases/{testcaseId}/duplicate")
@PermitAll
public Testcase duplicate(@PathParam("testcaseId") long testcaseId, @QueryParam("targetFolderId") long targetFolderId) {
    Testcase testcase = new Testcase();
    testcase.setId(testcaseDAO.duplicate(testcaseId, targetFolderId));
    return testcase;
}
Also used : Testcase(io.irontest.models.Testcase) PermitAll(javax.annotation.security.PermitAll)

Example 29 with PermitAll

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

the class UserResource method updatePassword.

@PUT
@Path("{userId}/password")
@PermitAll
public void updatePassword(@PathParam("userId") long userId, @QueryParam("newPassword") String newPassword, @Context SecurityContext context) {
    SimplePrincipal principal = (SimplePrincipal) context.getUserPrincipal();
    User user = userDAO.findByUsername(principal.getName());
    if (user.getId() == userId) {
        userDAO.updatePassword(userId, newPassword);
    } else {
        throw new RuntimeException("You can't change other user's password.");
    }
}
Also used : User(io.irontest.models.User) SimplePrincipal(io.irontest.auth.SimplePrincipal) PermitAll(javax.annotation.security.PermitAll)

Example 30 with PermitAll

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

the class ManagedEndpointResource method create.

@POST
@Path("environments/{environmentId}/endpoints")
@PermitAll
public Endpoint create(@PathParam("environmentId") long environmentId, Endpoint endpoint) {
    Environment env = new Environment();
    env.setId(environmentId);
    endpoint.setEnvironment(env);
    if (Endpoint.TYPE_SOAP.equals(endpoint.getType())) {
        endpoint.setOtherProperties(new SOAPEndpointProperties());
    } else if (Endpoint.TYPE_FTP.equals(endpoint.getType())) {
        endpoint.setOtherProperties(new FTPEndpointProperties());
    } else if (Endpoint.TYPE_MQ.equals(endpoint.getType())) {
        MQEndpointProperties otherProperties = new MQEndpointProperties();
        otherProperties.setConnectionMode(appInfo.getAppMode() == AppMode.LOCAL ? MQConnectionMode.BINDINGS : MQConnectionMode.CLIENT);
        endpoint.setOtherProperties(otherProperties);
    } else if (Endpoint.TYPE_IIB.equals(endpoint.getType())) {
        endpoint.setOtherProperties(new IIBEndpointProperties());
    }
    long id = endpointDAO.insertManagedEndpoint(endpoint);
    endpoint.setId(id);
    return endpoint;
}
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