Saturday, 12 November 2016

Angular 2


Saturday, 12 November 2016

Finally, Started learning angular 2.. It is been  a while, i wanted to learn angular 2 but got busy with other works.. Then my company itself provided us angular training + FOOD :D... hooo..! Thank You..
Training ended good.. hope i can share my road block in the following post.. :)

as of now.. https://angular.io/ & my angular trainer gitub
https://github.com/MicroTamil-Haribabu/ 



Thursdau 09 Feb 2017


Yep, After a long gap, i thought of start working on Angular 2. Now only got bit free from  project works.
so, now my 1st task to myself is, guess.. the same login page, what else it would be.. the developers who start learning a language obviously first task would be LOGIN page. So folks, lets begin.

I'm gonna continue with the application which i have in hand, which Mr.Haribabu helped me to create in a 3 days angular training.




Hope, it looks not that bad, lets do the logic in the fore-coming days.. ;)

Thursday, 20 October 2016

Spring Security + ACL button level Authentication + URL Authentication


In my case, i have some ArrayList of String in httpsession. i need to show a button the user, only if the button function name is available in that list. i have implement it via Spring Security ACL.
For that add ACL + spring security core jar in the classpath.
<dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>${spring.security.version}</version>
    </dependency>       
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.security.version}</version>
    </dependency>       
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-acl</artifactId>
        <version>${spring.security.version}</version>
    </dependency>
then, i have added the bean in xml.
<global-method-security pre-post-annotations="enabled">
  <expression-handler ref="expressionHandler"/>
</global-method-security>    
<beans:bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
    <beans:property name="permissionEvaluator" ref="permissionEvaluator"/>
</beans:bean> 
<beans:bean id="permissionEvaluator" class="com.config.BasePermissionEvaluator"/>
then the handler class BasePermissionEvaluator, this class will evaluate, if that button has permission,
public class BasePermissionEvaluator implements PermissionEvaluator{
 @Override
 public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {

  boolean hasPermission = true;
  // targetDomainObject [101001, 102001, 103001, 201001, 202001, 203001, 204001, 205001, 206001, 301001, 302001, 303001]permission : 303001
    @SuppressWarnings("unchecked")
    List<String> functionList =(List<String>) targetDomainObject;       
    if(!functionList.contains(permission.toString())) {
        hasPermission = false;  
    }
  return hasPermission;
 }

 @Override
 public boolean hasPermission(Authentication authentication,
   Serializable targetId, String targetType, Object permission) {
    throw new RuntimeException("Id and Class permissions are not supperted by this application");
 }
}
Finally in the jsp,
    <%@taglib uri="http://www.springframework.org/security/tags"
 prefix="sec"%>

<sec:accesscontrollist hasPermission="101001"   domainObject="${USER_FUNCTIONS}"> 
                    <button type="reset" id ="clearMPId"><spring:message code="mp.clear"/></button>
  </sec:accesscontrollist>   

for URL authentication, please follow

https://stackoverflow.com/a/45354372/2573744

Hope it helps.

Friday, 14 October 2016

Thursday, 1 September 2016

multi file upload + ajax post + jQuery

mannnnNNNNNN... File uploading.. File handling.. File writing.. File reading.. 
All these file operations, i'm bit scared of.. on these, i can now do file reading and file writing also can handle file.. but, this file upload.. i'm always had a fear of.. this time i got a chance to face it.. and lets see.. im confident, ill come up with a solution as always.. background songs going on.. lets start..

so.. this time, i got a partner.. to give me an UI.. so he gave me.. 

https://blueimp.github.io/jQuery-File-Upload/index.html

started with this.. implemented it my project.. UI came.. surprisingly, the expected functionality came.. however, as always, it ll not go that smooth.. i clicked the start button.. i cant guess.. where the url linq going.. ???

getting  an error SyntaxError: Unexpected token < in JSON at position 0

spend hours.. cannot find.. ask him to find, when uploading where the file is uploading.. 

http://hmkcode.com/spring-mvc-jquery-file-upload-multiple-dragdrop-progress/



Wednesday, 24 August 2016

JAS

JAS - Java Authentication Server

This time i been assigned with such  a wonderful task.. JASzzzzzzz
Initially, i given the requirement of authenticating username & password in the server and returning user functionalities, and according to that show the menu items..

With that i start the work.. 

SERVER Side 

i created a new dynamic project in eclipse.. Dynamic web module 2.5.. caz, AXIS 2 support only for this.. 
convert it a maven project..
-- include the AXIS 2 dependencies.. // not required

set the Axis 2 runtime location in  windows - preference - webservices - Axis 2.x Preference - "D:\Siva\AXIS2 "
Saying about AXIS 2, 
   - it is used to convert my class file to WSDL file
   - expose my class as a webservice.
yes most of my work done by itself.. thanks for all AXIS 2

so, i was saying.. create a interface and implement it in a class  in your package and do your business logic

Right click interface file which need to be expose - web services - create web service-  set the server environment and set the webservice environment as AXIS 2 - click finish.

Thats it.. you application is now deployed.. You have created soap server application.
to check it is working fine.. check your WSDL file is generating in the server.

Save the WSDL file. From this WSDL file we gonna generate the java file

Client Side

create a dynamic web project - convert it a maven project - in pom.xml add cxf dependency 

Saying abt CXF, it helps us to generate the java file from WSDL file we have.

<properties>
<cxf.version>3.1.0</cxf.version>
</properties>

<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>

</dependency>

add the plugin

