I have tried to work this out for several days. I am trying to create a form based authentication for my JAVA EE app which is running on wildfly. I am using JAX-RS and AngularJS. I have created the wildfly security domain as follows
<security-domain name="malison">
<authentication>
<login-module code="Database" flag="required">
<module-option name="dsJndiName" value="java:jboss/datasources/malisonDS"/>
<module-option name="principalsQuery" value="select password from USER where user=?"/>
<module-option name="rolesQuery" value="select position from USER where user=?"/>
</login-module>
</authentication>
</security-domain>
and configured my web.xml
<security-constraint>
<display-name>UnSecuredPages</display-name>
<web-resource-collection>
<web-resource-name>Access</web-resource-name>
<url-pattern>/api/user/*</url-pattern>
</web-resource-collection>
<web-resource-collection>
<web-resource-name>Access</web-resource-name>
<url-pattern>/user.jsp</url-pattern>
</web-resource-collection>
<web-resource-collection>
<web-resource-name>Access</web-resource-name>
<url-pattern>/assets/*</url-pattern>
</web-resource-collection>
</security-constraint>
<security-role>
<role-name>ADMIN</role-name>
</security-role>
Now I have a problem writing code for my authenticate function. Which should send a success reply to the client. I thought this would work.
@POST
@Path("/authenticate")
@Consumes(MediaType.APPLICATION_JSON)
public String authenticate(@Context HttpServletRequest request, JSONObject obj){
String userName = String.valueOf(obj.get("username"));
String password = String.valueOf(obj.get("password"));
try{
request.login(userName, password);
}
catch(Exception e){
e.printStackTrace();
}
return "{\"success\":true, \"msg\": \"Saved successfully\"}";
}
Can anyone provide a solution or work around I would be grateful...