Search in sources :

Example 16 with RolesAllowed

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();
}
Also used : Appender(org.apache.log4j.Appender) Level(org.apache.log4j.Level) LogLevel(org.apache.log4j.lf5.LogLevel) Logger(org.apache.log4j.Logger) IbisAppenderWrapper(nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 17 with RolesAllowed

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);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 18 with RolesAllowed

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();
}
Also used : Locale(java.util.Locale) AnswerFormatter(org.openhab.ui.habot.nlp.internal.AnswerFormatter) ChatReply(org.openhab.ui.habot.nlp.ChatReply) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 19 with RolesAllowed

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();
        }
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) RolesAllowed(javax.annotation.security.RolesAllowed) SecurityContext(javax.ws.rs.core.SecurityContext) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Annotation(java.lang.annotation.Annotation)

Example 20 with RolesAllowed

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);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) DomainPrincipal(org.wildfly.extension.camel.security.DomainPrincipal) EncodedUsernamePasswordPrincipal(org.wildfly.extension.camel.security.EncodedUsernamePasswordPrincipal) Subject(javax.security.auth.Subject) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

RolesAllowed (javax.annotation.security.RolesAllowed)191 Path (javax.ws.rs.Path)127 Produces (javax.ws.rs.Produces)110 Consumes (javax.ws.rs.Consumes)55 GET (javax.ws.rs.GET)54 POST (javax.ws.rs.POST)40 PUT (javax.ws.rs.PUT)35 HashMap (java.util.HashMap)34 ArrayList (java.util.ArrayList)32 IOException (java.io.IOException)30 ApiOperation (io.swagger.annotations.ApiOperation)29 ApiResponses (io.swagger.annotations.ApiResponses)29 Response (javax.ws.rs.core.Response)28 Adapter (nl.nn.adapterframework.core.Adapter)21 DELETE (javax.ws.rs.DELETE)19 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)19 LinkedHashMap (java.util.LinkedHashMap)16 Locale (java.util.Locale)16 Map (java.util.Map)12 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)12