Search in sources :

Example 21 with PermitAll

use of javax.annotation.security.PermitAll in project iaf by ibissource.

the class ServerStatistics method getLogConfiguration.

@GET
@PermitAll
@Path("/server/log")
@Produces(MediaType.APPLICATION_JSON)
public Response getLogConfiguration() throws ApiException {
    Map<String, Object> logSettings = new HashMap<String, Object>(3);
    Logger rootLogger = LogUtil.getRootLogger();
    Appender appender = rootLogger.getAppender("appwrap");
    IbisAppenderWrapper iaw = null;
    if (appender != null && appender instanceof IbisAppenderWrapper) {
        iaw = (IbisAppenderWrapper) appender;
        logSettings.put("maxMessageLength", iaw.getMaxMessageLength());
    } else {
        logSettings.put("maxMessageLength", -1);
    }
    List<String> errorLevels = new ArrayList<String>(Arrays.asList("DEBUG", "INFO", "WARN", "ERROR"));
    logSettings.put("errorLevels", errorLevels);
    for (Iterator<String> iterator = errorLevels.iterator(); iterator.hasNext(); ) {
        String level = iterator.next();
        if (rootLogger.getLevel() == Level.toLevel(level))
            logSettings.put("loglevel", level);
    }
    logSettings.put("logIntermediaryResults", AppConstants.getInstance().getBoolean("log.logIntermediaryResults", true));
    return Response.status(Response.Status.CREATED).entity(logSettings).build();
}
Also used : Appender(org.apache.log4j.Appender) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) IbisAppenderWrapper(nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 22 with PermitAll

use of javax.annotation.security.PermitAll in project iaf by ibissource.

the class ServerStatistics method getServerConfiguration.

@GET
@PermitAll
@Path("/server/warnings")
@Produces(MediaType.APPLICATION_JSON)
public Response getServerConfiguration() throws ApiException {
    initBase(servletConfig);
    ConfigurationWarnings globalConfigWarnings = ConfigurationWarnings.getInstance();
    // (globalConfigWarnings.size() + 1); //Add 1 for ESR
    List<Object> warnings = new ArrayList<Object>();
    boolean showCountErrorStore = AppConstants.getInstance().getBoolean("errorStore.count.show", true);
    List<IAdapter> registeredAdapters = ibisManager.getRegisteredAdapters();
    long esr = 0;
    if (showCountErrorStore) {
        for (Iterator<IAdapter> adapterIt = registeredAdapters.iterator(); adapterIt.hasNext(); ) {
            Adapter adapter = (Adapter) adapterIt.next();
            for (Iterator<?> receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
                ReceiverBase receiver = (ReceiverBase) receiverIt.next();
                ITransactionalStorage errorStorage = receiver.getErrorStorage();
                if (errorStorage != null) {
                    try {
                        esr += errorStorage.getMessageCount();
                    } catch (Exception e) {
                        // error("error occured on getting number of errorlog records for adapter ["+adapter.getName()+"]",e);
                        log.warn("Assuming there are no errorlog records for adapter [" + adapter.getName() + "]");
                    }
                }
            }
        }
    } else {
        esr = -1;
    }
    if (esr != 0) {
        Map<String, Object> messageObj = new HashMap<String, Object>(2);
        String message;
        if (esr == -1) {
            message = "Errorlog might contain records. This is unknown because errorStore.count.show is not set to true";
        } else if (esr == 1) {
            message = "Errorlog contains 1 record. Service management should check whether this record has to be resent or deleted";
        } else {
            message = "Errorlog contains " + esr + " records. Service Management should check whether these records have to be resent or deleted";
        }
        messageObj.put("message", message);
        messageObj.put("type", "severe");
        warnings.add(messageObj);
    }
    for (Configuration config : ibisManager.getConfigurations()) {
        if (config.getConfigurationException() != null) {
            Map<String, Object> messageObj = new HashMap<String, Object>(2);
            String message = config.getConfigurationException().getMessage();
            messageObj.put("message", message);
            messageObj.put("type", "exception");
            warnings.add(messageObj);
        }
    }
    // Configuration specific warnings
    for (Configuration configuration : ibisManager.getConfigurations()) {
        BaseConfigurationWarnings configWarns = configuration.getConfigurationWarnings();
        for (int j = 0; j < configWarns.size(); j++) {
            Map<String, Object> messageObj = new HashMap<String, Object>(1);
            messageObj.put("message", configWarns.get(j));
            messageObj.put("configuration", configuration.getName());
            warnings.add(messageObj);
        }
    }
    // Global warnings
    if (globalConfigWarnings.size() > 0) {
        for (int j = 0; j < globalConfigWarnings.size(); j++) {
            Map<String, Object> messageObj = new HashMap<String, Object>(1);
            messageObj.put("message", globalConfigWarnings.get(j));
            warnings.add(messageObj);
        }
    }
    return Response.status(Response.Status.CREATED).entity(warnings).build();
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) BaseConfigurationWarnings(nl.nn.adapterframework.configuration.BaseConfigurationWarnings) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) IAdapter(nl.nn.adapterframework.core.IAdapter) BaseConfigurationWarnings(nl.nn.adapterframework.configuration.BaseConfigurationWarnings) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 23 with PermitAll

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

