Search in sources :

Example 11 with Metered

use of com.codahale.metrics.annotation.Metered in project cas by apereo.

the class DefaultCentralAuthenticationService method createTicketGrantingTicket.

@Audit(action = "TICKET_GRANTING_TICKET", actionResolverName = "CREATE_TICKET_GRANTING_TICKET_RESOLVER", resourceResolverName = "CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "CREATE_TICKET_GRANTING_TICKET_TIMER")
@Metered(name = "CREATE_TICKET_GRANTING_TICKET_METER")
@Counted(name = "CREATE_TICKET_GRANTING_TICKET_COUNTER", monotonic = true)
@Override
public TicketGrantingTicket createTicketGrantingTicket(final AuthenticationResult authenticationResult) throws AuthenticationException, AbstractTicketException {
    final Authentication authentication = authenticationResult.getAuthentication();
    final Service service = authenticationResult.getService();
    AuthenticationCredentialsLocalBinder.bindCurrent(authentication);
    if (service != null) {
        final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
        RegisteredServiceAccessStrategyUtils.ensurePrincipalAccessIsAllowedForService(service, registeredService, authentication);
    }
    final TicketGrantingTicketFactory factory = this.ticketFactory.get(TicketGrantingTicket.class);
    final TicketGrantingTicket ticketGrantingTicket = factory.create(authentication);
    this.ticketRegistry.addTicket(ticketGrantingTicket);
    doPublishEvent(new CasTicketGrantingTicketCreatedEvent(this, ticketGrantingTicket));
    return ticketGrantingTicket;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) CasTicketGrantingTicketCreatedEvent(org.apereo.cas.support.events.ticket.CasTicketGrantingTicketCreatedEvent) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) TicketGrantingTicketFactory(org.apereo.cas.ticket.TicketGrantingTicketFactory) Audit(org.apereo.inspektr.audit.annotation.Audit) Counted(com.codahale.metrics.annotation.Counted) Metered(com.codahale.metrics.annotation.Metered) Timed(com.codahale.metrics.annotation.Timed)

Example 12 with Metered

use of com.codahale.metrics.annotation.Metered in project cas by apereo.

the class DefaultCentralAuthenticationService method createProxyGrantingTicket.

@Audit(action = "PROXY_GRANTING_TICKET", actionResolverName = "CREATE_PROXY_GRANTING_TICKET_RESOLVER", resourceResolverName = "CREATE_PROXY_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "CREATE_PROXY_GRANTING_TICKET_TIMER")
@Metered(name = "CREATE_PROXY_GRANTING_TICKET_METER")
@Counted(name = "CREATE_PROXY_GRANTING_TICKET_COUNTER", monotonic = true)
@Override
public ProxyGrantingTicket createProxyGrantingTicket(final String serviceTicketId, final AuthenticationResult authenticationResult) throws AuthenticationException, AbstractTicketException {
    AuthenticationCredentialsLocalBinder.bindCurrent(authenticationResult.getAuthentication());
    final ServiceTicket serviceTicket = this.ticketRegistry.getTicket(serviceTicketId, ServiceTicket.class);
    if (serviceTicket == null || serviceTicket.isExpired()) {
        LOGGER.debug("ServiceTicket [{}] has expired or cannot be found in the ticket registry", serviceTicketId);
        throw new InvalidTicketException(serviceTicketId);
    }
    final RegisteredService registeredService = this.servicesManager.findServiceBy(serviceTicket.getService());
    RegisteredServiceAccessStrategyUtils.ensurePrincipalAccessIsAllowedForService(serviceTicket, authenticationResult, registeredService);
    if (!registeredService.getProxyPolicy().isAllowedToProxy()) {
        LOGGER.warn("ServiceManagement: Service [{}] attempted to proxy, but is not allowed.", serviceTicket.getService().getId());
        throw new UnauthorizedProxyingException();
    }
    final Authentication authentication = authenticationResult.getAuthentication();
    final ProxyGrantingTicketFactory factory = this.ticketFactory.get(ProxyGrantingTicket.class);
    final ProxyGrantingTicket proxyGrantingTicket = factory.create(serviceTicket, authentication);
    LOGGER.debug("Generated proxy granting ticket [{}] based off of [{}]", proxyGrantingTicket, serviceTicketId);
    this.ticketRegistry.addTicket(proxyGrantingTicket);
    doPublishEvent(new CasProxyGrantingTicketCreatedEvent(this, proxyGrantingTicket));
    return proxyGrantingTicket;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) CasProxyGrantingTicketCreatedEvent(org.apereo.cas.support.events.ticket.CasProxyGrantingTicketCreatedEvent) UnauthorizedProxyingException(org.apereo.cas.services.UnauthorizedProxyingException) ProxyGrantingTicketFactory(org.apereo.cas.ticket.proxy.ProxyGrantingTicketFactory) Audit(org.apereo.inspektr.audit.annotation.Audit) Counted(com.codahale.metrics.annotation.Counted) Metered(com.codahale.metrics.annotation.Metered) Timed(com.codahale.metrics.annotation.Timed)

Example 13 with Metered

use of com.codahale.metrics.annotation.Metered in project metrics by dropwizard.

the class InstrumentedResourceMethodDispatchProvider method create.

@Override
public RequestDispatcher create(AbstractResourceMethod method) {
    RequestDispatcher dispatcher = provider.create(method);
    if (dispatcher == null) {
        return null;
    }
    if (method.getMethod().isAnnotationPresent(Timed.class)) {
        final Timed annotation = method.getMethod().getAnnotation(Timed.class);
        final String name = chooseName(annotation.name(), annotation.absolute(), method);
        final Timer timer = registry.timer(name);
        dispatcher = new TimedRequestDispatcher(dispatcher, timer);
    }
    if (method.getMethod().isAnnotationPresent(Metered.class)) {
        final Metered annotation = method.getMethod().getAnnotation(Metered.class);
        final String name = chooseName(annotation.name(), annotation.absolute(), method);
        final Meter meter = registry.meter(name);
        dispatcher = new MeteredRequestDispatcher(dispatcher, meter);
    }
    if (method.getMethod().isAnnotationPresent(ExceptionMetered.class)) {
        final ExceptionMetered annotation = method.getMethod().getAnnotation(ExceptionMetered.class);
        final String name = chooseName(annotation.name(), annotation.absolute(), method, ExceptionMetered.DEFAULT_NAME_SUFFIX);
        final Meter meter = registry.meter(name);
        dispatcher = new ExceptionMeteredRequestDispatcher(dispatcher, meter, annotation.cause());
    }
    return dispatcher;
}
Also used : Metered(com.codahale.metrics.annotation.Metered) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) RequestDispatcher(com.sun.jersey.spi.dispatch.RequestDispatcher)

Aggregations

Metered (com.codahale.metrics.annotation.Metered)13 Timed (com.codahale.metrics.annotation.Timed)12 Counted (com.codahale.metrics.annotation.Counted)9 Audit (org.apereo.inspektr.audit.annotation.Audit)7 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)6 Authentication (org.apereo.cas.authentication.Authentication)5 RegisteredService (org.apereo.cas.services.RegisteredService)5 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)4 Principal (org.apereo.cas.authentication.principal.Principal)4 ServiceContext (org.apereo.cas.services.ServiceContext)3 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)3 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)3 Method (java.lang.reflect.Method)2 Service (org.apereo.cas.authentication.principal.Service)2 Ticket (org.apereo.cas.ticket.Ticket)2 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)2 ResourceMethod (org.glassfish.jersey.server.model.ResourceMethod)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Meter (com.codahale.metrics.Meter)1 Timer (com.codahale.metrics.Timer)1