use of net.geoprism.registry.session.UserNotOuathEnabledException in project geoprism-registry by terraframe.
the class RegistrySessionService method getActor.
@Transaction
private static synchronized SingleActorDAOIF getActor(OauthServer server, String username) throws JSONException {
UsersQuery query = new UsersQuery(new QueryFactory());
query.WHERE(query.getUsername().EQ(username));
OIterator<? extends Users> it = query.getIterator();
try {
if (it.hasNext()) {
UserDAO user = (UserDAO) BusinessFacade.getEntityDAO(it.next());
try {
GeoprismUser geoprismUser = GeoprismUser.getByUsername(user.getUsername());
UserInfo userInfo = UserInfo.getByUser(geoprismUser);
ExternalSystem system = ExternalSystem.get(userInfo.getExternalSystemOid());
if (system instanceof DHIS2ExternalSystem) {
DHIS2ExternalSystem dhis2System = (DHIS2ExternalSystem) system;
if (dhis2System.getOauthServerOid().equals(server.getOid())) {
return user;
}
}
} catch (Throwable t) {
logger.error("Encountered an unexpected error while logging user in.", t);
}
UserNotOuathEnabledException ex = new UserNotOuathEnabledException();
ex.setUsername(user.getUsername());
ex.setOauthServer(server.getDisplayLabel().getValue());
throw ex;
} else {
UserNotFoundException ex = new UserNotFoundException();
ex.setUsername(username);
throw ex;
}
} finally {
it.close();
}
}
Aggregations