How to do URL authentication in struts2 - spring

I am using struts2.1.6 + Spring 2.5 I have four modules in my application.
Registration Module
Admin Module
Quote Module
Location Module.
In registration module the customer can register himself and only after registering he is supposed to have access of the remaining three modules.
I want to implement something like if the action being called belongs to the registration module it will work as normal but if the action being called belongs to the rest of those three modules it first should check if the user is logged-in and session has not timed-out. if yes it should proceed normally otherwise it should redirect to the login page.
Through research I have found out that interceptors could be used for this purpose but before proceeding I thought its better to get some feedback on it from experts.
Please suggest how it should be done and If possible put some code suggestions.
Here is my struts.xml file(The struts.xml contains four different config files belonging to each module):
<struts>
<include file="struts-default.xml" />
<constant name="struts.i18n.reload" value="false" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.devMode" value="false" />
<constant name="struts.serve.static.browserCache" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.multipart.maxSize" value="10000000" />
<constant name="struts.multipart.saveDir" value="C:/Temporary_image_location" />
<include file="/com/action/mappingFiles/registration_config.xml" />
<include file="/com/action/mappingFiles/admin_config.xml" />
<include file="/com/action/mappingFiles/quote.xml" />
<include file="/com/action/mappingFiles/location_config.xml" />
</struts>
The sample registration_config.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="registration" extends="struts-default"
namespace="/my_company">
<action name="LoginView" class="registration" method="showLoginView">
<result>....</result>
<result name="input">...</result>
</action>
</package>
</struts>
The sample admin_config.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="admin" extends="struts-default"
namespace="/my_company">
<action name="viewAdmin" class="admin" method="showAdminView">
<result>....</result>
<result name="input">...</result>
</action>
</package>
</struts>
Same code is there in the rest of two struts2 xml config files. I have used the same namespace in all the four config files with the different package names(As you can see)

Note: standard practice is to use a different namespace for each package, e.g. "/my_company/admin" for the admin package, etc.
Using interceptors is the right approach: it decouples authentication from the actions themselves. You can define two different interceptor stacks, one that requires the user to be logged in, and one which doesn't. Start by copying the interceptor stack from struts-default.xml, and then customize to your requirements. These definitions can be placed in an abstract base package:
<package name="my-base" abstract="true" extends="struts-default">
<interceptors>
<interceptor-stack name="login-required">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<!-- etc -->
</interceptor-stack>
<interceptor-stack name="login-not-required">
<!-- etc -->
</interceptor-stack>
</interceptors>
</package>
Then your other packages just need to extend this base package:
<package name="admin" extends="my-base" namespace="/my_company/admin">
<default-interceptor-ref name="login-required"/>
<!-- actions defined here -->
</package>

Related

Upgrading to Cordova ios6 causes errors in xcode for project