the class SessionResource method get.

@PermitAll
@GET
public User get(@QueryParam("token") String token) throws StorageException, UnsupportedEncodingException {
    if (token != null) {
        User user = Context.getUsersManager().getUserByToken(token);
        if (user != null) {
            Context.getPermissionsManager().checkUserEnabled(user.getId());
            request.getSession().setAttribute(USER_ID_KEY, user.getId());
            return user;
        }
    }
    Long userId = (Long) request.getSession().getAttribute(USER_ID_KEY);
    if (userId == null) {
        Cookie[] cookies = request.getCookies();
        String email = null, password = null;
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals(USER_COOKIE_KEY)) {
                    byte[] emailBytes = DataConverter.parseBase64(URLDecoder.decode(cookie.getValue(), StandardCharsets.US_ASCII.name()));
                    email = new String(emailBytes, StandardCharsets.UTF_8);
                } else if (cookie.getName().equals(PASS_COOKIE_KEY)) {
                    byte[] passwordBytes = DataConverter.parseBase64(URLDecoder.decode(cookie.getValue(), StandardCharsets.US_ASCII.name()));
                    password = new String(passwordBytes, StandardCharsets.UTF_8);
                }
            }
        }
        if (email != null && password != null) {
            User user = Context.getPermissionsManager().login(email, password);
            if (user != null) {
                Context.getPermissionsManager().checkUserEnabled(user.getId());
                request.getSession().setAttribute(USER_ID_KEY, user.getId());
                return user;
            }
        }
    } else {
        Context.getPermissionsManager().checkUserEnabled(userId);
        return Context.getPermissionsManager().getUser(userId);
    }
    throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
}
Also used : Cookie(javax.servlet.http.Cookie) User(org.traccar.model.User) WebApplicationException(javax.ws.rs.WebApplicationException) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 24 with PermitAll

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

the class UserResource method add.

@Override
@PermitAll
@POST
public Response add(User entity) throws StorageException {
    if (!Context.getPermissionsManager().getUserAdmin(getUserId())) {
        Context.getPermissionsManager().checkUserUpdate(getUserId(), new User(), entity);
        if (Context.getPermissionsManager().getUserManager(getUserId())) {
            Context.getPermissionsManager().checkUserLimit(getUserId());
        } else {
            Context.getPermissionsManager().checkRegistration(getUserId());
            entity.setDeviceLimit(Context.getConfig().getInteger(Keys.USERS_DEFAULT_DEVICE_LIMIT));
            int expirationDays = Context.getConfig().getInteger(Keys.USERS_DEFAULT_EXPIRATION_DAYS);
            if (expirationDays > 0) {
                entity.setExpirationTime(new Date(System.currentTimeMillis() + (long) expirationDays * 24 * 3600 * 1000));
            }
        }
    }
    Context.getUsersManager().addItem(entity);
    LogAction.create(getUserId(), entity);
    if (Context.getPermissionsManager().getUserManager(getUserId())) {
        Context.getDataManager().linkObject(User.class, getUserId(), ManagedUser.class, entity.getId(), true);
        LogAction.link(getUserId(), User.class, getUserId(), ManagedUser.class, entity.getId());
    }
    Context.getUsersManager().refreshUserItems();
    return Response.ok(entity).build();
}
Also used : ManagedUser(org.traccar.model.ManagedUser) User(org.traccar.model.User) Date(java.util.Date) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 25 with PermitAll

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

the class PasswordResource method update.

@Path("update")
@PermitAll
@POST
public Response update(@FormParam("token") String token, @FormParam("password") String password) throws StorageException {
    for (long userId : Context.getUsersManager().getAllItems()) {
        User user = Context.getUsersManager().getById(userId);
        if (token.equals(user.getString(PASSWORD_RESET_TOKEN))) {
            user.getAttributes().remove(PASSWORD_RESET_TOKEN);
            user.setPassword(password);
            Context.getUsersManager().updateItem(user);
            return Response.ok().build();
        }
    }
    return Response.status(Response.Status.NOT_FOUND).build();
}
Also used : User(org.traccar.model.User) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) 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