2 Replies Latest reply on Oct 18, 2006 2:52 AM by Manuel Aznar Pérez

    Conversor error in examples/secutiry

    Manuel Aznar Pérez Newbie

      Jboss-jems-installer-1.2.0-BETA2 -> JBoss-EJB3
      Jboss-seam-1.0.1GA

      I install examples-security change datasource to mysql datasource. the deployment is ok.

      But in login page said : "username" conversion error
      I put login name : demo password : demo

      In log don't show errors.

      In database mysql create in Roles table:

      one column user_username and other USERNAME.

      CREATE TABLE `Role` (
      `roleId` int(11) NOT NULL,
      `role` varchar(255) default NULL,
      `user_username` varchar(255) default NULL,
      `USERNAME` varchar(255) default NULL,
      PRIMARY KEY (`roleId`),
      KEY `FK26F496CCD1BE70` (`user_username`),
      KEY `FK26F496C9CE647C` (`USERNAME`),
      CONSTRAINT `FK26F496C9CE647C` FOREIGN KEY (`USERNAME`) REFERENCES `Users` (`username`),
      CONSTRAINT `FK26F496CCD1BE70` FOREIGN KEY (`user_username`) REFERENCES `Users` (`username`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

      I fill two columns with demo, demo and shane, shane.

      But don't work.

      Any idea?

        • 1. Re: Conversor error in examples/secutiry
          Shane Bryzak Master

          That table looks wrong, the Role table should only have one username column. I don't know if it's an artifact of using MySql, but you could try giving the user entity a surrogate key instead of using the username.

          • 2. Re: Conversor error in examples/secutiry
            Manuel Aznar Pérez Newbie

            -In example/security/resources/import.sql (CVS) :

            insert into Users (username, password) values ('shane', 'password')
            insert into Users (username, password) values ('demo', 'demo')
            insert into Role (roleid, username, role) values (1, 'shane', 'user');
            insert into Role (roleid, username, role) values (2, 'shane', 'admin');
            insert into Role (roleid, username, role) values (3, 'demo', 'user');
            insert into Role (roleid, username, role) values (4, 'demo', 'admin');


            -Don't have column "user_username"

            -In Role.java :

            package org.jboss.seam.example.security;
            
            import javax.persistence.Entity;
            import org.jboss.seam.annotations.Name;
            import javax.persistence.Id;
            import javax.persistence.ManyToOne;
            import javax.persistence.JoinColumn;
            
            /**
             * A user role.
             *
             * @author Shane Bryzak
             * @version 1.0
             */
            @Entity
            @Name("userrole")
            public class Role
            {
             private Integer roleId;
             private User user;
             private String role;
            
             @Id
             public Integer getRoleId()
             {
             return roleId;
             }
            
             @ManyToOne
             public User getUser()
             {
             return user;
             }
            
             public String getRole()
             {
             return role;
             }
            
             public void setRoleId(Integer roleId)
             {
             this.roleId = roleId;
             }
            
             public void setUser(User user)
             {
             this.user = user;
             }
            
             public void setRole(String role)
             {
             this.role = role;
             }
            }
            


            -In User.java :

            package org.jboss.seam.example.security;
            
            import java.util.Set;
            import javax.persistence.Entity;
            import javax.persistence.Id;
            import javax.persistence.OneToMany;
            import javax.persistence.Table;
            
            import org.jboss.seam.annotations.Name;
            import javax.persistence.JoinColumn;
            
            /**
             *
             * @author Shane Bryzak
             */
            @Entity
            @Name("user")
            @Table(name="Users")
            public class User
            {
             private String username;
             private String password;
             private Set<Role> roles;
            
             @Id
             public String getUsername()
             {
             return username;
             }
            
             public String getPassword()
             {
             return password;
             }
            
             @OneToMany
             @JoinColumn(name = "USERNAME")
             public Set<Role> getRoles()
             {
             return roles;
             }
            
             public void setPassword(String password)
             {
             this.password = password;
             }
            
             public void setUsername(String username)
             {
             this.username = username;
             }
            
             public void setRoles(Set<Role> roles)
             {
             this.roles = roles;
             }
            }