use of org.alfresco.repo.security.authentication.AuthenticationException in project alfresco-remote-api by Alfresco.
the class AuthenticationsImpl method validateTicket.
@Override
public LoginTicketResponse validateTicket(String me, Parameters parameters, WithResponse withResponse) {
if (!People.DEFAULT_USER.equals(me)) {
throw new InvalidArgumentException("Invalid parameter: " + me);
}
final String ticket = getTicket(parameters);
try {
final String ticketUser = ticketComponent.validateTicket(ticket);
final String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
// or the user is not fully authenticated
if (currentUser == null || !currentUser.equals(ticketUser)) {
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
}
} catch (AuthenticationException e) {
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
}
LoginTicketResponse response = new LoginTicketResponse();
response.setId(ticket);
return response;
}
use of org.alfresco.repo.security.authentication.AuthenticationException in project alfresco-remote-api by Alfresco.
the class AuthenticationsImpl method deleteTicket.
@Override
public void deleteTicket(String me, Parameters parameters, WithResponse withResponse) {
if (!People.DEFAULT_USER.equals(me)) {
throw new InvalidArgumentException("Invalid parameter: " + me);
}
final String ticket = getTicket(parameters);
try {
final String ticketUser = ticketComponent.validateTicket(ticket);
final String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
// or the user is not fully authenticated
if (currentUser == null || !currentUser.equals(ticketUser)) {
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
} else {
// delete the ticket
authenticationService.invalidateTicket(ticket);
}
} catch (AuthenticationException e) {
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
}
}
use of org.alfresco.repo.security.authentication.AuthenticationException in project alfresco-remote-api by Alfresco.
the class AbstractLoginBean method login.
protected Map<String, Object> login(final String username, String password) {
try {
// get ticket
authenticationService.authenticate(username, password.toCharArray());
eventPublisher.publishEvent(new EventPreparator() {
@Override
public Event prepareEvent(String user, String networkId, String transactionId) {
// TODO need to fix up to pass correct seqNo and alfrescoClientId
return new RepositoryEventImpl(-1l, "login", transactionId, networkId, new Date().getTime(), username, null);
}
});
// add ticket to model for javascript and template access
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
model.put("username", username);
model.put("ticket", authenticationService.getCurrentTicket());
return model;
} catch (AuthenticationException e) {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Login failed");
} finally {
AuthenticationUtil.clearCurrentSecurityContext();
}
}
use of org.alfresco.repo.security.authentication.AuthenticationException in project alfresco-remote-api by Alfresco.
the class RemoteAlfrescoTicketServiceTest method testGetStoreGetCredentials.
/**
* Getting, storing and fetching credentials
*/
public void testGetStoreGetCredentials() throws Exception {
// Run this test initially as the first user
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
// First, try an invalid system
try {
remoteAlfrescoTicketService.getRemoteCredentials(INVALID_REMOTE_SYSTEM_ID);
fail("Shouldn't work for an invalid system");
} catch (NoSuchSystemException e) {
}
try {
remoteAlfrescoTicketService.storeRemoteCredentials(INVALID_REMOTE_SYSTEM_ID, null, null);
fail("Shouldn't work for an invalid system");
} catch (NoSuchSystemException e) {
}
// Our user starts out without credentials
BaseCredentialsInfo credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(null, credentials);
// Try to store some invalid credentials (real user, but password wrong)
try {
remoteAlfrescoTicketService.storeRemoteCredentials(TEST_REMOTE_SYSTEM_ID, USER_ONE, "invalid");
fail("Credentials invalid, shouldn't be allowed");
} catch (AuthenticationException e) {
}
// And an invalid user
try {
remoteAlfrescoTicketService.storeRemoteCredentials(TEST_REMOTE_SYSTEM_ID, "thisUSERdoesNOTexist", "invalid");
fail("Credentials invalid, shouldn't be allowed");
} catch (AuthenticationException e) {
}
// Still none there
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(null, credentials);
// Store some valid ones
credentials = remoteAlfrescoTicketService.storeRemoteCredentials(TEST_REMOTE_SYSTEM_ID, USER_ONE, PASSWORD);
assertNotNull(credentials);
assertEquals(TEST_REMOTE_SYSTEM_ID, credentials.getRemoteSystemName());
assertEquals(USER_ONE, credentials.getRemoteUsername());
// Check we can find them
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertNotNull(credentials);
assertEquals(TEST_REMOTE_SYSTEM_ID, credentials.getRemoteSystemName());
assertEquals(USER_ONE, credentials.getRemoteUsername());
// Store some different, valid credentials for the user
credentials = remoteAlfrescoTicketService.storeRemoteCredentials(TEST_REMOTE_SYSTEM_ID, USER_TWO, PASSWORD);
assertNotNull(credentials);
assertEquals(TEST_REMOTE_SYSTEM_ID, credentials.getRemoteSystemName());
assertEquals(USER_TWO, credentials.getRemoteUsername());
// Check we see the change
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertNotNull(credentials);
assertEquals(TEST_REMOTE_SYSTEM_ID, credentials.getRemoteSystemName());
assertEquals(USER_TWO, credentials.getRemoteUsername());
// Switch to the other user, no credentials there
AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(null, credentials);
// Switch back, and delete
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertNotNull(credentials);
boolean deleted = remoteAlfrescoTicketService.deleteRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(true, deleted);
// Will have gone
credentials = remoteAlfrescoTicketService.getRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(null, credentials);
// Double delete is reported
deleted = remoteAlfrescoTicketService.deleteRemoteCredentials(TEST_REMOTE_SYSTEM_ID);
assertEquals(false, deleted);
}
Aggregations