Search in sources :

Example 16 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class RemoteAPITokenServiceImpl method updateTokenFromRefreshToken.

/**
 * {@inheritDoc}
 */
@Transactional
public RemoteAPIToken updateTokenFromRefreshToken(RemoteAPI api) {
    RemoteAPIToken token = null;
    try {
        token = getToken(api);
        String refreshToken = token.getRefreshToken();
        if (refreshToken != null) {
            URI serviceTokenLocation = UriBuilder.fromUri(api.getServiceURI()).path("oauth").path("token").build();
            OAuthClientRequest tokenRequest = OAuthClientRequest.tokenLocation(serviceTokenLocation.toString()).setClientId(api.getClientId()).setClientSecret(api.getClientSecret()).setRefreshToken(refreshToken).setGrantType(GrantType.REFRESH_TOKEN).buildBodyMessage();
            OAuthJSONAccessTokenResponse accessToken = oauthClient.accessToken(tokenRequest);
            token = buildTokenFromResponse(accessToken, api);
            delete(api);
            token = create(token);
            logger.debug("Token for api " + api + " updated by refresh token.");
        } else {
            logger.debug("No refresh token for api " + api + ". Cannot update access token.");
        }
    } catch (EntityNotFoundException ex) {
        logger.debug("Token not found for api " + api + ".  Cannot update access token.");
    } catch (OAuthProblemException | OAuthSystemException ex) {
        logger.error("Updating token by refresh token failed", ex.getMessage());
    }
    return token;
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) OAuthJSONAccessTokenResponse(org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest) URI(java.net.URI) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class UserServiceImpl method loadUserByUsername.

/**
 * {@inheritDoc}
 */
@Override
@Transactional(readOnly = true)
@PreAuthorize("permitAll")
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    logger.trace("Loading user with username: [" + username + "].");
    org.springframework.security.core.userdetails.User userDetails = null;
    User u;
    try {
        u = userRepository.loadUserByUsername(username);
        userDetails = new org.springframework.security.core.userdetails.User(u.getUsername(), u.getPassword(), u.getAuthorities());
    } catch (EntityNotFoundException e) {
        throw new UsernameNotFoundException(e.getMessage());
    }
    return userDetails;
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) User(ca.corefacility.bioinformatics.irida.model.user.User) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class UserServiceImpl method loadUserByEmail.

/**
 * {@inheritDoc}
 */
@Override
@PreAuthorize("permitAll")
public User loadUserByEmail(String email) throws EntityNotFoundException {
    logger.trace("Loading user with email " + email);
    User loadUserByEmail = userRepository.loadUserByEmail(email);
    if (loadUserByEmail == null) {
        throw new EntityNotFoundException("User could not be found with that email address.");
    }
    return loadUserByEmail;
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 19 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class RESTAnalysisSubmissionController method getAnalysisOutputFile.

/**
 * Get an analysis output file for a given submission
 *
 * @param submissionId
 *            The {@link AnalysisSubmission} id
 * @param fileType
 *            The {@link AnalysisOutputFile} type as defined in the
 *            {@link Analysis} subclass
 * @return {@link ModelMap} containing the {@link AnalysisOutputFile}
 */
@RequestMapping("/{submissionId}/analysis/file/{fileType}")
public ModelMap getAnalysisOutputFile(@PathVariable Long submissionId, @PathVariable String fileType) {
    ModelMap model = new ModelMap();
    AnalysisSubmission read = analysisSubmissionService.read(submissionId);
    if (read.getAnalysisState() != AnalysisState.COMPLETED) {
        throw new EntityNotFoundException("Analysis is not completed");
    }
    AnalysisOutputFile analysisOutputFile = read.getAnalysis().getAnalysisOutputFile(fileType);
    analysisOutputFile.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisOutputFile(submissionId, fileType)).withSelfRel());
    model.addAttribute(RESOURCE_NAME, analysisOutputFile);
    return model;
}
Also used : ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class OAuthTokenRestTemplate method createRequest.

/**
 * Add an OAuth token from the tokenRepository to the request
 */
@Override
protected ClientHttpRequest createRequest(URI uri, HttpMethod method) throws IOException {
    RemoteAPIToken token;
    try {
        token = tokenService.getToken(remoteAPI);
    } catch (EntityNotFoundException ex) {
        logger.debug("No token found for service " + remoteAPI);
        throw new IridaOAuthException("No token fround for service", remoteAPI, ex);
    }
    if (token.isExpired()) {
        logger.debug("Token for service is expired " + remoteAPI);
        throw new IridaOAuthException("Token is expired for service", remoteAPI);
    }
    ClientHttpRequest createRequest = super.createRequest(uri, method);
    createRequest.getHeaders().add("Authorization", "Bearer " + token.getTokenString());
    return createRequest;
}
Also used : IridaOAuthException(ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest)

Aggregations

EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)45 Test (org.junit.Test)12 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 Project (ca.corefacility.bioinformatics.irida.model.project.Project)7 Transactional (org.springframework.transaction.annotation.Transactional)7 User (ca.corefacility.bioinformatics.irida.model.user.User)6 RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)5 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)5 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)5 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)4 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)4 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)4 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)4 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)4 Path (java.nio.file.Path)4