Play Framework, RAW field doesn't work properly - oracle

I´ve got a User model like this one
#Entity
#Table(name="SHOPPER")
public class User extends GenericModel {
#Id
#Column(name="SHRFNBR")
#GeneratedValue(generator="SEQ_SHP", strategy=GenerationType.SEQUENCE)
#SequenceGenerator(name="SEQ_SHP", sequenceName="SEQ_SHP", allocationSize=1)
public Long id;
#Column(name="SHLOGID")
public String email;
#Column(name="SHLPSWD")
public String password;
public static User isUser(String user, String pass){
return User.find("byEmailAndPassword", user, pass).first();
}
}
On DB password its RAW type and on Controller it´s encoded with RSA.
The main thing it´s that it doesn't find any result because the binary that goes into the DB seems different than the one that's on the field.
At first I thought it could be some character encoding issue on the Application but then I pointed to the same DB but on production and it worked. So I checked the Devel DB and found another Characterset instead of ISO-8859-1 (prod) was ISO-8859-15 (devel) that seems little different.
After updating the devel characterset the situation it´s the same. Is there any other place where the RSA string is getting wrong encoded on DB?
Process description:
The process is a login process where the user inserts email and password, the last one gets encoded with RSA and the result it´s sent to DB for comparison.
The field on DB contains a value like this one:
CB4F3ECB7763C98EF67CA761700D1FB255F90E4473B1BB594B2238756307DF2D155D57A2CBA2930C‌162CB0634765D48EA111F743F6825F2457340148F680E300
More info:
DB Oracle 10g
Play Framework 1.2.4

Don't map binary data to a String, use byte[] instead, this way you won't have any character encoding issues.

Related

Spring boot Spring data mySql

My following entity generated an error when i add these attributes
#Size(min=1, max=6)
private String status;
#Size(min=1, max=2)
private String vip;
#Size(min=1, max=2)
private String sensitive;
However when i delete these attributes everything is ok no error found.
I don't know what's wrong with these attributes.
Is someone have an idea to help?
the error:
That's because SENSITIVE is a SQL reserved keyword.
Finaly i find the solution. the only attribute which generate the error is sensitive.
I just rename the attribute to mySensitive and everything is ok now.

PersistentLocalDateTimeAsString results in DateTimeParseException

