Strange behavior with users keychain - ios6

I'm trying to debug a strange behavior while saving to the users keychain on iOS. I'm using the below code to check for the user being on the keychain:
keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:KeyName accessGroup:nil];
if(keychainItem != NULL && [keychainItem objectForKey:(id)kSecValueData] != NULL && [[keychainItem objectForKey:(id)kSecValueData] length] > 0 &&
[keychainItem objectForKey:(id)kSecAttrAccount] != NULL && [[keychainItem objectForKey:(id)kSecAttrAccount] length] > 0) {
txtPassword.text = [keychainItem objectForKey:(id)kSecValueData];
txtLogin.text = [keychainItem objectForKey:(id)kSecAttrAccount];
// Call webservice to login
[self btnPressedLogin:nil];
}
I'm using the following for saving to the keychain:
[keychainItem setObject:KeyName forKey: (id)kSecAttrService];
[keychainItem setObject:txtLogin.text forKey:(id)kSecAttrAccount];
[keychainItem setObject:txtPassword.text forKey:(id)kSecValueData];
When the user logs out, I simply do:
[keychainItem resetKeychainItem];
I'm noticing it works in all scenarios EXCEPT:
I log in (manually entering username/password)
Log out
I log in (manually entering username/password)
Restart simulator
It DOESN'T auto-login as it should
Is there something wrong with my code snippets above? I'm able to reproduce this on the simulator each time, and i'm not aware, as I was following tutorials online. Including the following page:
iOS: How to store username/password within an app?
[EDIT]
I was stepping through breakpoints, and I confirmed that after step 3 (relogging in), it is in fact saving to the keychain. I was able to output what it saved.
However, right after that when I restart the simulator...it shows that it can't find username and password! Which makes no sense...

I found the issue. It was a memory issue. When the screen was moving, keychainItem was a property that was being deallocated. I had to reinitialize it since I was creating in the viewDidLoad function, which wasn't getting called after logging out. Case closed.

Related

MERN stack app randomly broke after 6 months in production and throws the following error: "TypeError: r.filter is not a function"

I wrote a full stack critical application using the MERN stack for a client and it has been running smoothly for over 6 months now. Today, my client notified me that upon logging into the app, the Dashboard view flashes on the screen and then disappears throwing this error: TypeError: r.filter is not a function.
The Dashboard view makes an AJAX call to the back-end and fetches a number of tickets from the database that are then stored in Redux and then categorized and displayed on the browser. There are several array methods used in this component, for example:
const awaiting = tickets.filter(
ticket =>
(ticket.status === 'Return to Provider' ||
ticket.status === 'Require survey') &&
!ticket.closed
);
const unassigned = tickets.filter(
ticket => ticket.status === 'Unassigned'
);
const pending = tickets.filter(ticket => ticket.status === 'Issued');
const active = tickets.filter(
ticket =>
ticket.status === 'On field' ||
ticket.status === 'Provisioning required by client'
);
const complete = tickets.filter(
ticket =>
(ticket.status === 'Complete' ||
ticket.status === 'Complete to activate at a later date') &&
!ticket.closed
);
The error is thrown at the first .filter method. If I comment that out, the error is thrown at the next and so on. The same error is being thrown wherever there is an array method used and this is the exact error message:
TypeError: r.filter is not a function
at t.value (Dashboard.js:99)
at Mi (react-dom.production.min.js:3785)
at Pi (react-dom.production.min.js:3776)
at ji (react-dom.production.min.js:3960)
at Ba (react-dom.production.min.js:5514)
at $a (react-dom.production.min.js:5536)
at Mu (react-dom.production.min.js:5958)
at Cu (react-dom.production.min.js:5925)
at ku (react-dom.production.min.js:5860)
at Xa (react-dom.production.min.js:5787)
When I try to access another view on the app where an array method is used to render a list of tickets specifically, I get the same error. But, I am able to access any other view that does not render a list of tickets, there are no errors thrown.
NOTE: This ONLY occurs when I connect to the production database, which has over 2000 tickets (over 30MB of data), regardless of whether I am connecting from my localhost environment or from production environment.
However, when I connect the same code base to my test database (which has 34 tickets), there are no errors thrown and everything runs smoothly.
This is literally the only difference I can identify that is producing this error and crashing the entire app (the number of tickets that the array methods are operating on).
As I said before, the production app was running smoothly for the last 6 months. What would cause such a random app-breaking error like this?
There could be a number of reasons why filter() might not work in your situation.
Can you specify the network response you are getting ? That would be a good way to start debugging.
There are 2 main failure points at play here:
Response is coming wrong from backend or not coming at all (server side fault, which seems like the probable cause because your app suddenly broke)
There is something wrong with your client side code
Response from backend can break because of any number of reasons. You can check for:
SSL Certificate expiry
Environment Variable mis-function issue
Response being very large (as you said 30MB, in which case you can use and should definitely use pagination)

