Search in sources :

Example 6 with Counted

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

the class DefaultCentralAuthenticationService method validateServiceTicket.

@Audit(action = "SERVICE_TICKET_VALIDATE", actionResolverName = "VALIDATE_SERVICE_TICKET_RESOLVER", resourceResolverName = "VALIDATE_SERVICE_TICKET_RESOURCE_RESOLVER")
@Timed(name = "VALIDATE_SERVICE_TICKET_TIMER")
@Metered(name = "VALIDATE_SERVICE_TICKET_METER")
@Counted(name = "VALIDATE_SERVICE_TICKET_COUNTER", monotonic = true)
@Override
public Assertion validateServiceTicket(final String serviceTicketId, final Service service) throws AbstractTicketException {
    if (!isTicketAuthenticityVerified(serviceTicketId)) {
        LOGGER.info("Service ticket [{}] is not a valid ticket issued by CAS.", serviceTicketId);
        throw new InvalidTicketException(serviceTicketId);
    }
    final ServiceTicket serviceTicket = this.ticketRegistry.getTicket(serviceTicketId, ServiceTicket.class);
    if (serviceTicket == null) {
        LOGGER.info("Service ticket [{}] does not exist.", serviceTicketId);
        throw new InvalidTicketException(serviceTicketId);
    }
    try {
        /*
             * Synchronization on ticket object in case of cache based registry doesn't serialize
             * access to critical section. The reason is that cache pulls serialized data and
             * builds new object, most likely for each pull. Is this synchronization needed here?
             */
        synchronized (serviceTicket) {
            if (serviceTicket.isExpired()) {
                LOGGER.info("ServiceTicket [{}] has expired.", serviceTicketId);
                throw new InvalidTicketException(serviceTicketId);
            }
            if (!serviceTicket.isValidFor(service)) {
                LOGGER.error("Service ticket [{}] with service [{}] does not match supplied service [{}]", serviceTicketId, serviceTicket.getService().getId(), service);
                throw new UnrecognizableServiceForServiceTicketValidationException(serviceTicket.getService());
            }
        }
        final Service selectedService = resolveServiceFromAuthenticationRequest(service);
        LOGGER.debug("Resolved service [{}] from the authentication request", selectedService);
        final RegisteredService registeredService = this.servicesManager.findServiceBy(selectedService);
        LOGGER.debug("Located registered service definition [{}] from [{}] to handle validation request", registeredService, selectedService);
        RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(selectedService, registeredService);
        final TicketGrantingTicket root = serviceTicket.getGrantingTicket().getRoot();
        final Authentication authentication = getAuthenticationSatisfiedByPolicy(root.getAuthentication(), new ServiceContext(selectedService, registeredService));
        final Principal principal = authentication.getPrincipal();
        final RegisteredServiceAttributeReleasePolicy attributePolicy = registeredService.getAttributeReleasePolicy();
        LOGGER.debug("Attribute policy [{}] is associated with service [{}]", attributePolicy, registeredService);
        @SuppressWarnings("unchecked") final Map<String, Object> attributesToRelease = attributePolicy != null ? attributePolicy.getAttributes(principal, registeredService) : new HashMap<>();
        final String principalId = registeredService.getUsernameAttributeProvider().resolveUsername(principal, selectedService);
        final Principal modifiedPrincipal = this.principalFactory.createPrincipal(principalId, attributesToRelease);
        final AuthenticationBuilder builder = DefaultAuthenticationBuilder.newInstance(authentication);
        builder.setPrincipal(modifiedPrincipal);
        final Authentication finalAuthentication = builder.build();
        AuthenticationCredentialsLocalBinder.bindCurrent(finalAuthentication);
        final Assertion assertion = new ImmutableAssertion(finalAuthentication, serviceTicket.getGrantingTicket().getChainedAuthentications(), selectedService, serviceTicket.isFromNewLogin());
        doPublishEvent(new CasServiceTicketValidatedEvent(this, serviceTicket, assertion));
        return assertion;
    } finally {
        if (serviceTicket.isExpired()) {
            this.ticketRegistry.deleteTicket(serviceTicketId);
        } else {
            this.ticketRegistry.updateTicket(serviceTicket);
        }
    }
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceContext(org.apereo.cas.services.ServiceContext) UnrecognizableServiceForServiceTicketValidationException(org.apereo.cas.ticket.UnrecognizableServiceForServiceTicketValidationException) Assertion(org.apereo.cas.validation.Assertion) ImmutableAssertion(org.apereo.cas.validation.ImmutableAssertion) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ImmutableAssertion(org.apereo.cas.validation.ImmutableAssertion) Authentication(org.apereo.cas.authentication.Authentication) CasServiceTicketValidatedEvent(org.apereo.cas.support.events.ticket.CasServiceTicketValidatedEvent) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) Principal(org.apereo.cas.authentication.principal.Principal) RegisteredServiceAttributeReleasePolicy(org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy) 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 7 with Counted

use of com.codahale.metrics.annotation.Counted in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordHateoasController method findOneBasicRecordBySystemId.

