use of com.emc.metalnx.services.auth.UserTokenDetails in project metalnx-web by irods-contrib.
the class TestTicketAuthenticatedAccess method setUp.
@Before
public void setUp() throws DataGridException, JargonException, IOException {
String parentPath = String.format("/%s/home", zone);
targetPath = String.format("%s/%s", parentPath, username);
ticketUtils = new TestTicketUtils(irodsServices);
ticketString = ticketUtils.createTicket(parentPath, username, TicketCreateModeEnum.WRITE);
localFile = ticketUtils.createLocalFile();
filePath = String.format("%s/%s", targetPath, localFile.getName());
IRODSAccount authIrodsAccount = IRODSAccount.instance(host, Integer.valueOf(port), username, password, targetPath, zone, RESOURCE);
UserTokenDetails userTokenDetails = Mockito.mock(UserTokenDetails.class);
Authentication authentication = Mockito.mock(Authentication.class);
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
SecurityContextHolder.setContext(securityContext);
Mockito.when(securityContext.getAuthentication()).thenReturn(authentication);
Mockito.when(authentication.getDetails()).thenReturn(userTokenDetails);
Mockito.when(userTokenDetails.getIrodsAccount()).thenReturn(authIrodsAccount);
}
use of com.emc.metalnx.services.auth.UserTokenDetails in project metalnx-web by irods-contrib.
the class TicketClientExceptionController method handleTicketFileNotFound.
@ExceptionHandler({ DataGridTicketDownloadException.class })
public ModelAndView handleTicketFileNotFound(DataGridTicketDownloadException e) {
ticketClientService.deleteTempTicketDir();
String path = e.getPath();
String objName = path.substring(path.lastIndexOf(IRODS_PATH_SEPARATOR) + 1, path.length());
ModelAndView mav = new ModelAndView();
mav.addObject("error", e.getMessage());
mav.addObject("objName", objName);
mav.addObject("path", path);
mav.addObject("ticketString", e.getTicketString());
String viewName = "tickets/ticketclient";
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
if (loggedUser != null) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
UserTokenDetails userTokenDetails = (UserTokenDetails) auth.getDetails();
mav.addObject("userDetails", userTokenDetails.getUser());
viewName = "tickets/ticketAuthAccess";
}
mav.setViewName(viewName);
return mav;
}
use of com.emc.metalnx.services.auth.UserTokenDetails in project metalnx-web by irods-contrib.
the class TicketClientServiceImpl method setUpAccess.
/**
* Sets up all necessary stuff for an anonymous user to be able to interact with the grid. This interaction means
* iput & iget.
*/
private void setUpAccess() {
try {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || !(authentication.getDetails() instanceof UserTokenDetails)) {
logger.warn("Accessing files and collections with tickets using anonymous account");
irodsAccount = IRODSAccount.instanceForAnonymous(host, port, ANONYMOUS_HOME_DIRECTORY, zone, RESOURCE);
} else {
logger.warn("Accessing files and collections with tickets as authenticated user");
irodsAccount = ((UserTokenDetails) authentication.getDetails()).getIrodsAccount();
}
TicketServiceFactory ticketServiceFactory = new TicketServiceFactoryImpl(irodsAccessObjectFactory);
ticketClientOperations = ticketServiceFactory.instanceTicketClientOperations(irodsAccount);
} catch (JargonException e) {
logger.error("Could not set up anonymous access");
}
}
Aggregations