} else {
if(session.isConnected()) { // already got a active session going
OAuthSession session = service.getSession();
UserProfile userProfile = session.getUserProfile();
User user = repository.get(userProfile.getId());
if(user == null) { // can't find a matching account, shouldn't really happen
setStatus(AuthenticationStatus.FAILURE);
} else {
setAccount(new UserAccount(user));
setStatus(AuthenticationStatus.SUCCESS);
}
} else {
// Callback
String verifier = request.getParameter(service.getVerifierParamName());
if(verifier != null) {
session.setVerifier(verifier);
service.initAccessToken();
// https://issues.jboss.org/browse/AGOVA-53
successful.fire(new SuccessfulAuthentication(service.getSession().getUserProfile(), service.getAccessToken()));
String screenName = ((TwitterProfile)service.getSession().getUserProfile()).getScreenName();
User user = repository.get(screenName);
if(user == null) { // can't find a matching account
setStatus(AuthenticationStatus.FAILURE);
} else {
setAccount(new UserAccount(user));
setStatus(AuthenticationStatus.SUCCESS);
response.addCookie(new Cookie(AUTH_COOKIE_NAME, user.getApiToken()));
}
} else {
// initiate redirect request to 3. party
String redirectUrl = service.getAuthorizationUrl();