I am able to successfully build and run my app in ios5, but when I upgrade to ios6.1.0 in order to install a plugin that will allow me to use VKwebview and reference local html files, I get 3 fatal errors in xcode:
Property 'userAgent' not found on object of type 'CDVViewController *'
Use of undeclared identifier 'CDVUserAgentUtil'. (these are repeated twice)
I am at a total loss as to even start looking for the answers.
This is my config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.slate.v2" version="1.3.1" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>ACCELERATE RMS</name>
<description>
M-learning accelerated.
</description>
<author email="support#phonegap.com" href="http://phonegap.com">
Cnnect
</author>
<content src="index.html" />
<access origin="*" />
<allow-navigation href="*" />
<icon density="mdpi" height="57" platform="ios" src="icon.png" width="57" />
<config-file overwrite="true" parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
<string>Allow the app to use your camera to take your profile picture.</string>
</config-file>
<preference name="AllowInlineMediaPlayback" value="true" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<platform name="ios">
<preference name="WKWebViewOnly" value="true" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
</platform>
<platform name="ios">
<preference name="Orientation" value="all" />
</platform>
<engine name="browser" spec="^5.0.4" />
<plugin name="phonegap-plugin-contentsync" spec="~1.4.2" />
<plugin name="cordova-plugin-camera" spec="~4.0.3" />
<plugin name="cordova-plugin-geolocation" spec="~4.0.1" />
<plugin name="cordova-plugin-file" spec="~6.0.1" />
<plugin name="cordova-plugin-whitelist" spec="~1.3.3" />
<plugin name="cordova-plugin-dialogs" spec="~2.0.1" />
<plugin name="cordova-plugin-local-notification" spec="~0.9.0-beta.3">
<variable name="ANDROID_SUPPORT_V4_VERSION" value="26.+" />
</plugin>
<plugin name="phonegap-plugin-barcodescanner" spec="~8.0.1" />
<plugin name="onesignal-cordova-plugin" spec="~2.8.1" />
<plugin name="cordova-plugin-file-transfer" spec="~1.7.1" />
<plugin name="cordova-plugin-wkwebview-engine" spec="^1.2.1" />
<plugin name="cordova-plugin-wkwebviewxhrfix" spec="~0.1.0" />
</widget>
CDVUserAgentUtil has been removed in cordova-ios#6 which is a breaking change (hence the major version increment in cordova-ios to 6).
This class is used by some Cordova plugins in your project hence the error.
You should first update all of your plugins to the latest versions so those which have been updated to removed references to CDVUserAgentUtil are used.
At least one of your plugins - cordova-plugin-file-transfer is deprecated and contains an implicit reference to CDVUserAgentUtil. In this case you could use my fork of this plugin which has been fixed to remove the reference:
cordova plugin rm cordova-plugin-file-transfer && cordova plugin add https://github.com/dpa99c/cordova-plugin-file-transfer
It may be that other plugins in your project still contain references to CDVUserAgentUtil after updating all your plugins.
If this is the case, you should search them for references:
grep -r -l 'CDVUserAgentUtil' plugins/
If you find any references and no plugin upates are available, you could:
raise an issue against the plugin asking for it to be updated
look for a fork of the plugin that has already been updated
fork the plugin and fix it yourself
If the build still fails after updating all your plugins to remove the references, there may be more implicit references such as that in cordova-plugin-file-transfer so you'll need to search for and resolve those:
grep -r -l 'userAgent' plugins/
The cordova-plugin-wkwebview-engine is deprecated in Cordova iOS#6.x for more details see, from Cordova iOS#6.x onwards it by defaults supports WKWebView not UIWebView. So, you need to remove the Cordova plugin from your project.
cordova plugin rm cordova-plugin-wkwebview-engine
Note : Please backup your project before doing any change for your safety.
For ionic v5 users
I have fixed this by upgrading cordova-plugin-ionic-webview to 4.2.1
hopping this help

How to troubleshoot local Windows UWP (Cordova) networking issues