In the hibernate model when using jadira-usertype org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTimeAsString as Type, the conversion is not reversible.
#Column(name="requested_start")
#Type(type="org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTimeAsString")
private LocalDateTime requestedStartDate;
When creating object with datetime in following format;
myObject.setRequestedStartDate(LocalDateTime.parse("2014-12-28T19:30:00"));
is stored in DB (MariaDB) as "2014-12-28T19:30" ignoring the seconds part (don't know why).
when querying back the data, I'm getting the following exception
java.time.format.DateTimeParseException: Text '2014-12-28T19:30' could not be parsed at index 16
But, If I set date as "2014-12-28T19:30:01" with seconds set to "01", it is working fine.
I also tried setting the springframework's DateTimeFormat, still facing the same exception.
#Column(name="requested_start")
#Type(type="org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTimeAsString")
#DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime requestedStartDate;
You can try this modified pattern "yyyy-MM-dd'T'HH:mm[:ss]".
The meaning of the square brackets is indicating an optional part during parsing - see javadoc.

SQLite with WebMatrix.WebData.SimpleMembershipProvider Long to Int Cast Error

I'm trying to use the SimpleMembershipProvider with SQLite to enable authentication on my site. I have it initialized in my Global.aspx and can create users, however I can't log users in. I get the following error when I try to call WebSecurity.Login([UserName], [Password]):
Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
The stack trace is as follows (after I make the call to the Login function:
CallSite.Target(Closure , CallSite , Object ) +146
System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +661
WebMatrix.WebData.SimpleMembershipProvider.VerifyUserNameHasConfirmedAccount(IDatabase db, String username, Boolean throwException) +315
WebMatrix.WebData.SimpleMembershipProvider.ValidateUser(String username, String password) +162
WebMatrix.WebData.WebSecurity.Login(String userName, String password, Boolean persistCookie) +32
I know that SQLite only allows Int64 values in numeric columns (that aren't float). The question is: how do I get the SimpleMembershipProvider to work with Int64 values? I had a look at the source code for the offending routines listed in the stack trace and it seems that all numbers are being explicitly cast before being returned from their Int32 functions. However, I don't have the source to System.Dynamic.UpdateDelegates.UpdateAndExecute1 or CallSite.Target, so I can't see what is going on there. What is more, those are probably pre-compiled. So, the question remains, how can I get this to work?
The SimpleMembership Provider only supports SQL Server and SQL Compact 4.0. SQLite is not supported. If you want to use SQLite, you will have to create your own implementation of ExtendedMembershipProvider. You can more or less copy SimpleMembershipProvider.cs, and just modify the bits where the data type conflict arises.

how do I create a file upload in grails which works with oracle?

got the following problem:
I tried to create a simpel file upload functionality in grails. I just created a domain class with a
byte[] rawFile
as property. Grails did most of the rest for me. It worked fine for the standard hsqldb in the dev environment.
Then I deployed it to the server with an oracle db configured (thin driver). Everything but the file upload works fine with the oracle db. For the file upload I get a (as far as I can remember)
SQLException: ORA-01461: can bind a LONG value only for insert into a LONG
I tried several ways to fix it (including some columnmappings to blobs and using java.sql.blob instead of byte[]) but nothing really worked and I went in a direction where my code wouldn't be db independent anymore.
Google didn't really help me and my grails books don't help too.
Saving the file to the disk isn't a good solution im my opinion.
So here's my question:
how do I create a file upload in grails which works with oracle?
Update: got some additional infos. Managed to reproduce the problem with the XE-Edition of Oracle:
Hibernate creates a VARBINARY(255) column for the rawFile. So I tried to upload a 4 bytes file and it worked.
I then changed the type of the column manually to 'blob' and it worked with bigger files.
I then added
static mapping = {
columns {
rawFile type:'blob'
}
}
to my domain class and it stopped working:
ERROR errors.GrailsExceptionResolver - [B cannot be cast to java.sql.Blob
java.lang.ClassCastException: [B cannot be cast to java.sql.Blob
:-(
Instead of setting the type to blob try to increase the maxSize constraint:
static constraints = {
rawFile(maxSize: 20 * 1024 * 1024) // 20 MBs
// ...
}
If you want to use a Blob field in Oracle then set your domain property to byte[] and set the type to org.hibernate.type.MaterializedBlobType. The MaterializedBlobType handles conversion back and forth between Oracle (presumably other databases, but I've only done this on Oracle) and byte[].
byte[] blobFile
static mapping = {
blobFile type: org.hibernate.type.MaterializedBlobType
}
I'm not sure what you are doing in your controller, try doing it manually to see what happens:
request.fileMap.each { name, file ->
if (!file.empty) {
model.rawFile = file.bytes
}
}
model.save()
Try setting the sqlType.
Using a domain field with type byte[] with sqlType set to "blob" in the mapping block works for me using Grails 2.3.1 and Oracle 11g. Grails handles the type conversion automatically.
class Image {
byte[] image
static mapping = {
image(sqlType: "blob")
}
}

Unable to load connection string using xRM data context

Edited to add solution:
changed to use the constructor that takes a Microsoft.Xrm.Client.CrmConnection rather that a String connection string and it works.
I used the crmsvcutil.exe to generate the data context for our crm environment. When I try to initialize the connection.
This line:
public CSIDataContext(global::System.String name)
: base(name)
throws this error:
Unable to load the connection string name 'Authentication Type=AD; Server=/rest of conn string is here/'
This code resides in a BizLayer class library project and is being called from a win form test project. If both the generated entities class and the calling code are in the same project, I don't get that error.
It sounds like you're passing the full connection string in the constructor rather than the name of the connection string in the connectionStrings node of the app.config/web.config.
The XRM connection string is very similar to an ADO.NET connection string in that it resides in the element in the app.config/web.config. So, you would normally place the full connection string into your config with a name like so:
<connectionStrings>
<add name="XrmConnectionString" connectionString="Authentication Type=AD; Server=http://server.com; User ID=Domain\Username; Password=P#$$w0RD"/>
</connectionStrings>
Then, when you want to initialize the XRM context, you just supply the connection string's name:
var dataContext = new XRMDataContext("XrmConnectionString");
Try that and see if it works for you.

Resources