use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class SchedulerStateRest method login.
/**
* Login to the scheduler using a form containing 2 fields (username and
* password).
*
* @param username
* username
* @param password
* password
* @return the session id associated to the login.
* @throws LoginException
*/
@Override
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("login")
@Produces("application/json")
public String login(@FormParam("username") String username, @FormParam("password") String password) throws LoginException, SchedulerRestException {
try {
if ((username == null) || (password == null)) {
throw new LoginException("Empty login/password");
}
Session session = sessionStore.create(username);
session.connectToScheduler(new CredData(username, password));
logger.info("Binding user " + username + " to session " + session.getSessionId());
return session.getSessionId();
} catch (ActiveObjectCreationException e) {
throw new SchedulerRestException(e);
} catch (SchedulerException e) {
throw new SchedulerRestException(e);
} catch (NodeException e) {
throw new SchedulerRestException(e);
}
}
use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class SchedulerStateRest method loginWithCredential.
/**
* Login to the scheduler using a multipart form can be used either by
* submitting 2 fields ({@code username} and {@code password}) or by sending
* a credential file with field name {@code credential}.
*
* @return the session id associated to this new connection.
* @throws KeyException
* @throws LoginException
* @throws SchedulerRestException
*/
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("login")
@Produces("application/json")
public String loginWithCredential(@MultipartForm LoginForm multipart) throws LoginException, KeyException, SchedulerRestException {
try {
Session session;
if (multipart.getCredential() != null) {
Credentials credentials;
try {
session = sessionStore.createUnnamedSession();
credentials = Credentials.getCredentials(multipart.getCredential());
session.connectToScheduler(credentials);
} catch (IOException e) {
throw new LoginException(e.getMessage());
}
} else {
if ((multipart.getUsername() == null) || (multipart.getPassword() == null)) {
throw new LoginException("empty login/password");
}
session = sessionStore.create(multipart.getUsername());
CredData credData = new CredData(CredData.parseLogin(multipart.getUsername()), CredData.parseDomain(multipart.getUsername()), multipart.getPassword(), multipart.getSshKey());
session.connectToScheduler(credData);
}
return session.getSessionId();
} catch (PermissionException e) {
throw new SchedulerRestException(e);
} catch (ActiveObjectCreationException e) {
throw new SchedulerRestException(e);
} catch (SchedulerException e) {
throw new SchedulerRestException(e);
} catch (NodeException e) {
throw new SchedulerRestException(e);
}
}
use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class SessionStoreTest method testRmCreatedOnLoginAndSchedulerLazyCreation.
@Test
public void testRmCreatedOnLoginAndSchedulerLazyCreation() throws Exception {
String sessionId = sessionStore.createUnnamedSession().getSessionId();
Session session = sessionStore.get(sessionId);
verifyZeroInteractions(schedulerProxyFactory);
assertNull(session.getScheduler());
when(schedulerProxyFactory.connectToScheduler(Matchers.<CredData>any())).thenReturn(mock(SchedulerProxyUserInterface.class));
when(schedulerProxyFactory.connectToRM(Matchers.<CredData>any())).thenReturn(mock(RMProxyUserInterface.class));
session.connectToRM(new CredData("login", "password"));
assertNotNull(session.getRM());
assertNotNull(session.getScheduler());
assertEquals("login", session.getUserName());
}
use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class SessionStoreTest method testSchedulerCreatedOnLoginAndRmLazyCreation.
@Test
public void testSchedulerCreatedOnLoginAndRmLazyCreation() throws Exception {
String sessionId = sessionStore.createUnnamedSession().getSessionId();
Session session = sessionStore.get(sessionId);
verifyZeroInteractions(schedulerProxyFactory);
assertNull(session.getScheduler());
when(schedulerProxyFactory.connectToScheduler(Matchers.<CredData>any())).thenReturn(mock(SchedulerProxyUserInterface.class));
when(schedulerProxyFactory.connectToRM(Matchers.<CredData>any())).thenReturn(mock(RMProxyUserInterface.class));
session.connectToScheduler(new CredData("login", "password"));
assertNotNull(session.getScheduler());
assertNotNull(session.getRM());
assertEquals("login", session.getUserName());
}
use of org.ow2.proactive.authentication.crypto.CredData in project scheduling by ow2-proactive.
the class SharedSessionStoreTestUtils method createValidSession.
public static String createValidSession(RMProxyUserInterface rm) throws ActiveObjectCreationException, NodeException, RMException, KeyException, LoginException {
SchedulerRMProxyFactory schedulerFactory = mock(SchedulerRMProxyFactory.class);
when(schedulerFactory.connectToRM(Matchers.<CredData>any())).thenReturn(rm);
SharedSessionStore.getInstance().setSchedulerRMProxyFactory(schedulerFactory);
// login
Session session = SharedSessionStore.getInstance().createUnnamedSession();
session.connectToRM(new CredData());
return session.getSessionId();
}
Aggregations