I have a Windows 10 UWP application built using Ionic/Cordova, so my http requests originate from the embedded webview.
I can run my application at home, or on a tablet connected via cell and the http requests all work. However, when I run this on any office machine (work machines), the requests other than to local host appear to be blocked. I initially thought this was the network, however using Wireshark, I can see the request if I just run them in the machine browser, but I can't see them if I run the same from the application.
If I run the application via the desktop browser (using Ionic serve), it also works. It only seems to be when it is running in the UWP container.
Since the requests don't appear in Wireshark, I have no idea how to diagnose where this is getting blocked.
How can I diagnose this (I assume the local TCP/IP stack?)
Update 1
Some more information on a minimal application
I create a new Ionic 3 application, straight from a template, and my config.xml looks something like
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>MyApp</name>
<description>An awesome Ionic/Cordova app.</description>
<author email="hi#ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-navigation href="*" />
<feature name="http://api.phonegap.com/1.0/network" />
<access origin="*" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="android-minSdkVersion" value="16" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="windows-target-version" value="10.0" />
<platform name="android">
...
<platform name="ios">
...
</platform>
<engine name="windows" spec="^5.0.0" />
<plugin name="cordova-plugin-console" spec="^1.0.5" />
<plugin name="cordova-plugin-device" spec="^1.1.4" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.2.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<plugin name="cordova-plugin-wkwebview-engine" spec="^1.1.3" />
</widget>
When I build to the Window package, the AppxManifest.xml includes the following...
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
The test service should by CORS enabled, and I can connect to it via cell, and any other network I have tried except for our office network, as we have no idea where it is being blocked. I don't see anything in wireshark. If I run the same application via Ionic serve (so running in the desktop browser), then I have no problems. If I install the Windows version at home, I can connect. If I install it on a Tablet (eg Surface), then is does NOT connect if the serface is on the office WIFI, but it DOES connect if I tether the surface to my phone.
If we give the Surface a fixed IP it also then seems to work. I have no idea why the fixed IP makes a difference.
The actual test app code looks like the following (the only difference is the url to the office test server)...
export class HomePage {
public result : any;
public url : string;
constructor(public navCtrl: NavController, private http: Http) {
this.url='http://mytesturl';
}
public onClick() : void {
this.http.get(this.url).subscribe(res => {
this.result = res.statusText;
console.log(res);
}, (error : Response) => {
let json = error.json();
this.result = `failed ${error.statusText}`;
console.log(error);
});
}
}
We had the same problem and fixed it by adding the capability "privateNetworkClientServer" to the app. Perhaps that's your problem as well?

How to create a Shield TV APP with phonegap build

How can i install Shield TV support in Phonegap build?
when i add this to my config.xml
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
i get this error message
Error - Malformed config.xml - You can fix this here
Any ideas what i making wrong?
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.xxxx.app"
versionCode = "1.0.9"
version = "1.0.9" >
<!-- versionCode is Android only -->
<!-- version is in major.minor.patch format -->
<name>XXX</name>
<description>
XXX
</description>
<author href="xxxxx" email="contact#xxx.com">
XXX
</author>
<icon src="icon.png" />
<preference name="fullscreen" value="true" />
<preference name="StatusBarOverlaysWebView" value="true" />
<access origin="*" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<!-- Intenet zugriff plugin -->
<plugin name="cordova-plugin-whitelist" source="npm"/>
<plugin name="cordova-plugin-statusbar" source="npm"/>
<!--- <plugin name="cordova-plugin-fullscreen" source="npm" /> -->
<plugin name="cordova-plugin-vibration" source="npm" />
<plugin name="cordova-plugin-x-socialsharing" source="npm" />
<plugin name="phonegap-admob" source="npm"/>
</widget>
Well, try to check this documentation on how to properly build the PhoneGap.
You can check here the Essential Properties and Example of config.xml
I also found here in this Failed Builds that if you encountered an error Malformed config.xml, you can use the W3C validator to check whether your config.xml is a valid XML.

Telerik AppBuilder Using Custom Plugin