// API - All GET Requests (CRUD - READ)
@ApiOperation(value = "Retrieves a single BasicRecord entity given a systemId", response = BasicRecord.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "BasicRecord returned", response = BasicRecord.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.GET)
public ResponseEntity<BasicRecordHateoas> findOneBasicRecordBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the basicRecord to retrieve", required = true) @PathVariable("systemID") final String basicRecordSystemId) {
    BasicRecord createdBasicRecord = basicRecordService.findBySystemIdOrderBySystemId(basicRecordSystemId);
    BasicRecordHateoas basicRecordHateoas = new BasicRecordHateoas(createdBasicRecord);
    basicRecordHateoasHandler.addLinks(basicRecordHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdBasicRecord.getVersion().toString()).body(basicRecordHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 8 with Counted

use of com.codahale.metrics.annotation.Counted in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordHateoasController method findAllBasicRecord.

@ApiOperation(value = "Retrieves multiple BasicRecord entities limited by ownership rights", notes = "The field skip" + "tells how many BasicRecord rows of the result set to ignore (starting at 0), while  top tells how many rows" + " after skip to return. Note if the value of top is greater than system value " + " nikita-noark5-core.pagination.maxPageSize, then nikita-noark5-core.pagination.maxPageSize is used. ", response = BasicRecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "BasicRecord list found", response = BasicRecordHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<BasicRecordHateoas> findAllBasicRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip) {
    BasicRecordHateoas basicRecordHateoas = new BasicRecordHateoas((ArrayList<INikitaEntity>) (ArrayList) basicRecordService.findBasicRecordByOwnerPaginated(top, skip));
    basicRecordHateoasHandler.addLinks(basicRecordHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(basicRecordHateoas);
}
Also used : INikitaEntity(nikita.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 9 with Counted

use of com.codahale.metrics.annotation.Counted in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordHateoasController method updateBasicRecord.

// API - All PUT Requests (CRUD - UPDATE)
// Update a BasicRecord
// PUT [contextPath][api]/arkivstruktur/basisregistrering/{systemID}
@ApiOperation(value = "Updates a BasicRecord object", notes = "Returns the newly" + " update BasicRecord object after it is persisted to the database", response = BasicRecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "BasicRecord " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = BasicRecordHateoas.class), @ApiResponse(code = 201, message = "BasicRecord " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = BasicRecordHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type BasicRecord"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.PUT, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<BasicRecordHateoas> updateBasicRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of basicRecord to update.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "basicRecord", value = "Incoming basicRecord object", required = true) @RequestBody BasicRecord basicRecord) throws NikitaException {
    validateForUpdate(basicRecord);
    BasicRecord updatedBasicRecord = basicRecordService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), basicRecord);
    BasicRecordHateoas basicRecordHateoas = new BasicRecordHateoas(updatedBasicRecord);
    basicRecordHateoasHandler.addLinks(basicRecordHateoas, request, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedBasicRecord));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedBasicRecord.getVersion().toString()).body(basicRecordHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) AfterNoarkEntityUpdatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with Counted

use of com.codahale.metrics.annotation.Counted in project nikita-noark5-core by HiOA-ABI.

the class ClassHateoasController method createClassAssociatedWithClassificationSystem.

// API - All POST Requests (CRUD - CREATE)
// POST [contextPath][api]/arkivstruktur/klassifikasjonsystem/{systemID}/ny-underklass
@ApiOperation(value = "Persists a Class object associated with the (other) given Class systemId", notes = "Returns the newly created class object after it was associated with a class" + "object and persisted to the database", response = ClassHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Class " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = Class.class), @ApiResponse(code = 201, message = "Class " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = Class.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type Class"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + "classificationSystemSystemId" + RIGHT_PARENTHESIS + SLASH + NEW_SUB_CLASS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<ClassHateoas> createClassAssociatedWithClassificationSystem(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "classificationSystemSystemId", value = "systemId of classificationSystem to associate the klass with.", required = true) @PathVariable String classSystemId, @ApiParam(name = "klass", value = "Incoming class object", required = true) @RequestBody Class klass) throws NikitaException {
    Class createdClass = classService.createClassAssociatedWithClass(classSystemId, klass);
    ClassHateoas classHateoas = new ClassHateoas(createdClass);
    classHateoasHandler.addLinks(classHateoas, request, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdClass));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdClass.getVersion().toString()).body(classHateoas);
}
Also used : ClassHateoas(nikita.model.noark5.v4.hateoas.ClassHateoas) AfterNoarkEntityCreatedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Class(nikita.model.noark5.v4.Class) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)127 Timed (com.codahale.metrics.annotation.Timed)127 ApiOperation (io.swagger.annotations.ApiOperation)107 ApiResponses (io.swagger.annotations.ApiResponses)107 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)105 AfterNoarkEntityCreatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityCreatedEvent)18 AfterNoarkEntityUpdatedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent)16 ArrayList (java.util.ArrayList)15 MetadataHateoas (nikita.model.noark5.v4.hateoas.metadata.MetadataHateoas)15 INikitaEntity (nikita.model.noark5.v4.interfaces.entities.INikitaEntity)14 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)14 CaseFileHateoas (nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)13 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)11 Metered (com.codahale.metrics.annotation.Metered)9 Fonds (nikita.model.noark5.v4.Fonds)9 FondsHateoas (nikita.model.noark5.v4.hateoas.FondsHateoas)9 DocumentObject (nikita.model.noark5.v4.DocumentObject)8 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)8 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)7 DocumentObjectHateoas (nikita.model.noark5.v4.hateoas.DocumentObjectHateoas)7