<!-- Generate Java classes from WSDL during build -->
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <!-- which source folder the generated classes should be placed in a package -->
<!--                             <sourceRoot>${project.basedir}/src/main/java</sourceRoot> -->
                      <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <!-- put the wsdl file in this location -->
                                    <wsdl>${project.basedir}/src/main/resources/wsdl/Login.wsdl</wsdl>
                                    <extraargs>
                                        <extraarg>-client</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin>

 this ll generate the java file in the target folder.

from the generated end points, use that code to connect to the server. 

change the wsdl location,
 wsdlLocation = "http://localhost:9001/demo-server/services/DemoClass?wsdl",

Thats it. 

thats what i thought..

But.. 

It ll not finish that easy.. after reviewing i understand, the client requirement, they need the older version of axis.. ie.. AXIS 1.4 

AXIS 1.4 

Server side

hooooo.. got chance to do R&D on that..

same way i started.. of implementing it with AXIS 1.4

Road blocks:

  - In the server side, i cannot expose the webservice as before. it give me..

IWAB0398E Error in generating WSDL from Java:  java.lang.ClassCastException: org.apache.axis.encoding.ser.BeanSerializer cannot be cast to org.apache.axis.encoding.Serializer

  - Without the server running, i cannot generate the java files in the client side. caz, there is no end point.. 

so im struck here.. 

then got an idea of do everything manually, caz, at the starting of the internet, they did like that.. 
there was not ANT, Maven or Gradle.. 

so started.. with the reference 

http://www.digizol.com/2008/07/web-service-axis-tutorial-client-server.html

1. i compiled all the java files in commad promet | terminal.. 

javac -d classes test\com\admin\service\*.java 

2. generate wsdl file from the compiled classes

java org.apache.axis.wsdl.Java2WSDL  -o wsdl/Login.wsdl -n http://service.admin.com.test/  -l http://localhost:8080/admin/services/Login?wsdl=Login.wsdl test.com.admin.service.Login

3. Then created the deployment war file manually and deployed it in the server.

4. Finally linq the WSDL to the server

java org.apache.axis.client.AdminClient src\test\com\admin\service\generated\deploy.wsdd

now got struck here.. it is showing connection timeout.. means, it cannot find that deployed environment.. finding way to resolve it..

thanks to this site..
https://cuppajavamattiz.wordpress.com/2013/10/04/creating-a-simple-web-service-using-apache-axis-1-4/

caz of this i can able to continue with, what i was doing.. also gave me a bit confidence of, i going in the right path..

so 4th step gave me an error.. 
so this site was saying, to comment the following line in web.xml

<!--
 <servlet-mapping>
   <servlet-name>AdminServlet</servlet-name>
   <url-pattern>/servlet/AdminServlet</url-pattern>
 </servlet-mapping>
-->
did that. and did the 4th step again.. this time the error changed to
D:\WSDL2JAVA>java org.apache.axis.client.AdminClient src\sg\com\jp\admin\service \generated\deploy.wsdd Processing file src\sg\com\jp\admin\service\generated\deploy.wsdd Exception: AxisFault faultCode: {http://xml.apache.org/axis/}HTTP faultSubcode: faultString: (404)Not Found faultActor: faultNode: faultDetail: {}:return code: 404 &lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/7.0.67 - Error report&lt;/tit le&gt;&lt;style&gt;&lt;!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;ba ckground-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif; color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Ari al,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-f amily:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-famil y:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family: Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--&gt;&lt;/style&gt; &lt;/hea d&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 404 - /axis/services/AdminService&lt;/h1& gt;&lt;HR size=&quot;1&quot; noshade=&quot;noshade&quot;&gt;&lt;p&gt;&lt;b&gt;ty pe&lt;/b&gt; Status report&lt;/p&gt;&lt;p&gt;&lt;b&gt;message&lt;/b&gt; &lt;u&gt ;/axis/services/AdminService&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;description&lt ;/b&gt; &lt;u&gt;The requested resource is not available.&lt;/u&gt;&lt;/p&gt;&lt ;HR size=&quot;1&quot; noshade=&quot;noshade&quot;&gt;&lt;h3&gt;Apache Tomcat/7. 0.67&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt; {http://xml.apache.org/axis/}HttpErrorCode:404

i changed the project name to axis, created folder services, put my compiled class file in adminservice folder then i did the 4th step again, this time...

D:\WSDL2JAVA>java org.apache.axis.client.AdminClient src\test\com\admin\service \generated\deploy.wsdd Processing file src\test\com\admin\service\generated\deploy.wsdd <Admin>Done processing</Admin>

Yaaayyyyyyyyy... i have successfully exposed my web service.. also i can see my wdsl

So the Server part is completed, since we already had generated the java file from WSDL, i believe, we can directly connect to the end points through that. So the task moved to done.



Monday, 22 August 2016

Resource files not loading after adding Spring Security and 2 times login issue solution

referred a lot in stack-overflow, other sites.. didn't found a solution for this.. already spend 8-10 hrs, in this issue.. 

progress i made:

* when i changed the working copy, the old issue 2 time login issue came again, referred http://www.baeldung.com/spring_redirect_after_login
and created LoginSuccessHandler and resolved that issue.

* but this css issue taking hours..

Finally, decided to drop this and i was reverting the things i did..

after reverting also, the css issue was not resolving.. 

then only i understand it is not spring security issue, it the controller issue..

while updating, i added ** in the mapping.. it blocked the css..


@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET }, value = {

"/**", "/login**" })

spend alot of time for this.. Finally resolved..