Grails3/groovy error iterating a list where index 0 was removed

this is my first grails project, so sorry if it's a newbish question but I didn't find anything about it.
I'm using Grails 3.3.2 with mongoDB and the calls to the DB are made with GORM.
I created a method that receives a list of users to create a MAP with the users and their specific roles and render it in a view. Only the admin has access to this page and now I don't want for a logged in admin to have access to his privileges/role, in other words, an admin can ONLY change the roles for other admins.
This way the system don't be with no admin by mistake.
This is the method:
#Secured(["ROLE_Administrador"])
def renderListUsers(def listUsers) {
//remove o proprio utilizador antes de tudo!
// THIS PRINTLN !!
//println(listUsers)
listUsers.remove(User.findByUsername(getPrincipal().username))
def usersWithRole = [:]
for (user in listUsers) {
usersWithRole[user.username] = UserRole.findByUser(user).role.toString().split("_")[1]
}
render(view: "listUsers", model: [users: listUsers, userRoles: usersWithRole])
}
This method is working perfectly, the issue is that as soon as I added the "listUsers.remove(...)" (line 7) to remove the logged in user I was getting this error and I didn't understand why, then I find out that the error only occurs if the user removed is in the index 0 of that list.
Now I found if I add that "println(listUsers)" before it just works always! Even if the object removed is in the index 0.
Is this a known error on groovy or what am I doing wrong? I don't want to leave that print there.
Thank you for your time!
EDIT:
Got it to work! This way:
def loggedUser = User.findByUsername(getPrincipal().username)
if (loggedUser in listUsers) {
listUsers.remove(loggedUser)
}
I knew that I needed to add this verification, but I didn't thought that it would resolve this.

D3 Connection issue using mvsp java api

I am trying to connect to D3 Database with MVSP java api. So far:
I have downloaded the mvapi.jar
added it in project lib folder
written the sample code for connection inside main method
String url = "jdbc:mv:d3:hostname:portNo";
Properties props = new Properties();
props.setProperty("username", "");
props.setProperty("password", "");
String account = "AGCO";
String password = "";
MVConnection connection = null;
try {
// Getting error at this point
connection = new MVConnection(url,props);
MVStatement mvStatement = connection.createStatement();
connection.logTo(account,password);
MVResultSet results = mvStatement.executeQuery(query);
}
com.tigr.mvapi.exceptions.MVException: server error with errorCode 1023.
I checked the console but I'm not able to figure out the actual cause or whether I am entering the wrong username, password.
Please suggest what I am doing wrong.
First, you have to set a breakpoint or trace which function is throwing the errors. Then check the routes, (FileName) probably you will have much more experience than I do, but keep in mind that giving the full route ("account,filename," where the last comma is important) is never a bad idea while keep you safer and is mandatory if the filename is in a different account that you are logged to.
And like always please verify these things:
You have enough licenses. Try to close any terminal you have opened for testing your queries. Yes you know is true. One connection one license. Sometimes MVSP let you two under the same IP but chek this.
MVSP service is running. See Pick D3 documentation.
Your USER and ACCOUNT are both ENABLED to access in the MVSP server otherwise you won't be able to access these files or login with the user through the API. See the documentation to enable in the MVSP.Menu account.
I hope this helps.

CakePHP - Site Offline - Admin Routing Not Working

