Grails Spring Security Core - Generating password manually - grails

I am trying generate a password manually to insert it directly into the database. But unfortunatelly I doesn´t work.
Spring security core is set to use MD5 encoding. I generate a new password in a md5 hash generation webpage, update the bbdd but I can not log in with that user.
I guess it has some specific structure before enconding but I don´t know it.

Just have a look in the source code of the basespasswordencoder class.
protected String mergePasswordAndSalt(String password, Object salt, boolean strict) {
if (password == null) {
password = "";
}
if (strict && (salt != null)) {
if ((salt.toString().lastIndexOf("{") != -1) || (salt.toString().lastIndexOf("}") != -1)) {
throw new IllegalArgumentException("Cannot use { or } in salt.toString()");
}
}
if ((salt == null) || "".equals(salt)) {
**return password**;
} else {
**return password + "{" + salt.toString() + "}"**;
}
}
}
http://grepcode.com/file/repo1.maven.org/maven2/org.springframework.security/spring-security-core/3.0.1.RELEASE/org/springframework/security/authentication/encoding/BasePasswordEncoder.java#BasePasswordEncoder.mergePasswordAndSalt%28java.lang.String%2Cjava.lang.Object%2Cboolean%29

Related

Criteria in grails

Could you tell me what's wrong in my Criteria here?
def users
def u = User.createCriteria()
users = u.list (max: max, offset: offset) {
eq("account",account)
and {
if(teacherName != null && teacherName != ""){
like("userName", "%"+teacherName+"%")
}
if(mobileNumber != null && mobileNumber != ""){
like("mobileNumber", "%"+mobileNumber+"%")
}
eq("status", Status.ACTIVE)
eq("userType","Account Teacher")
}
}
return users
}
the list returned empty why?
The code you posted is unnecessarily verbose. An equivalent implementation is:
def users = User.withCriteria(max: max, offset: offset) {
eq("account", account)
if (teacherName) {
like("userName", "%${teacherName}%")
}
if (mobileNumber) {
like("mobileNumber", "%${mobileNumber}%")
}
eq("status", Status.ACTIVE)
eq("userType", "Account Teacher")
}
I can't say why this isn't working because I don't know what the User domain class looks like or what behaviour the query is supposed to exhibit, but it ought to be easier to debug a more concise implementation.

What is the query to fetch result from database in deployd server?

I am new in delpoyd server and need to validate email address already exist.
I read his document but unable to achieve result as expected.
According to deployd doc, I was trying this.
dpd['to-do'].get(query, function (result) { console.log(result); });
Please help me if anyone know.
This is the code I use for validating whether email already exists.I use this code in the Validate event.The need for checking the method 'PUT' is to prevent users from changing the email id to something that already exists after registering.
function validate(result, field) {
if (method === 'PUT') {
if (result.length === 0) {
} else if (!(result.length === 1 && result[0].id === id)) {
error(field, field + " is already in use");
}
} else if (result.length !== 0) {
error(field, field + " is already in use");
}
}
if (!internal) {
var email;
var method = ctx.method;
email = {
"email": this.email
};
dpd.users.get(email, function (result) {
validate(result, "email");
});
}

How to use findAll in Grails with "if" statement to verify if the field is null before searching

