public AuthenticatedUser auth(AuthCredentials authCredentials) throws SwordAuthException, SwordServerException { if (authCredentials == null) { /** * in DVN 3.x at least, it seems this was never reached... eaten * somewhere by way of ServiceDocumentServletDefault -> * ServiceDocumentAPI -> SwordAPIEndpoint */ String msg = "No credentials provided."; throw new SwordAuthException(msg); } String username = authCredentials.getUsername(); if (username == null) { String msg = "No API token/key (formerly username) provided."; logger.info(msg); throw new SwordAuthException(msg); } AuthenticatedUser authenticatedUserFromToken = findUserByApiToken(username); if (authenticatedUserFromToken == null) { String msg = "User not found based on API token."; logger.fine(msg); throw new SwordAuthException(msg); } else { authenticatedUserFromToken = userSvc.updateLastApiUseTime(authenticatedUserFromToken); return authenticatedUserFromToken; } }
public void authentication(AuthCredentials credentials) throws SwordAuthException { if (!exists(credentials.getUsername())) { throw new SwordAuthException("Wrong login data!"); } MCRUser mcrUser = login(credentials.getUsername(), credentials.getPassword()); if (mcrUser == null) { throw new SwordAuthException("Wrong login data!"); } } }
private List<Bitstream> unzipToBundle(Context context, File depositFile, Bundle target) throws DSpaceSwordException, SwordError, SwordAuthException { try { // get the zip file into a usable form ZipFile zip = new ZipFile(depositFile); List<Bitstream> derivedResources = new ArrayList<Bitstream>(); Enumeration zenum = zip.entries(); while (zenum.hasMoreElements()) { ZipEntry entry = (ZipEntry) zenum.nextElement(); InputStream stream = zip.getInputStream(entry); Bitstream bs = bitstreamService.create(context, target, stream); BitstreamFormat format = this .getFormat(context, entry.getName()); bs.setFormat(context, format); bs.setName(context, entry.getName()); bitstreamService.update(context, bs); derivedResources.add(bs); } return derivedResources; } catch (ZipException e) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "unable to unzip provided package", e); } catch (IOException | SQLException e) { throw new DSpaceSwordException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e); } }
private void removeContent(SwordContext swordContext, Item item, AuthCredentials authCredentials, SwordConfigurationDSpace swordConfig) throws DSpaceSwordException, SwordAuthException { try { // remove content only really means everything from the ORIGINAL bundle VersionManager vm = new VersionManager(); Iterator<Bundle> bundles = item.getBundles().iterator(); while (bundles.hasNext()) { Bundle bundle = bundles.next(); if (Constants.CONTENT_BUNDLE_NAME.equals(bundle.getName())) { bundles.remove(); vm.removeBundle(swordContext.getContext(), item, bundle); } } } catch (SQLException | IOException e) { throw new DSpaceSwordException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e); } }
private void removeBitstream(SwordContext swordContext, Bitstream bitstream, List<Item> items, AuthCredentials authCredentials, SwordConfigurationDSpace swordConfig) throws DSpaceSwordException, SwordAuthException { try { // remove content only really means everything from the ORIGINAL bundle VersionManager vm = new VersionManager(); for (Item item : items) { vm.removeBitstream(swordContext.getContext(), item, bitstream); } } catch (SQLException | IOException e) { throw new DSpaceSwordException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e); } }
throw new DSpaceSwordException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e);
private void checkAuth(SwordContext sc, Item item) throws DSpaceSwordException, SwordError, SwordAuthException { Context context = sc.getContext(); SwordAuthenticator auth = new SwordAuthenticator(); if (!auth.canSubmit(sc, item, this.verboseDescription)) { // throw an exception if the deposit can't be made String oboEmail = "none"; if (sc.getOnBehalfOf() != null) { oboEmail = sc.getOnBehalfOf().getEmail(); } log.info(LogManager .getHeader(context, "replace_failed_authorisation", "user=" + sc.getAuthenticated().getEmail() + ",on_behalf_of=" + oboEmail)); throw new SwordAuthException( "Cannot replace the given item with this context"); } } }
public SwordContext doAuth(AuthCredentials authCredentials) throws SwordAuthException, SwordError, DSpaceSwordException { // if there is no supplied username, then we should request a retry if (authCredentials.getUsername() == null) { throw new SwordAuthException(true); } // first authenticate the request // note: this will build our various DSpace contexts for us SwordAuthenticator auth = new SwordAuthenticator(); SwordContext sc = auth.authenticate(authCredentials); // log the request String un = authCredentials.getUsername() != null ? authCredentials.getUsername() : "NONE"; String obo = authCredentials.getOnBehalfOf() != null ? authCredentials.getOnBehalfOf() : "NONE"; log.info(LogManager.getHeader(sc.getContext(), "sword_auth_request", "username=" + un + ",on_behalf_of=" + obo)); return sc; }
throw new DSpaceSwordException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e);
throw new DSpaceSwordException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e);
"user=" + sc.getAuthenticated().getEmail() + ",on_behalf_of=" + oboEmail)); throw new SwordAuthException( "Cannot delete the given item with this context");
private MediaResource getBitstreamResource(Context context, Bitstream bitstream) throws SwordServerException, SwordAuthException { try { InputStream stream = bitstreamService.retrieve(context, bitstream); MediaResource mr = new MediaResource(stream, bitstream.getFormat(context).getMIMEType(), null, true); mr.setContentMD5(bitstream.getChecksum()); mr.setLastModified(this.getLastModified(context, bitstream)); return mr; } catch (IOException | SQLException e) { throw new SwordServerException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e); } }
throw new SwordAuthException(); } catch (SQLException | DSpaceSwordException e) { throw new SwordServerException(e);
protected void doContainerDelete(SwordContext swordContext, Item item, AuthCredentials authCredentials, SwordConfigurationDSpace swordConfig) throws DSpaceSwordException, SwordAuthException { try { Context context = swordContext.getContext(); // first figure out if there's anything we need to do about the workflow/workspace state WorkflowTools wft = new WorkflowTools(); if (wft.isItemInWorkspace(swordContext.getContext(), item)) { WorkspaceItem wsi = wft.getWorkspaceItem(context, item); workspaceItemService.deleteAll(context, wsi); } else if (wft.isItemInWorkflow(context, item)) { WorkflowItem wfi = wft.getWorkflowItem(context, item); workflowItemService.deleteWrapper(context, wfi); } // then delete the item itemService.delete(context, item); } catch (SQLException | IOException e) { throw new DSpaceSwordException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e); } }
public DepositReceipt getEntry(String editIRI, Map<String, String> accept, AuthCredentials authCredentials, SwordConfiguration swordConfig) throws SwordServerException, SwordError, SwordAuthException { SwordContext sc = null; try { SwordConfigurationDSpace config = (SwordConfigurationDSpace) swordConfig; sc = this.doAuth(authCredentials); Context context = sc.getContext(); SwordUrlManager urlManager = config.getUrlManager(context, config); Item item = urlManager.getItem(context, editIRI); if (item == null) { throw new SwordError(404); } // we can't give back an entry unless the user is authorised to retrieve it authorizeService.authorizeAction(context, item, Constants.READ); ReceiptGenerator genny = new ReceiptGenerator(); DepositReceipt receipt = genny.createReceipt(context, item, config); sc.abort(); return receipt; } catch (AuthorizeException e) { throw new SwordAuthException(); } catch (SQLException | DSpaceSwordException e) { throw new SwordServerException(e); } finally { // this is a read operation only, so there's never any need to commit the context if (sc != null) { sc.abort(); } } }
throw new SwordAuthException(e); } catch (SQLException e) { throw new DSpaceSwordException(e);
throw new SwordAuthException(e); } catch (SQLException e) { throw new DSpaceSwordException(e);
throw new SwordAuthException(e); } catch (SQLException | IOException e) { throw new DSpaceSwordException(e);
throw new SwordAuthException(e); } catch (SQLException e) { throw new DSpaceSwordException(e);
throw new SwordAuthException(e); } catch (SQLException | IOException e) { throw new DSpaceSwordException(e);