I setup the following code in my app_controllers.php file to control access to the site when the site is set to OFFLINE (site_status = 0).
function beforeFilter(){
// Site Offline = 0 , Site Online = 1
if($this->Configuration->get_site_status() == 1){
// Allow access to the site to all users and perform all required
// beforeFilter code
}else{
...
// If site is OFFLINE but User is logged in allow access.
// Later I will need to change it to only allow admin access if logged in as I am still developing
// Everyone else will be denied access even if they are able to authenticate
if(!$this->Auth->user() == null){
$this->layout = 'default';
$this->Auth->allow('*');
}else{
$this->layout = 'offline';
$this->Auth->deny('*');
}
...
}
}
Everything works great when the requested address looks like the following:
http://www.mydomain.com/articles
However, when I have the following it does not work properly
http://www.mydomain.com/admin/articles
It prevents access to the site correctly, but it fails to use the $this->layout = 'offline'. It defaults back to the default layout.
What do I need to do to fix this.
Thank you!
Your if conditions look weird. They are:
If site is offline and user logged in
use default layout
otherwise
use offline layout and require authentication on all pages
I.e. you're using offline layout when site is online OR user is not logged in. Are you sure that is what you want?
Well, the first thing that looks out of place to me is:
(!$this->Auth->user() == null)
This looks very wrong and might be causing your problems. I would suggest changing this to something like:
(!is_null($this->Auth->user())
or
($this->Auth->user() !== NULL)
Edits
First, check out the PHP logical operators. You were appending a NOT statement to the return value of $this->Auth->user(). So, with a user logged in you're essentially asking if false is equal to null, which of course it isn't and never will be.
Second, check out the PHP comparison operators. You aren't wanting to check if the value of $this->Auth->user() is equal to the value null, you're wanting to check if the data type of $this->Auth->user() is equal to the type null. In short, null is a data type, not a value. If you did just have to use "=" in your if statement then you would want to use the identical === check or the identical not check !==.

app-engine-patch and pyFacebook not working

I am trying to write a facebook app using app-engine-patch and pyFacebook.
I am using nothing but the examples provided with each tool and for some reason it will not work.
I have combined the two just as described in the accepted answet here:
Facebook, Django, and Google App Engine
app-engine-patch seems to work just fine but when I try to use #facebook.require_login() I get this from GAE's logs:
Exception in request:
Traceback (most recent call last):
File "/base/data/home/apps/app-name/1.339079629847560090/common/zip-packages/django-1.1.zip/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/base/data/home/apps/app-name/1.339079629847560090/facebook/djangofb/__init__.py", line 87, in newview
if not fb.check_session(request):
File "/base/data/home/apps/app-name/1.339079629847560090/facebook/__init__.py", line 1293, in check_session
self.session_key_expires = int(params['expires'])
ValueError: invalid literal for int() with base 10: 'None'
This happends no matter which view I decorate with #facebook.require_login()
I am using the latest from both projects and I have no idea why it wont work.
Many thanks for your time.
UPDATE: I made a quickfix for pyFacebook, but I just forgot to put it back in the thread.
Now also as an answer, since it seems to be the only way.
If you change facebook/__init__.py line 1292+ from this:
if params.get('expires'):
self.session_key_expires = int(params['expires'])
To this:
if params.get('expires'):
if params['expires'] == 'None':
params['expires'] = 0
self.session_key_expires = int(params['expires'])
It will work, but it is a hack and maybe it could be done more elegantly, but it works.
Gotta point the pyFacebook devs to this thread, maybe they will have a better solution.
You should not use pyfacebook's decorator #facebook.require_login() when using pyfacebook with facebook-connect. The decorator is meant to be used for a facebook application, as it redirects the user to the facebook site if they are not logged in, but you really want to redirect the user to your login page on your site if they are not logged in.
To check if someone is logged in with facebook-connect and pyfacebook with the djangofb middleware, you call request.fb.check_session(request). If check_session returns True then they have a valid session. If it returns False then you need to redirect the user to your login page so they can click the facebook connect login button you (should) have placed on that page.
If you change facebook/__init__.py line 1292+ from this:
if params.get('expires'):
self.session_key_expires = int(params['expires'])
To this:
if params.get('expires'):
if params['expires'] == 'None':
params['expires'] = 0
self.session_key_expires = int(params['expires'])
It will work, but it is a hack and maybe it could be done more elegantly, but it works.

Resources