I need to create a findAll criteria in Grails, but I have 4 fields to search. I just need to search by those fields if a specific variable is not null.
For example, if all variables are not null, I'll search by all the fields like the following:
list = MyObject.findAll {
'in'("job", jobList)
'in'("businessUnit", businessUnitList)
'in'("company", companyList)
eq("regularTime", params.regularTime)
}
What I want to do is something like this:
regularTimeList = RegularTime.findAll {
if(params.job != null) 'in'("job", jobList)
if(params.businessUnit != null) 'in'("businessUnit", businessUnitList)
if(params.company != null) 'in'("company", companyList)
if(params.regularTime != null) eq("regularTime", params.domainClassSearchFilters.regularTime)
}
It's not working so I'd like to know if there is a way to do that because right now I had to create a lot of ifs to verify them... I need one if to each scenario... Like:
If job is not null and company is not null, one findAll. If company is not null and regularTime is not null, another findAll.
You can do something like this:
regularTimeList = RegularTime.findAll {
if (params.job != null) params.job in jobList
if (params.businessUnit != null) params.businessUnit in businessUnitList
if (params.company != null) params.company in companyList
if (params.regularTime != null) regularTime == params.domainClass
}
I don't know what happened, but the way Above didn't work for me...
I solved it using criteria.
list= MyObject.createCriteria().list {
if(params.job != null && "" != params.domainClassSearchFilters.job )
'in'("job", jobList)
if(params.businessUnit != null && "" != params.businessUnit)
'in'("businessUnit", businessUnitList)
if(params.company != null && "" != params.company)
'in'("company", companyList)
if(params.regularTime != null && "" != params.regularTime && params.regularTime.isDouble())
eq("regularTime", Double.parseDouble(params.regularTime))
}

Not able to clear cookies properly

Hi my application has two types of login's one is facebook and other is normal log in. To differentiate between them and bring the values accordingly i have used cookies and clearing those in logout event like this.
But when i login through email and password and then logout and again log in through Fb the UserCookie cookie is still persisting and its entering to the first if statement again
public ActionResult Logout(string returnUrl = "/")
{
try
{
FormsAuthentication.SignOut();
}
finally
{
if (Request.Cookies["UserCookie"] != null)
{
Request.Cookies["UserCookie"].Expires = DateTime.Now;
Request.Cookies["UserCookie"].Value = "";
}
if (Request.Cookies["fbUserUserID"] != null)
{
Request.Cookies["fbUserUserID"].Expires = DateTime.Now;
Request.Cookies["fbUserUserID"].Value = "";
}
if (Request.Cookies["fbFirstName"] != null)
{
Request.Cookies["fbFirstName"].Expires = DateTime.Now;
Request.Cookies["fbFirstName"].Value = "";
}
FederatedAuthentication.WSFederationAuthenticationModule.SignOut(true);
}
//return Redirect(returnUrl);
return View();
}
and in my view i am checking for cookies like this
#if (HttpContext.Current.Request.Cookies["UserCookie"] != null && HttpContext.Current.Request.Cookies["UserCookie"].Value != "")
{
}
else if (HttpContext.Current.Request.Cookies["fbFirstName"] != null && HttpContext.Current.Request.Cookies["fbFirstName"].Value != "")
{
}
but its not clearing i guess its showing empty string "" for the cookie value in the controller but i donno whats happening in view.
is there any thing that i am missing?
Request.Cookies is used to read the cookies that have come to the server from the client. If you want to set cookies, you need to use Response.Cookies so the server sends the cookie information the server response.
Try modifying your code to use Response.Cookies instead of Request.Cookies when you are trying to unset the cookies.

APN is not specified?

iam creating httpConnection ,but when run the application it gives following exception ?
java.io.IOException
APN is not specified ?
I think the See the Developer Knowledge Base article: link can solve your problem
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_make_an_HTTP_or_socket_connection.html?nodeid=826935&vernum=0
also see this sample code
private static String getConnectionString(){
String connectionString="";
if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){
connectionString="?;interface=wifi";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){
connectionString = "?;&deviceside=false";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT)==CoverageInfo.COVERAGE_DIRECT){
String carrierUid=getCarrierBIBSUid();
if(carrierUid == null) {
connectionString = "?;deviceside=true";
}
else{
connectionString = "?;deviceside=false?;connectionUID="+carrierUid + "?;ConnectionType=mds-public";
}
}
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {
}
return connectionString;
}
More to the point,
http://supportforums.blackberry.com/t5/Java-Development/How-to-get-APN-Settings/td-p/1704995
It is not completely possible to put the APN settings in your url eg. there is no way to get the username and password.

Resources