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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations