I have angualrJS web app that recieves alerts from mobile app and marks the location of the mobile app user on google map. Once that mark is clicked info windo opens with name of user etc.
BackEnd is java maven project, and using spring boot.
My question is:
When I add spring boot security, to authenticate the page this stops all communication and no alerts show at all....
Any suggestions:
At the moment this is the application.js
var app = angular.module('sos',['ngRoute','mgcrea.ngStrap']);
app.config(['$httpProvider','$logProvider','$routeProvider',
function($httpProvider,$logProvider,$routeProvider) {
$logProvider.debugEnabled(true);
$routeProvider
.when('/', {
controller: 'MainController',
templateUrl: 'index.html',
controllerAs: 'controller'
})
.when('/download',{
templateUrl: 'download.html'
})
There is also a websocket connection that also stops and shows error 500 when I enable spring security...
This is web socket configuration:
#Configuration
#EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer{
#Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(geoLocationHandler(),
"/GeoLocationHandler").setAllowedOrigins("*");
}
#Bean
public GeoLocationHandler geoLocationHandler(){
return new GeoLocationHandler();
}
Any suggestions why spring security stops the alerts and markers showing on the map on the web app? And the spring security would make websocket fail giving error 500?
I tried to extend WebSecurityConfigAdapter and add mathcers to home page etc didnt work, I tried cors filters didnt work, I tried csrf filters didnt work as well...Any suggestion would be appreciated....
Can u try this in your
WebSecurityConfig.java file?
#Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().cors().disable().httpBasic().and().authorizeRequests()
.antMatchers(PUBLIC_MATCHERS).permitAll().anyRequest().authenticated();
(my snippet , try it and then remove what you don't like)
I think that eventually you don't let anyone to GET.
Here I give you also my Global method , in case you need it.
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userSecurityService).passwordEncoder(passwordEncoder());
}
Ok, after research I found that I needed to include http method get to be able to recive alerts on the the web app, so my websecurityConfiguration is like this:
#Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
//.and()
.httpBasic()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/*").permitAll()
.antMatchers(HttpMethod.GET, "/api/geolocation/*").permitAll()
.antMatchers(HttpMethod.GET, "/GeoLocationHandler").permitAll()
.antMatchers(HttpMethod.GET, "/api/responser/*").permitAll()
.antMatchers(HttpMethod.GET, "/api/user/").authenticated()
.anyRequest().authenticated();
}
Otherwise the webapp will not accept any alerts....
Hope this helps someone needing it....
Related
I'd really like some help with uploading a Node.js code to Firebase, to be a server for my Android app.
What I need to do:
I'm developing an app and pretty much the only thing that's left for me to do is uploading my server, which is written in Node.js, to the cloud. For that purpose, I'm using Firebase Cloud Functions.
What I have:
Following tutorials I found online, I have followed these steps:
Opened a Firebase project.
Wrote Node.js code for my server (which works well on local host).
Installed Firebase Tools with npm install -g firebase-tools.
Logged in, initiated and deployed a Function, getting this result:
Throughout the process, I mainly followed this tutorial and this video. In addition to some tutorials in the Firebase documentation.
What my problem is:
Well, in the console I see only this:
The URL in the picture (below the "Trigger" headline) doesn't work for me, unfortunately, and I have absolutely no idea what I'm doing wrong. The server worked just fine in localhost before I tried uploading it in the first place. In addition, my access to the Firebase Realtime Database has stopped working as well - and it did work well before.
Some code:
Here's some relevant parts of my Node.js code (which I wrote in the index.js file):
...
// Post request for sending token to server:
app.post('/token', (req, res, next) => {
// Get token from user:
let token = req.body.token;
if (!token) return res.status(400).json({err: "missing token"});
console.log(`Received save token request from ${req.params.user} for token=${token}`);
// Put it as a value in the JSON object 'tokens' with the user's username as key:
tokens[req.params.user] = token;
res.status(200).json({msg: "saved ok"});
});
...
exports.app = functions.https.onRequest(app);
The rest is mostly more of the same, in addition to all the necessary requires and all that.
Here's my firebase.JSON:
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**",
"function": "app"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
And in my Android client, here's an example of how I call an HTTP request (corresponding to the POST function I posted above):
_queue = Volley.newRequestQueue(this);
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
#Override
public void onSuccess(InstanceIdResult instanceIdResult) {
token = instanceIdResult.getToken();
getUser(token);
JSONObject requestObject = new JSONObject();
try {
requestObject.put("token", token);
}
catch (JSONException e) {
Log.e(TAG_MAINACTIVITY, token);
}
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, REQUEST_URL + "token",
requestObject, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.i(TAG_MAINACTIVITY, "Token saved successfully");
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG_MAINACTIVITY, "Failed to save token - " + error);
}
});
_queue.add(req);
}
});
I tried several variations of the request URL, currently it's this:
https://emotional-clarity-9ced0.web.app/
Main issues:
I'm unsure what URL I should use to access my functions. As I said, the one in the picture I provided doesn't work, nor do several variations of it which I tried using.
I cannot be sure that my upload process was even correct in the first place. As I said, I followed the tutorials which I linked quite closely. It shows no errors throughout the process, yet when trying to send an HTTP request from my client, I receive no response.
Being completely honest, I have zero idea what I'm missing here, and I obviously am missing something. Nothing I found online helped me. So I'd really appreciate if any of you could please shed some light on what I'm doing wrong because it's my first experience with these types of things.
Thanks.
Im trying to develop a sing up for AWS Cognito in Android. I just checked the official doc but in the Register a New User section there is only the sample for using SignUpHandler.
Checking other sections, for example Using the JavaScript SDK there is a clear sample using
userPool.signUp('username', 'password', attributeList, null, function(err, result)
Im trying to implement this aproach transpolating the javascript example. But I was wondering if there is any complete sample of sign up for Android?
Thanks in advance!!
The handler you noticed is a parameter for the call to sign up, much like 'function(err, result) in the JS example. Take a look at this part of the docs, it shows how to use that handler. From the example you screenshotted, it might look like this:
userPool.signUpInBackground(userId, password, userAttributes, null, handler);
Here is a complete sample using the link sugested by Jeff:
CognitoUserAttributes attributes = new CognitoUserAttributes();
attributes.addAttribute("phone_number","+15555555555");
attributes.addAttribute("email","email#mydomain.com");
cognitoUserPool.signUp('username', 'password', attributes, null, new SignUpHandler() {
#Override
public void onSuccess(CognitoUser cognitoUser, boolean b, CognitoUserCodeDeliveryDetails cognitoUserCodeDeliveryDetails) {
// If the sign up was successful, "user" is a CognitoUser object of the user who was signed up.
// "codeDeliveryDetails" will contain details about where the confirmation codes will be delivered.
}
#Override
public void onFailure(Exception e) {
// Sign up failed, code check the exception for cause and perform remedial actions.
}
});
The sections Examples of Using User Pools with the Mobile SDK for Android seems to be outdated.
Hope to help somebody else ;)
I am trying the upload videos into vimeo from my android application. The video is getting uploaded . But when the Delete request is called in order to get the video id , I am getting a response as "Invalid state". The same piece of code works in Htc X. Is this the issue with video codec format or something else ?
This is my piece of code for delete request
public void vimeoDelete() {
// Vimeo upload step 3
RestClient.mEndPoint.setUrl(APIHandler.VIMEO_BASE_URL);
RestClient.getVimeo().deleteVideo(mCompleteUri.substring(1), new Callback<Response>() {
#Override
public void success(Response response, Response response2) {
Log.i("Delete", "Done");
Log.i("Header", response2.getHeaders().toString());
Log.i("Body", response2.getBody().toString());
List<Header> aHeaders = response2.getHeaders();
for (Header aHeader : aHeaders) {
if (aHeader.getName().equals("Location")) {
mVideoUrlLocation = aHeader.getValue();
}
}
Log.i("Location", mVideoUrlLocation);
mFinalVideoUrl = mVideoUrlLocation.substring(8);
saveDetails();
}
#Override
public void failure(RetrofitError error) {
mProgress.dismiss();
}
});
}
Can anyone suggest a solution to this .
Regards
I just replied to the same issue over on the Vimeo forum - I had the same issue and am simply posting it here as there didn't seem to be a solution on this particular thread.
Also, regarding your post - there's not a lot of information provided in your post. Your delete request is not all that's required - the assumption would be that you created a valid ticket request, uploaded properly, THEN tried the del request you posted.
Vimeo post:
https://vimeo.com/forums/api/topic:278394
My solution:
I solved my version of the issue - I think Vimeo corrected some stuff on their API recently because my code did not have a bug and then suddenly one appeared recently. I would bet they added rate limiting on their API gateway or potentially overwriting existing requests to clean up old requests...
Anyhow, here is my fix:
In order to complete a video upload via "Resumable HTTP PUT uploads" (developer.vimeo.com/api/upload/videos), there are 5 steps.
I do everything but the upload through my PHP backend. I was requesting a ticket through PHP as to not expose some secret info through my modified JS frontend (github.com/websemantics/vimeo-upload) but I had not edited out the ticket request properly through the JS code, so the current bug was probably being triggered on that second invalid request (i.e. overwriting or rate limiting my initial valid request through PHP). Once I bypassed the JS "upload" function properly and jumped right to JS "sendFile_", the upload works properly again.
Hope that helps somebody out there!
I'm making an iOS app, and I'm using an UIWebView to show a site, and everything seems to be working fine.
But when I go to a page of this site that require HTTP Authentication (Basic/NTLM Auth, HTTP) it does not work fine.
I was reading and I found a method didReceiveAuthenticationChallenge that indicate when is necessary Authentication in a page.
I found a example provided by Apple (but it does not work for me). https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html
-(void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential;
newCredential = [NSURLCredential credentialWithUser:[self preferencesName]
password:[self preferencesPassword]
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential
forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
// inform the user that the user name and password
// in the preferences are incorrect
[self showPreferencesCredentialsAreIncorrectPanel:self];
}
}
I was doing the same testing In Android and I found that We can use this method (It works for me):
#Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
handler.proceed(username, password);
...
}
My question is, What is the correctly way to do HTTP Authentication (Basic Auth, HTTP) in objective-C ?
I did a test with two apps(android and IOS) for the same WebSite so Android app works fine, but the iOS app not.
Any advice will be use full for me!
Thanks.
I am a beginner in Phonegap and I made a simple web service in Microsoft Visual studio 2010 with two simple method. I want to call a method from that service from my Phonegap application for android platform. I am using xui library which method xhr is pretty much incomprehensible for me. I have read a lot of posts in that topic but I could not figure out how to do that.
My link to the web service looks like this: http://localhost/testservice/Service1.asmx.
This is my web service code:
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int Calculate(int firsNumber, int secundNumber)
{
return firsNumber + secundNumber;
}
}
This is my method which should test that service:
function checkWebService() {
var url = new "http://localhost/testservice/Service1.asmx?op=HelloWorld";
x$('#test').xhr(url, {error: function(){alert("failed "+this.responseText)},
callback: function(){
alert("Success " + this.responseText);
}
});
I call this method on button click and I am always getting alert with the text "Success", without "response text".
Probably my url is wrong, but I do not know which url I suppose to type.
This is for "HelloWorld" method without parameters, and I also do not know how to call method with parameters.
Any help or explanation please.
Looking at the docs (I'm not familiar with XUI), xhr is for getting a standard web page/JSON web service, where as you are calling a standard web service which will return an XML soap response (they are XML tags not HTML). You would need to parse this response to get just the result you require.
An easy way forward would be to change your web service to return a JSON response, then use eval() in javascript to give you a "typed" view of the object. XUI Example here.
If you're new to this you might find that JQuery has a larger document/community support than XUI.
BTW "Localhost" is a loopback address that essentially means "this" computer, so even it did work it would be trying to connect to the webservice on the mobile device (or emulator) rather than your server which you would typically connect to via a URL.