@ Override @ Transactional @ RunAsSystem public String generateAndStoreToken ( String username , String description ) { User user = dataService . query ( USER , User . class ) . eq ( USERNAME , username ) . findOne ( ) ; if ( user == null ) { throw new IllegalArgumentException ( format ( "Unknown username [%s]" , username ) ) ; } String token = tokenGenerator . generateToken ( ) ; Token molgenisToken = tokenFactory . create ( ) ; molgenisToken . setUser ( user ) ; molgenisToken . setToken ( token ) ; molgenisToken . setDescription ( description ) ; molgenisToken . setExpirationDate ( now ( ) . plus ( 2 , HOURS ) ) ; dataService . add ( TOKEN , molgenisToken ) ; return token ; }
Generates a token and associates it with a user .