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();
}
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();
}
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());
}
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();
}
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();
}
Aggregations