I have recently started some app development with Telerik's AppBuilder and am running into one thing that I'm not certain of. I added a custom plugin to my project (Cordova Local Notifications Plugin) which seemed to work (it shows up in my solution now under a Plugins folder), but I have no idea how to reference the scripts and such from it. According to the Telerik documentation (Reference the Custom Plugin in index.html and config.xml), they say to add includes for anything with in the plugin.xml file, yet this plugin doesn't have that.
Any ideas on how I reference their script so I can start using it? Do I just reference Plugins/cordova-plugin-local-notifications-master/www/local-notification.js file direct or something else? Here is their plugin.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="de.appplant.cordova.plugin.local-notification"
version="0.8.0dev">
<name>LocalNotification</name>
<description>The purpose of the plugin is to create an platform independent javascript interface for Cordova based mobile applications to access the specific Notification API on each platform.</description>
<repo>https://github.com/katzer/cordova-plugin-local-notifications.git</repo>
<keywords>notification, local notification, alarm, scheduler, tile, live tiles, ios, android, windows phone 8, wp8</keywords>
<license>Apache 2.0</license>
<author>Sebastián Katzer</author>
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
<dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device" />
<js-module src="www/local-notification.js" name="LocalNotification">
<clobbers target="plugin.notification.local" />
</js-module>
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="LocalNotification">
<param name="ios-package" value="APPLocalNotification" onload="true" />
<param name="onload" value="true" />
</feature>
</config-file>
<header-file src="src/ios/APPLocalNotification.h" />
<source-file src="src/ios/APPLocalNotification.m" />
</platform>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="LocalNotification">
<param name="android-package" value="de.appplant.cordova.plugin.localnotification.LocalNotification"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<!--
* The alarm receiver is triggered when a scheduled alarm is fired. This class
* reads the information in the intent and displays this information in the
* Android notification bar. The notification uses the default notification
* sound and it vibrates the phone.
-->
<receiver android:name="de.appplant.cordova.plugin.localnotification.Receiver" />
<!--
* This class is triggered upon reboot of the device. It needs to re-register
* the alarms with the AlarmManager since these alarms are lost in case of
* reboot.
-->
<receiver android:name="de.appplant.cordova.plugin.localnotification.Restore" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<!--
* The receiver activity is triggered when a notification is clicked by a user.
* The activity calls the background callback and brings the launch inten
* up to foreground.
-->
<activity android:name="de.appplant.cordova.plugin.localnotification.ReceiverActivity" android:launchMode="singleInstance" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</config-file>
<lib-file src="libs/android/android-support-v4.jar" />
<source-file src="src/android/LocalNotification.java" target-dir="src/de/appplant/cordova/plugin/localnotification" />
<source-file src="src/android/Receiver.java" target-dir="src/de/appplant/cordova/plugin/localnotification" />
<source-file src="src/android/Options.java" target-dir="src/de/appplant/cordova/plugin/localnotification" />
<source-file src="src/android/Restore.java" target-dir="src/de/appplant/cordova/plugin/localnotification" />
<source-file src="src/android/ReceiverActivity.java" target-dir="src/de/appplant/cordova/plugin/localnotification" />
</platform>
<!-- wp8 -->
<platform name="wp8">
<config-file target="config.xml" parent="/*">
<feature name="LocalNotification">
<param name="wp-package" value="LocalNotification"/>
</feature>
</config-file>
<source-file src="src/wp8/LocalNotification.cs" />
<source-file src="src/wp8/Options.cs" />
</platform>
</plugin>
Any JavaScript file references are automatically inserted into your app when AppBuilder creates a build, so there is really not much you have to do aside from including the plugin. BTW, you should look for custom plugins first on the Verified Plugins Marketplace - which includes instructions on including the plugin in your AppBuilder project.

MS Azure Emulator through IIS

