Search in sources :

Example 1 with UserTokenDetails

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);
}
Also used : UserTokenDetails(com.emc.metalnx.services.auth.UserTokenDetails) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) Authentication(org.springframework.security.core.Authentication) TestTicketUtils(com.emc.metalnx.services.tests.tickets.TestTicketUtils) SecurityContext(org.springframework.security.core.context.SecurityContext) Before(org.junit.Before)

Example 2 with UserTokenDetails

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;
}
Also used : UserTokenDetails(com.emc.metalnx.services.auth.UserTokenDetails) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) Authentication(org.springframework.security.core.Authentication) ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 3 with UserTokenDetails

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");
    }
}
Also used : TicketServiceFactory(org.irods.jargon.ticket.TicketServiceFactory) UserTokenDetails(com.emc.metalnx.services.auth.UserTokenDetails) TicketServiceFactoryImpl(org.irods.jargon.ticket.TicketServiceFactoryImpl) Authentication(org.springframework.security.core.Authentication)

Aggregations

UserTokenDetails (com.emc.metalnx.services.auth.UserTokenDetails)3 Authentication (org.springframework.security.core.Authentication)3 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)1 TestTicketUtils (com.emc.metalnx.services.tests.tickets.TestTicketUtils)1 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)1 TicketServiceFactory (org.irods.jargon.ticket.TicketServiceFactory)1 TicketServiceFactoryImpl (org.irods.jargon.ticket.TicketServiceFactoryImpl)1 Before (org.junit.Before)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1