use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ServerStatistics method updateLogConfiguration.
@PUT
@RolesAllowed({ "IbisAdmin", "IbisTester" })
@Path("/server/log")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateLogConfiguration(LinkedHashMap<String, Object> json) throws ApiException {
initBase(servletConfig);
Level loglevel = null;
Boolean logIntermediaryResults = true;
int maxMessageLength = -1;
StringBuilder msg = new StringBuilder();
Logger rootLogger = LogUtil.getRootLogger();
Appender appender = rootLogger.getAppender("appwrap");
IbisAppenderWrapper iaw = null;
if (appender != null && appender instanceof IbisAppenderWrapper) {
iaw = (IbisAppenderWrapper) appender;
}
for (Entry<String, Object> entry : json.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key.equalsIgnoreCase("loglevel")) {
loglevel = Level.toLevel("" + value);
} else if (key.equalsIgnoreCase("logIntermediaryResults")) {
logIntermediaryResults = Boolean.parseBoolean("" + value);
} else if (key.equalsIgnoreCase("maxMessageLength")) {
maxMessageLength = Integer.parseInt("" + value);
}
}
if (loglevel != null && rootLogger.getLevel() != loglevel) {
rootLogger.setLevel(loglevel);
msg.append("LogLevel changed from [" + rootLogger.getLevel() + "] to [" + loglevel + "]");
}
boolean logIntermediary = AppConstants.getInstance().getBoolean("log.logIntermediaryResults", true);
if (logIntermediary != logIntermediaryResults) {
AppConstants.getInstance().put("log.logIntermediaryResults", "" + logIntermediaryResults);
if (msg.length() > 0)
msg.append(", logIntermediaryResults from [" + logIntermediary + "] to [" + logIntermediaryResults + "]");
else
msg.append("logIntermediaryResults changed from [" + logIntermediary + "] to [" + logIntermediaryResults + "]");
}
if (iaw != null) {
if (iaw.getMaxMessageLength() != maxMessageLength) {
if (msg.length() > 0)
msg.append(", logMaxMessageLength from [" + iaw.getMaxMessageLength() + "] to [" + maxMessageLength + "]");
else
msg.append("logMaxMessageLength changed from [" + iaw.getMaxMessageLength() + "] to [" + maxMessageLength + "]");
iaw.setMaxMessageLength(maxMessageLength);
}
}
if (msg.length() > 0) {
log.warn(msg.toString());
LogUtil.getLogger("SEC").info(msg.toString());
}
return Response.status(Response.Status.NO_CONTENT).build();
}
use of javax.annotation.security.RolesAllowed in project ART-TIME by Artezio.
the class NotificationManager method requestWorkTimeReport.
@Override
@RolesAllowed({ EXEC_ROLE, PM_ROLE, OFFICE_MANAGER })
public void requestWorkTimeReport(String recipientEmail, Period period) {
RequestReportMailBuilder mailBuilder = new RequestReportMailBuilder(mailTemplateManager);
Employee sender = employeeRepository.get(sessionContext.getCallerPrincipal().getName());
Mail mail = mailBuilder.setSenderEmailAddress(sender.getEmail()).setRecipientEmailAddress(recipientEmail).setPeriod(period).setAppHost(settings.getApplicationBaseUrl()).build();
mailingEngine.send(mail);
}
use of javax.annotation.security.RolesAllowed in project habot by ghys.
the class HABotResource method greet.
@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Path("/greet")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Retrieves a first greeting message from the bot in the specified or configured language.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ChatReply.class), @ApiResponse(code = 500, message = "There is no support for the configured language") })
public Response greet(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language (will use the default if omitted)") String language) {
final Locale locale = (this.localeProvider != null && this.localeProvider.getLocale() != null) ? this.localeProvider.getLocale() : LocaleUtil.getLocale(language);
AnswerFormatter answerFormatter = new AnswerFormatter(locale);
String greeting = answerFormatter.getRandomAnswer("greeting");
ChatReply reply = new ChatReply(locale);
reply.setAnswer(greeting);
return Response.ok(reply).build();
}
use of javax.annotation.security.RolesAllowed in project minijax by minijax.
the class MinijaxApplication method checkSecurity.
private void checkSecurity(final MinijaxRequestContext context) {
final Annotation a = context.getResourceMethod().getSecurityAnnotation();
if (a == null) {
return;
}
final Class<?> c = a.annotationType();
if (c == PermitAll.class) {
return;
}
if (c == DenyAll.class) {
throw new ForbiddenException();
}
if (c == RolesAllowed.class) {
final SecurityContext security = context.getSecurityContext();
if (security == null || security.getUserPrincipal() == null) {
throw new NotAuthorizedException(Response.status(Status.UNAUTHORIZED).build());
}
boolean found = false;
for (final String role : ((RolesAllowed) a).value()) {
if (security.isUserInRole(role)) {
found = true;
break;
}
}
if (!found) {
throw new ForbiddenException();
}
}
}
use of javax.annotation.security.RolesAllowed in project wildfly-camel by wildfly-extras.
the class AnnotatedSLSB method secureRouteAccess.
@RolesAllowed({ "Role2" })
public String secureRouteAccess(String msg) {
// [TODO #725] Add support for security context propagation
Subject subject = new Subject();
String username = ejbctx.getCallerPrincipal().getName();
subject.getPrincipals().add(new DomainPrincipal("user-domain"));
subject.getPrincipals().add(new EncodedUsernamePasswordPrincipal(username, PASSWORD.toCharArray()));
ProducerTemplate producer = camelctx.createProducerTemplate();
return producer.requestBodyAndHeader("direct:start", msg, Exchange.AUTHENTICATION, subject, String.class);
}
Aggregations