I am facing issue of starting MS Azure Emulator every time I run the application. May be the process I am following is not correct. It is like:
1) Edit code
2) run the project by hitting F5 in Visual Studio (Azure project is startup project)
3) VS starts Ms Azure Emulator
4) finally application runs in local host (in VS inbuilt web server) having some url like 127.0.0.1:82
The overhead is that each time i am making a change, i am doing the above 4 steps. That kills considerable amount of development time.
My question: Is there any way to directly run using IIS like
1) Edit code
2) Build and start the application in browser
3) attach to the process w3wp for debugging.
I am a new in azure kinda project. Your help will be appreciated.
My ServiceDefinition.csdef:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="ABC" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="ABCWebRole">
<Sites>
<!--<Site name="External" physicalDirectory="..\External">
<Bindings>
<Binding name="Http" endpointName="HttpIn" />
</Bindings>
</Site>-->
<Site name="ABCWebRole" physicalDirectory="..\ABCWebRole">
<Bindings>
<Binding name="Http" endpointName="HttpIn" />
<!--<Binding name="HttpsIn" endpointName="HttpsIn" hostHeader="app.ABC.com" />-->
</Bindings>
</Site>
</Sites>
<ConfigurationSettings>
<Setting name="StorageConnectionString" />
<Setting name="SmtpServer" />
<Setting name="SmtpPort" />
<Setting name="SmtpUsername" />
<Setting name="SmtpPassword" />
<Setting name="myDSUserName" />
<Setting name="myDSPassword" />
<Setting name="myDSIntegratorKey" />
<Setting name="APIUrl" />
<Setting name="AccountManagementUrl" />
<Setting name="myDSEmail" />
<Setting name="myDSAccountId" />
<Setting name="DSmemberPassword" />
<Setting name="QueueNamespace" />
<Setting name="QueueIssuer" />
<Setting name="QueueIssuerKey" />
<Setting name="ShowingFeedbackQueueName" />
<Setting name="ServiceReportQueueName" />
</ConfigurationSettings>
<LocalResources>
<LocalStorage name="ABCLocal" cleanOnRoleRecycle="true" sizeInMB="1024" />
<LocalStorage name="DiagnosticStore" cleanOnRoleRecycle="true" sizeInMB="7000" />
<LocalStorage name="CustomLogging" cleanOnRoleRecycle="true" sizeInMB="1024" />
</LocalResources>
<Certificates>
<Certificate name="app.ABC.com" storeLocation="LocalMachine" storeName="My" />
</Certificates>
<Endpoints>
<InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="app.ABC.com" />
<InputEndpoint name="HttpIn" protocol="http" port="80" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
</WebRole>
<WorkerRole name="ABCWorkerRole" vmsize="ExtraSmall">
<!--Remove diagnostics permissions fix... Remember to remove the associated files<Startup>
<Task commandLine="FixDiag.cmd" executionContext="elevated" taskType="background" />
</Startup>
-->
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<ConfigurationSettings>
<Setting name="StorageConnectionString" />
<Setting name="SmtpServer" />
<Setting name="SmtpPort" />
<Setting name="SmtpUsername" />
<Setting name="SmtpPassword" />
<Setting name="QueueNamespace" />
<Setting name="QueueIssuer" />
<Setting name="QueueIssuerKey" />
<Setting name="ShowingFeedbackQueueName" />
<Setting name="ServiceReportQueueName" />
</ConfigurationSettings>
<LocalResources>
<LocalStorage name="DiagnosticStore" cleanOnRoleRecycle="true" sizeInMB="7000" />
<LocalStorage name="CustomLogging" cleanOnRoleRecycle="true" sizeInMB="1024" />
</LocalResources>
</WorkerRole>
</ServiceDefinition>
I typically configure my service to be able to run in Azure or in IIS . It takes a little time to set it up at the beginning then later it's a matter of which project you choose to run from visual studio, so when you set the .ccproj as startup project, it runs in azure when you hit F5. Otherwise, when you set the .csproj as startup project, you can then run it in cassini, IIS Express or Local IIS based on how you configure your web app. The one time change that you need to make is move the logic that hooks to the Azure Diagnostics listener from the web.config to Global.asax->Application_Start() or WebRole.cs->Onstart() methods where you can check if the service is running inside or outside Azure environment through the RoleEnvironment object and the code would like this
if (RoleEnvironment.IsAvailable)
{
Trace.Listeners.Add(new DiagnosticMonitorTraceListener
{
Name = "AzureDiagnostics",
Filter = new EventTypeFilter(SourceLevels.All)
});
}
else
{
...hook it to a listener that writes logs to an xml file or something
}
Keep in mind that when running outside the azure environment, you're going to lose Azure specific functionalities, like ability to read .cscfg values through the RoleEnvironment object (but web.config will still be accessible from both). And you have to also run the worker role manually through a different type of configuration (less straight forward)

Resources