It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
url:
http://www.xxx.com/getUser?userid=1&username=john&usersex=1
Java Class:
Class User{
private long userId;
private String userName;
private int userSex;
// get and set methods
...
//constructos
User(long userId, String userName, int userSex){
this.userId = userId;
this.userName = userName;
this.userSex = userSex;
}
}
how to convert this url to User object?for this url,i want to get User user = new User(1,"john",1).and does have any java framework?
NO. just use substring for that,and set in your object
I think there is no java framework for this. Since solution is quite simple, you can implement it yourself.
get attributes passed into URL via Servlet's request parameters.
set attributes to User either dynamically using Java Reflection API, or manually by implementing lots of ifelse statements
Have a look at Apache Commons BeanUtils.
Java library to map request parameters onto an object
http://commons.apache.org/beanutils/
You can use any MVC framework like Struts where each HTML form will
have a java backing bean.
If you feel MVC is heavy, You can write your own logic by using
Java Reflections API.
Try using Apache HttpComponents. I can help you read and parse a URL into individual components like
Called Page
List of Arguments with values as a Named value Pair
Link :
Apache HttpComponents
You can use the different examples given and tweak for your purpose.
How about using RestEasy?
I've not used it before, but based on some examples seems to be really simple. See the possible implementation:
#GET
#Path("getUser") //example: "/getUser?userid=1&username=john&usersex=1"
#Produces("application/json")
public User getUser(#QueryParam("userid") final long userId, #QueryParam("username") final String userName, #QueryParam("usersex") final int userSex) {
User user = new User(userId, userName, userSex);
// do what's required
return user;
}
the question is also what output format you expect to be returned here. I provided sample for JSON reply.
It's quite simple, no framework should be required. See below:
public class TestClass {
public static void main (String[] args) throws Exception {
URL url = new URL("http://www.xxx.com/getUser?userid=1&username=john%20doe&usersex=1");
String q = url.getQuery();
User user = new User();
for (String token : q.split("&")) {
if (token.startsWith("userid")) {
int index = token.indexOf('=');
if (index >= 0 && index <token.length()-1) {
user.setUserId(Long.parseLong(token.substring(index+1)));
}
}
if (token.startsWith("username")) {
int index = token.indexOf('=');
if (index >= 0 && index <token.length()-1) {
user.setUserName(java.net.URLDecoder.decode(token.substring(index+1)));
}
}
if (token.startsWith("usersex")) {
int index = token.indexOf('=');
if (index >= 0 && index <token.length()-1) {
user.setUserSex(Integer.parseInt(token.substring(index+1)));
}
}
}
System.out.println(user.toString());
}
}
class User {
private long userId;
private String userName;
private int userSex;
//constructos
User(long userId, String userName, int userSex){
this.userId = userId;
this.userName = userName;
this.userSex = userSex;
}
User() {
this.userId = -1;
this.userName = "undefined";
this.userSex = -1;
}
#Override
public String toString() {
return String.format("id: %d; name: %s, sex: %d", userId, userName, userSex);
}
/**
* #return the userId
*/
public long getUserId() {
return userId;
}
/**
* #param userId the userId to set
*/
public void setUserId(long userId) {
this.userId = userId;
}
/**
* #return the userName
*/
public String getUserName() {
return userName;
}
/**
* #param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* #return the userSex
*/
public int getUserSex() {
return userSex;
}
/**
* #param userSex the userSex to set
*/
public void setUserSex(int userSex) {
this.userSex = userSex;
}
}
Related
I'm creating an app with a local database using Room. Every user have an option to create a 'Group' model, and these Groups are displayed in the main feed.
The groups are stored in the database, but when the user logs out and then logs in with a different account he can still see the previous account groups.
How can I fix that? Is there a way to implement the database so that after calling the logout function the DB will swap to a different DB?
Thanks.
How can I fix that?
2 Ways (at least) as will be shown
Is there a way to implement the database so that after calling the logout function the DB will swap to a different DB?
Yes. However I'd suggest that it is not the best way and is a little more complicated than the "Universal way".
Universal Way - Recommended approach
Have a single Database the log include the user (userId) as a column in the log and showing just the logs for the current user.
Mulltiple or UserOnly approach
You have at least 3 databases one for the User's so they can login and a database for each use with the log table. Switching between users makes this more complex as it requires opening another database when the user is switched. Unless using arrays (why would you? (rhetoric)) then if switching from a user to another then you should ideally close the first user's database.
Working Example
The following is a working example/demo that utilises BOTH approaches.
Hopefully the comments and names used explain.
The Entities first :-
User (common to both approaches) :-
#Entity
class User {
#PrimaryKey
Long userId;
#ColumnInfo(index = true)
String userName;
String userPassword;
public User(){};
#Ignore
public User(Long userId, String userName, String userPassword) {
this.userId = userId;
this.userName = userName;
this.userPassword = userPassword;
}
#Ignore
public User(String userName, String userPassword) {
this(null,userName,userPassword);
}
public Long getUserId() {
return userId;
}
public String getUserName() {
return userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
}
UserLog (common to both approaches)
#Entity(tableName = "log")
class UserLog {
#PrimaryKey
Long id;
Long timestamp;
Long userId;
String logData;
public UserLog(){}
#Ignore
public UserLog(User user, String logData) {
this.id = null;
this.timestamp = System.currentTimeMillis();
this.userId = user.getUserId();
this.logData = logData;
}
public Long getId() {
return id;
}
public Long getUserId() {
return userId;
}
public Long getTimestamp() {
return timestamp;
}
public String getLogData() {
return logData;
}
public void setId(Long id) {
this.id = id;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
public void setLogData(String logData) {
this.logData = logData;
}
}
That's the Entities and both are common to each approach.
Now the Dao's
UniversalDao (for the recommended approach)
#Dao
interface UniversalDao {
#Insert(onConflict = OnConflictStrategy.IGNORE)
long insertUser(User user);
#Insert
long insertLog(UserLog userLog);
#Query("SELECT * FROM user WHERE userId=:userId")
User getUserById(long userId);
#Query("SELECT * FROM log WHERE userId=:userId")
List<UserLog> getUserLogs(long userId);
#Query("SELECT userId FROM user WHERE userName=:userName AND userPassword=:password")
long verifyUserLogin(String userName, String password);
}
The getuserLogs Dao being used for getting and showing a specific user's logs.
UserOnlyDao
#Dao
interface UserOnlyDao {
#Insert
long insertUserLog(UserLog userLog);
#Query("SELECT * FROM Log")
List<UserLog> getUserLogs();
}
simpler BUT ....
The Database (#Database) classes utilsing singletons
UniversalUserDatabase (all-in-one database approach - Recommended)
#Database(entities = {User.class,UserLog.class},version = 1)
abstract class UniversalUserDatabase extends RoomDatabase {
abstract UniversalDao getAllDao();
private static UniversalUserDatabase instance;
static UniversalUserDatabase getInstance(Context context) {
if (instance == null) {
instance = Room.databaseBuilder(
context,
UniversalUserDatabase.class,"universaluser.db"
).allowMainThreadQueries()
.build();
}
return instance;
}
}
Pretty straightforward
UserOnlyDatabase (may need some time to understand this one)
#Database(entities = {UserLog.class},version = 1)
abstract class UserOnlyDatabase extends RoomDatabase {
abstract UserOnlyDao getUserOnlyDao();
private static volatile UserOnlyDatabase instance;
private static volatile User currentUser;
static UserOnlyDatabase getInstance(Context context, User user) {
if (user == null) {
throw new RuntimeException("Attempt to open Invalid - CANNOT continue");
}
if ( currentUser == null || (currentUser.getUserId() != user.getUserId())) {
if (instance != null) {
if (instance.isOpen()) {
instance.close();
}
instance = null;
}
}
if (instance == null) {
instance = Room.databaseBuilder(context,UserOnlyDatabase.class,user.userName+ "_log")
.allowMainThreadQueries()
.build();
}
return instance;
}
}
Note this works but has only been tested for a simple sceanrio
the getInstance method is where the swapping of userlog database is undertaken
Now putting it all together in an activity that demonstrates.
Note for convenience and brevity this runs on the main thread. So no consideration for not running it on the main thread has been included. However, as singletons are used there is probably little that isn't covered, just beware that there may be issues to consider.
MainActivity
public class MainActivity extends AppCompatActivity {
static int MAXLOGINATTEMPTS = 5;
static String TAG = "USERLOGINFO";
UniversalUserDatabase uniDB;
UniversalDao uniDao;
UserOnlyDatabase uoDB;
UserOnlyDao uoDao;
User currentUser = new User();
int loginAttempts = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uniDB = UniversalUserDatabase.getInstance(this);
uniDao = uniDB.getAllDao();
// Add Some Users
uniDao.insertUser(new User("Fred","password"));
uniDao.insertUser(new User(Long.valueOf(1000),"Mary","password"));
// Login to the first user logging the login attempt
if (forceLogin("Fred","password",true)) {
Log.d(TAG,currentUser.userName + " successfully logged in.");
uniDao.insertLog(new UserLog(currentUser,"Logged In Successfully"));
uoDB = UserOnlyDatabase.getInstance(this,currentUser);
uoDao = uoDB.getUserOnlyDao();
uoDao.insertUserLog(new UserLog(currentUser,"UOLogged in was Good"));
}
// Write the logs to the log for Universal and userOnly approach
logCurrentUserLog();
logUserOnlyLog();
// SWITCH USER and database for User Only approach logging login to the logs
if (forceLogin("Mary","password",true)) {
Log.d(TAG,currentUser.userName + " successfully logged in.");
uniDao.insertLog(new UserLog(currentUser,"Logged in Successfuly"));
uoDB = UserOnlyDatabase.getInstance(this,currentUser);
uoDao = uoDB.getUserOnlyDao();
uoDao.insertUserLog(new UserLog(currentUser,"UOLogged in was Good"));
}
logCurrentUserLog();
logUserOnlyLog();
}
private boolean addUser(String userName, String password) {
return uniDao.insertUser(new User(userName,password)) > 0;
}
private boolean login(String userName, String password) {
long userId;
if (++loginAttempts >= MAXLOGINATTEMPTS) return false;
if (!((userId = uniDao.verifyUserLogin(userName,password)) > 0)) return false;
currentUser = uniDao.getUserById(userId);
loginAttempts = 0;
return true;
}
private boolean forceLogin(String userName, String password, boolean crashIfTooManyAttempts) {
while (!login(userName,password)) {
if (loginAttempts >= MAXLOGINATTEMPTS) {
if (crashIfTooManyAttempts)
throw new RuntimeException("Too Many Login Attempts - Goodbye");
return false;
}
}
return true;
}
private void logCurrentUserLog() {
for(UserLog ul: uniDao.getUserLogs(currentUser.getUserId())) {
Log.d(TAG,ul.timestamp + " User = " + currentUser.userName + "Log = " + ul.logData);
}
}
private void logUserOnlyLog() {
for(UserLog ul: uoDao.getUserLogs()) {
Log.d(TAG + "_UO",ul.timestamp + " UO ID = " +ul.userId + " " + ul.id + ul.logData);
}
}
}
So this :-
Gets an instance of the Universal Database and gets the Dao.
Adds 2 users Fred and Mary (Mary with an id forced to be 1000 just for show, makes no difference to the demo what Mary's id is)
1.Logs on to Fred writing.
A login entry is added for Fred in the Universal Database log.
An instance of Fred's UserOnly database is obtained and a login entry is made in Fred's log in Fred's database.
Fred's log entries, from the Universal database, are output to the Device's log.
Fred's log entries from his personal database are output to the Device's log.
USER is SWITCHED to Mary when Mary log's on.
A login entry is added for Mary in the Universal Database Log.
An instance of Mary's UserOnly database is obtained and a login entry is made in Mary's log in Mary's database.
Mary's log entries. from the Universal Database Log are output to the Device's log.
NOTE Fred's entries ARE NOT output even though they exist in the Log..
Mary's log entries from his personal database are output to the Device's log.
Results
The Device's Log after the first run :-
2021-04-18 13:38:18.381 D/USERLOGINFO: Fred successfully logged in.
2021-04-18 13:38:18.412 D/USERLOGINFO: 1618717098382 User = FredLog = Logged In Successfully
2021-04-18 13:38:18.415 D/USERLOGINFO_UO: 1618717098385 UO ID = 1 1UOLogged in was Good
2021-04-18 13:38:18.419 D/USERLOGINFO: Mary successfully logged in.
2021-04-18 13:38:18.453 D/USERLOGINFO: 1618717098419 User = MaryLog = Logged in Successfuly
2021-04-18 13:38:18.457 D/USERLOGINFO_UO: 1618717098429 UO ID = 1000 1UOLogged in was Good
The database's via Database Inspector
Showing the Universal Database Log (recommended apporaoch) :-
As Fred's database was closed this is shown as closed
Showing The UserOnly log (Mary's) :-
You can shoud clear your databases every time a users logs out:
YourDataBase.getInstance(context).clearTables()
My code
package crypto;
import java.util.Vector;
public class Wallet {
public void main() {}
public String username;
public String password;
public int coins;
Vector<Object> wallets = new Vector<Object>();
public Wallet(String username, String password) {
this.username = username;
this.password = password;
this.coins = 0;
}
public void createWallet(String username, String password) {
wallets.add(new Wallet(username, password));
}
public Object findWallet(String username, String password) {
Object wallet;
for (int i = 0; i < wallets.size(); i++) {
wallet = wallets.get(i);
if (wallet.username == username && wallet.password == password) {
return wallet;
}
}
return 0;
}
public void addCoins(String username, String password, int coins) {
Object wallet = findWallet(username, password);
wallet.coins += coins;
}
}
Any help would be appreciated.
This is a test program for a cryptocurrency (just a personal project)
FYI this is just filler text because apparently you have to do that.
Your question is not very clear but let me guess what you need.
You can use generics:
Vector<Wallet> wallets = new Vector<Wallet>();
Anyway why didn't you consider using a simple ArrayList?
List<Wallet> wallets = new ArrayList<>();
Now you have an access to your Wallet methods when looking it up within a vector.
And change Object type to Wallet everywhere.
I would recommend you to rewrite search logic to something like that:
public Wallet findWallet(String userName, String password) {
return wallets.stream()
.filter(e -> e.getUserName().equals(userName))
.filter(e -> e.getPassword().equals(password))
.findAny()
.orElse(null);
}
You can google what getters and setters are.
I would also like to mention that you might want to use separate classes for your Wallet itself and a service that tends to perform operations over it.
I assume you can find more useful info here
I think you need method get(int index). It returns the element at the specified position in your Vector.
I am getting conditionalcheckfailed exception when trying to save/update items using dynamodb mapper.
Can anyone please share snippet of code using java that can demonstrate how versioning and optimistic locking can be implemented successfully?
Tried not setting version at all!!
Tried adding a record to table, and then doing read before save.
Nothing woked!! I continue to get ConditionalCheckFailed Exception.
Only thing works is if I set the config to COBBLER!! but that's not what I want as I need optimistic locking for my data.
DB item class---
#DynamoDBTable(tableName="Funds")
public class FundsItem {
private String id;
private String auditId;
private Long version;
private String shopId;
private String terminalId;
private String txId;
#DynamoDBHashKey(attributeName = "Id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
#DynamoDBRangeKey(attributeName = "AuditId")
public String getAuditId() {
return auditId;
}
public void setAuditId(String auditId) {
this.auditId = auditId;
}
#DynamoDBVersionAttribute(attributeName = "Version")
public Long getVersion() { return version; }
public void setVersion(Long version) { this.version = version; }
#DynamoDBAttribute(attributeName = "ShopId")
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
#DynamoDBAttribute(attributeName = "TerminalId")
public String getTerminalId() { return terminalId; }
public void setTerminalId(String terminalId) {
this.terminalId = terminalId;
}
#DynamoDBAttribute(attributeName = "TxId")
public String getTxId() {
return txId;
}
public void setTxId(String txId) {
this.txId = txId;
}
}
Code to save new item -----
public long addFunds(FundsRequest request){
FundsItem dbItem = new FundsItem();
String Id = request.getShopId().trim() + request.getTerminalId().trim();
String V0_Audit_Rec = "V0_Audit_" + Id;
//save V0 item.
dbItem.setVersion((long) 1);
dbItem.setId(Id);
dbItem.setAuditId(V0_Audit_Rec);
dbItem.setShopId(request.getShopId().trim());
dbItem.setTerminalId(request.getTerminalId().trim());
dbItem.setTxId(request.getTxId().trim());
mapper.save(dbItem);
}
Pls check the snippet above - This is a new empty table.
hashkey - id, rangekey - auditId, VersionField - version.
I just want to be able to add a new record that's why not doing any read before saving a new item. If I can get this simple case i.e. adding a new /first record to the dynamodb table work, I can implement rest of the use cases too.
In general:
Never set your version, the SDK will initialise this if required.
Always try and load an item with your key first. If null is returned, create the item and save it. Else update the returned item and save it.
I know you mentioned you've tried the above. If its truely an empty table your code should work OK (minus the setting of the version).
A couple of things I would also do:
Don't set your version field with a custom attribute name. In theory this should be fine, but for the sake of making your code the same as the AWS examples, I would remove this, at least until you have it working.
Although I think you need to remove the setting of the version, I note you are casting to a long, not a Long. Again, unlikely to be an issue but just something to eliminate at least. i.e. if you insist of setting version use new Long(l).
I am trying to execute this query:
#Override
public UserInfo get(Long id) {
String sql = "SELECT * FROM users WHERE id = ? ";
List<UserInfo> list = jdbcTemplate.query(sql,new UserInfoMapper(),id);
return list.get(0);
}
but jdbc return empty list and I get exception at return line.
But if try to execute directly though the console it returns:
Query, Answer
Query was executed with id 1 and retured correct anwser;
But in method its returned this
I couldn't find any same questions so that may be point at my inattention to something. But I can't see any problem that may cause this. Thanks in advance;
Updated 1
Changing code to
#Override
public UserInfo get(Long id) {
String sql = "SELECT * FROM users WHERE id = ? ";
List<UserInfo> list = jdbcTemplate.query(sql, new Object[] {id},new UserInfoMapper());
return list.get(0);
}
resulted in same: result
Updated 2
#Override
public UserInfo mapRow(ResultSet resultSet, int i) throws SQLException {
UserInfo info = new UserInfo();
info.setId(resultSet.getLong("id"));
info.setFirstname(resultSet.getString("firstname"));
info.setMiddlename(resultSet.getString("middlename"));
info.setLastname(resultSet.getString("lastname"));
info.setUsername(resultSet.getString("username"));
info.setPassword(resultSet.getString("password"));
info.setEmail(resultSet.getString("email"));
info.setMobilephone(resultSet.getString("mobilephone"));
info.setPosition(resultSet.getString("position"));
return info;
}
public class UserInfo {
private Long id;
private String firstname;
private String middlename;
private String lastname;
private String username;
private String password;
private String email;
private String mobilephone;
private String position;
public UserInfo() {
}
}
Getter and setters for each field is there but I think there is no need to show them up.
Check user credentials that you are using to connect database from your application and the user credentials in console. And also check owner schema , table owner schema in your application.
I have login pages and I add some profiles, so after adding some and make the configuration of the controller for each profile and also the HTML pages. When I make the good username and the password. The redirection to the index page for each profile doesn't work and they redirect me to the page of the login
>
public class Security extends Secure.Security {
static boolean authenticate(String login, String password) {
return UserGcv.connect(login, password) != null;
}
static void onDisconnected() {
Application.index();
}
static void onAuthenticated() {
UserGcv user = UserGcv.find("byLogin", connected()).first();
Cache.set("user_" + session.get("username"), user, "30min");
switch (user.profil) {
case ADMIN:
Administration.showUsers();
break;
case DMC:
Catalogs.consultArticle();
break;
case DCGP:
DCGPArticle.consultArticleDCGP();
break;
case DCE:
DCEArticle.consultArticleDCE();
break;
case Planificateur:
Planificateur.composerVersion();
break;
case ValidAvantage:
ValidateurAvantage.homeValidateur();
break;
case PARAMETRAGE:
PARAMETRAGE.createParam();
break;
case ConfAvantage:
ConfigAvantage.homeConfigurateur();
break;
}
} }
UserGCV.java
package models;
#Entity #Table(name = "user_gcv") #With(Secure.class) public class
UserGcv extends Model {
#Column(name = "user_name")
public String userName;
#Column(name = "user_last_name")
public String userLastName;
#Column(name = "user_direction")
public String userDirection;
#Column(name = "user_phone_number")
public Integer userPhoneNumber;
#Column(name = "user_cin")
public Integer userCin;
#Column(name = "user_fonction")
public String userFonction;
#Column(name = "login")
public String login;
#Column(name = "password")
public String password;
#Column(name = "user_mail_address")
#Email
public String userMailAddress;
#Enumerated(EnumType.STRING)
public Profil profil;
#Column(name = "actif")
public int actif;
#OneToMany(mappedBy = "utilisateur")
List<Trace> traces = new ArrayList();
public UserGcv(Long id, String userName, String userLastName,
String userDirection, Integer userPhoneNumber, Integer userCin,
String userFonction, String login, String password,
String userMailAddress, Profil profil, int actif) {
this.id = id;
this.userName = userName;
this.userLastName = userLastName;
this.userDirection = userDirection;
this.userPhoneNumber = userPhoneNumber;
this.userCin = userCin;
this.userFonction = userFonction;
this.login = login;
this.password = password;
this.userMailAddress = userMailAddress;
this.profil = profil;
this.actif = actif;
}
public UserGcv() {
}
public static UserGcv connect(String login, String password) {
return find("select distinct u from UserGcv u where login=? and password=? and actif=?", login, password, 1).first();
}
public UserGcv(String login, String password) {
this.login = login;
this.password = password;
}
public UserGcv(String userName, String userLastName, String userDirection, Integer userPhoneNumber, Integer userCin, String userFonction, String login, String password, String userMailAddress, Profil profil, int actif) {
this.userName = userName;
this.userLastName = userLastName;
this.userDirection = userDirection;
this.userPhoneNumber = userPhoneNumber;
this.userCin = userCin;
this.userFonction = userFonction;
this.login = login;
this.password = password;
this.userMailAddress = userMailAddress;
this.profil = profil;
this.actif = actif;
}
#Override
public String toString() {
return "" + id;
}
public static List<UserGcv> findAllUsers() {
return UserGcv.find("order by userName asc").fetch();
}
public boolean isAdmin() {
return Profil.ADMIN.equals(profil);
}
public boolean isDMC() {
return Profil.DMC.equals(profil);
}
public boolean isDCGP() {
return Profil.DCGP.equals(profil);
}
public boolean isPlanificateur() {
return Profil.Planificateur.equals(profil);
}
public boolean isDCE() {
return Profil.DCE.equals(profil);
}
public boolean isParametrage() {
return Profil.PARAMETRAGE.equals(profil);
}
public boolean isConfigAvantage() {
return Profil.ConfAvantage.equals(profil);
}
public boolean isValidateurAvantage() {
return Profil.ValidAvantage.equals(profil);
} }
Routes
# Routes
# Import Secure routes
#* / module:secure
GET / Secure.login
POST / Secure.authenticate
GET /logout Secure.logout
# Home page
#GET / Application.index
# Administration page
GET /administration/user/edit/{id} Administration.editUser
GET /administration/new Administration.newUser
GET /administration/user/save/{id} Administration.save
POST /administration/new Administration.save
GET /administration/script Administration.telechargerScript GET /administration/download Administration.download
GET /administration/details Administration.detailsVersion
GET /administration/traces Administration.consulterTraces
GET /administration/historique Administration.exportCSVFile
# DMC page
GET /catalog/index Catalogs.index
GET /catalog/search Catalogs.searchArticle
GET /catalog/consult Catalogs.modifArticle
GET /catalog/search Catalogs.searchArticleDes
GET /pack/modify Catalogs.modifPack
GET /pack/consult Catalogs.consultPack
GET /catalogues/getListArticle/? Catalogs.getListArticle
POST /pack/new Catalogs.savePack
# DCGP page
GET /dcepack/consultpackdce DCEPack.consultPackDCE
GET /dcgp/articles DCGP.allArticle
GET /dcgp/delete DCGP.deleteArticle
GET /dcgp/facture DCGP.generateFacture
GET /dcgp/modify DCGP.modifyArticle
GET /dcgp/valid DCGP.validPack
GET /dcgppack/consultpackdcgp DCGPPack.consultPackDCGP
# Planificateur page
GET /Planificateur/composer Planificateur.composerVersion
GET /Planificateur/planifierAvantage Planificateur.homePlanificateur
# Parametrage page
POST /parametrage/new Parametrage.saveParam
# Configurateur Avantage pages
GET /ConfigAvantage/homeConfigurateur ConfigAvantage.homeConfigurateur GET /ConfigAvantage/modifierAvantage/? ConfigAvantage.modifierAvantage
GET /ConfigAvantage/searchPackToAffectation/?ConfigAvantage.searchPackToAffectation
GET /VersionAvantage/goToGPS VersionAvantage.goToGPS
GET /ConfigAvantage/viewAvantageDetails/? ConfigAvantage.viewAvantageDetails
GET /ConfigAvantage/affectationPackView/? ConfigAvantage.affectationPackView
#Validateur Avantage Pages
GET /ValidateurAvantage/homeValidateur ValidateurAvantage.homeValidateur
# Ignore favicon requests
GET /favicon.ico 404
# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
# Import CRUD routes
* /admin module:crud
# Catch all
* /{controller}/{action} {controller}.{action}
i ckecked the method onAuthenticated in Secure.Security , it return null for the url
static void onAuthenticated() {
UserGcv user = UserGcv.find("byLogin", connected()).first();
Cache.set("user_" + session.get("username"), user, "60min");
System.err.println("usecccccccccccccccccccccr"+user);
switch (user.profil) {
case ADMIN:
Administration.showUsers();
break;
case DMC:
Catalogs.consultArticle();
break;
case DCGP:
DCGPArticle.consultArticleDCGP();
break;
case DCE:
DCEArticle.consultArticleDCE();
break;
case Planificateur:
Planificateur.composerVersion();
break;
case ValidAvantage:
ValidateurAvantage.homeValidateur();
break;
case PARAMETRAGE:
PARAMETRAGE.createParam();
break;
case ConfAvantage:
ConfigAvantage.homeConfigurateur();
break;
}
The problem was that the custom security class when the class extend from Secure.Security he didn't overide the method onAuthenticated So the solution was to impliment the custom onAuthenticated into the default class
public static class Security extends Controller {
/**
* #Deprecated
*
* #param username
* #param password
* #return
*/
static boolean authentify(String username, String password) {
throw new UnsupportedOperationException();
}
/**
* This method is called during the authentication process. This is
* where you check if the user is allowed to log in into the system.
* This is the actual authentication process against a third party
* system (most of the time a DB).
*
* #param username
* #param password
* #return true if the authentication process succeeded
*/
static boolean authenticate(String username, String password) {
return true;
}
/**
* This method checks that a profile is allowed to view this
* page/method. This method is called prior to the method's controller
* annotated with the #Check method.
*
* #param profile
* #return true if you are allowed to execute this controller method.
*/
static boolean check(String profile) {
return true;
}
/**
* This method returns the current connected username
*
* #return
*/
static String connected() {
return session.get("username");
}
/**
* Indicate if a user is currently connected
*
* #return true if the user is connected
*/
static boolean isConnected() {
return session.contains("username");
}
/**
* This method is called after a successful authentication. You need to
* override this method if you with to perform specific actions (eg.
* Record the time the user signed in)
*/
static void onAuthenticated() {
UserGcv user = UserGcv.find("byLogin", connected()).first();
Cache.set("user_" + session.get("username"), user, "60min");
switch (user.profil) {
case ADMIN:
Administration.showUsers();
break;
case DMC:
Catalogs.consultArticle();
break;
case DCGP:
DCGPArticle.consultArticleDCGP();
break;
case DCE:
DCEArticle.consultArticleDCE();
break;
case Planificateur:
Planificateur.composerVersion();
break;
case PARAMETRAGE:
PARAMETRAGE.createParam();
break;
case ConfAvantage:
ConfigAvantage.homeConfigurateur();
break;
case ValidAvantage:
ValidateurAvantage.homeValidateur();
break;
case PlanifDSC:
PlanifDSC.homePlanifDSC();
break;
}
}