return null;
}
Form requestForm = getRequest().getResourceRef().getQueryAsForm();
//getContext().getLogger().info("Testing auth...");
try {
ChallengeResponse authorization = getRequest().getChallengeResponse();
String idValue = AuthApplication.getStringAttribute(getRequest(),"session",null);
if (authorization==null || idValue!=null) {
if (idValue!=null) {
try {
UUID id = UUID.fromString(idValue);
User.Authenticated authd = db.isAuthenticated(realm,id);
if (authd!=null) {
String userAlias = authd.getUser().getAlias();
UUID userId = authd.getUser().getUUID();
String name = authd.getUser().getName();
String email = authd.getUser().getEmail();
Iterator<Group> groups = null;
Iterator<Role> roles = authd.getUser().getRoles();
// If we have a realm, we need the realm user to get the right alias
if (realm!=null) {
RealmUser ruser = db.findRealmUser(realm,authd.getUser());
if (ruser!=null) {
userAlias = ruser.getAlias();
name = ruser.getName();
email = ruser.getEmail();
groups = ruser.getGroups();
}
}
getResponse().setStatus(Status.SUCCESS_OK);
return getSessionEntity(authd.getSession(),userId,userAlias,name,email,roles,groups);
}
} catch (IllegalArgumentException ex) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return null;
}
}
getResponse().setChallengeRequests(Collections.singletonList(new ChallengeRequest(ChallengeScheme.HTTP_BASIC,realm==null ? "users" : "realm "+realm.getName())));
getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
return null;
}
String authid = authorization.getIdentifier().trim();
String password = new String(authorization.getSecret());
User user = null;
if (realm!=null) {
RealmUser ruser = findRealmUser(db,realm,authid);
if (ruser!=null) {
user = ruser.getUser();