Search code examples
javaweb-servicesapache-axis

Authentication and acknowledgement code


The is a webService code. I'll generate WSDL using bottom up approach from below code and publish it (using apache axis2 codeGenerator). I am writing JAVA Code that checks username and password. Once the username and password are authenticated, then my code should check unique ID is integer and also not zero, then it will check resolution is "RESOLVED" or not. IF uniqueID and resolution are true, then my code should return true as acknowledgement.

I tried the below JAVA code but it is not fully correct and not able to achieve the desired results. Please can any one help me to correct my AuthMain class to generate WSDL successfully. Thank you. I tried my best to explain the issue. If I missed any points in description plz let me know instead of marking negative (sometimes it tends to happen even though I don't want to miss any points).

AuthMain class

public class AuthMain {


/**
 * @param args
 */

// TODO Auto-generated method stub
Authenticate au = new Authenticate();

String resolution = null;
int bizId =0;

public boolean validateState() {
    if(resolution.equalsIgnoreCase("Resolved"))
    {
        return true;
    }
    else
    {
        System.out.println("Invalid State information");
        return false;
    }
}
    public boolean validateId()
    {

        if(bizId==0)
        {
            System.out.println("Invalid bizflow ID");
            return false;
        }
        else
        {
            return true;
        }
    }


}

below is my Authenticate.JAVA

public class Authenticate {

private  String password;
private String userName;


public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public boolean userValidation()
 {
 if(userName.equals("UserName@123"))
 {
     return true;
 }
 else
 {
System.out.println("Invalid User Name");
     return false;
 }
}

public boolean passwordValidation()
{
if(password.equals("Password@123"))
{
    return true;
}
else
{
    System.out.println("Invalid Password");
return false;
}
 }

 }

Solution

  • I would suggest, don't use a selfwirtten Authentification, there is no reason to write an own securityfeature.

    For example if you use the JBoss AS you can add the loginmechanism with simple annotation https://docs.jboss.org/author/display/JBWS/Authentication

    Add the annotations, add the securitydomain(with the prefered login module, eventually add some SSL/TSL) => done