// Logueja un usuari public boolean correctUserLogin(String username, String password) { if (dataController.existUser(username, password)) { currentUser.username = username; currentUser.password = password; return true; } return false; }
@Get public void listEntries(HttpServletResponse resp) throws IOException { user = currentUser.getUser(); if (null == user) { resp.sendRedirect(currentUser.getLoginUrl("/entries")); return; } signoutUrl = currentUser.getLogoutUrl(currentUser.getLoginUrl("/entries")); }
@Post public String postEntry() { user = currentUser.getUser(); if (null == user) { return currentUser.getLoginUrl("/entries"); } this.entry.setId(UUID.randomUUID().getMostSignificantBits()); this.entry.setUser(user); entryStore.save(this.entry); return "/entries"; }
@Test public void testDoFilterForClientBackwardsCompatibility() throws Exception { Filter filter = new FalconAuthenticationFilter(); final String userName = System.getProperty("user.name"); final String httpAuthType = StartupProperties.get().getProperty("falcon.http.authentication.type", "simple"); try { System.setProperty("user.name", ""); StartupProperties.get() .setProperty( "falcon.http.authentication.type", "org.apache.falcon.security.RemoteUserInHeaderBasedAuthenticationHandler"); synchronized (StartupProperties.get()) { filter.init(mockConfig); } Mockito.when(mockRequest.getMethod()).thenReturn("POST"); Mockito.when(mockRequest.getQueryString()).thenReturn(""); Mockito.when(mockRequest.getRemoteUser()).thenReturn(null); Mockito.when(mockRequest.getHeader("Remote-User")).thenReturn("remote-user"); filter.doFilter(mockRequest, mockResponse, mockChain); Assert.assertEquals(CurrentUser.getUser(), "remote-user"); } finally { System.setProperty("user.name", userName); StartupProperties.get().setProperty("falcon.http.authentication.type", httpAuthType); } }
@Test public void testDoFilterWithEmptyDoAsUser() throws Exception { Filter filter = new FalconAuthenticationFilter(); synchronized (StartupProperties.get()) { filter.init(mockConfig); } CurrentUser.authenticate(FalconTestUtil.TEST_USER_2); Mockito.when(mockRequest.getMethod()).thenReturn("POST"); Mockito.when(mockRequest.getQueryString()) .thenReturn("user.name=" + FalconTestUtil.TEST_USER_2); Mockito.when(mockRequest.getRemoteUser()).thenReturn(FalconTestUtil.TEST_USER_2); Mockito.when(mockRequest.getParameter(FalconAuthenticationFilter.DO_AS_PARAM)).thenReturn(""); filter.doFilter(mockRequest, mockResponse, mockChain); Assert.assertEquals(CurrentUser.getUser(), FalconTestUtil.TEST_USER_2); }
@Test public void testAnonymous() throws Exception { Filter filter = new FalconAuthenticationFilter(); synchronized (StartupProperties.get()) { filter.init(mockConfig); } CurrentUser.authenticate("nouser"); Assert.assertEquals(CurrentUser.getUser(), "nouser"); CurrentUser.authenticate(FalconTestUtil.TEST_USER_2); Mockito.when(mockRequest.getRemoteUser()).thenReturn(FalconTestUtil.TEST_USER_2); filter.doFilter(mockRequest, mockResponse, mockChain); Assert.assertEquals(CurrentUser.getUser(), FalconTestUtil.TEST_USER_2); }
@Test public void testDoFilterWithDoAsUser() throws Exception { Filter filter = new FalconAuthenticationFilter(); HostnameFilter.HOSTNAME_TL.set("localhost"); synchronized (StartupProperties.get()) { filter.init(mockConfig); } CurrentUser.authenticate("foo"); Mockito.when(mockRequest.getMethod()).thenReturn("POST"); Mockito.when(mockRequest.getQueryString()).thenReturn("user.name=foo"); Mockito.when(mockRequest.getRemoteUser()).thenReturn("foo"); Mockito.when(mockRequest.getParameter(FalconAuthenticationFilter.DO_AS_PARAM)) .thenReturn("doAsProxyUser"); Mockito.when(mockRequest.getMethod()).thenReturn("POST"); filter.doFilter(mockRequest, mockResponse, mockChain); Assert.assertEquals(CurrentUser.getUser(), "doAsProxyUser"); }
// region Responders for buttons public void loginResponder(View v) { // Show the progress bar showProgress(true); // Check to see if any inputs are invalid String username = usernameField.getText().toString(); String password = passwordField.getText().toString(); if (TextUtils.isEmpty(username)) { // NOTIFY USER OF EMPTY FIELD Log.d(LOG_TAG, "Username cannot be empty"); showProgress(false); usernameField.setError("Cannot be left blank"); usernameField.requestFocus(); return; } else if (TextUtils.isEmpty(password)) { // NOTIFY USER OF EMPTY FIELD Log.d(LOG_TAG, "Password cannot be empty"); showProgress(false); passwordField.setError("Cannot be left blank"); passwordField.requestFocus(); return; } else if (username.length() > 30 || username.length() < 4) { // NOTIFY USER OF EMPTY FIELD Log.d(LOG_TAG, "Username must be between 4 and 30 characters."); showProgress(false); usernameField.setError("Must be between 4 and 30 characters"); usernameField.requestFocus(); return; } else if (password.length() < 6) { // NOTIFY USER OF EMPTY FIELD Log.d(LOG_TAG, "Password must be more than 6 characters."); showProgress(false); passwordField.setError("Must be greater than 6 characters"); passwordField.requestFocus(); return; } // Create a current user object - not synced with server yet CurrentUser u = new CurrentUser(username, password); // Attempt to login the user signInRT = u.getBaasUser().login(onComplete); }
private void InitaializeData() { BaseActivity.imageLoader.displayImage(CurrentUser.getProfileImage(), myAvatorImageView, o); DBManager dbManager = new DBManager(this); List<Building> localBuildings = dbManager.GetLocalBuildings(CurrentUser.getId()); if (localBuildings != null) { for (Building building : localBuildings) { if (building.getHome() == 1) { myHome.setTag(building); myHomeImageView.setVisibility(View.VISIBLE); BaseActivity.imageLoader.displayImage(building.getFaceUrl(), myHomeImageView); } else if (building.getWork() == 1) { myWork.setTag(building); myWorkImageView.setVisibility(View.VISIBLE); BaseActivity.imageLoader.displayImage(building.getFaceUrl(), myWorkImageView); } } } dbManager.closeDB(); nickNameView.setText(CurrentUser.getName() != null ? CurrentUser.getName() : "还没有昵称"); accountNameView.setText(CurrentUser.getEmail()); }
@Test( expectedExceptions = AccessControlException.class, expectedExceptionsMessageRegExp = "User .* not defined as proxyuser.*") public void testDoFilterWithInvalidProxyUser() throws Exception { Filter filter = new FalconAuthenticationFilter(); HostnameFilter.HOSTNAME_TL.set("localhost"); synchronized (StartupProperties.get()) { filter.init(mockConfig); } CurrentUser.authenticate(FalconTestUtil.TEST_USER_2); Mockito.when(mockRequest.getMethod()).thenReturn("POST"); Mockito.when(mockRequest.getQueryString()) .thenReturn("user.name=" + FalconTestUtil.TEST_USER_2); Mockito.when(mockRequest.getRemoteUser()).thenReturn(FalconTestUtil.TEST_USER_2); Mockito.when(mockRequest.getParameter(FalconAuthenticationFilter.DO_AS_PARAM)) .thenReturn("doAsProxyUser"); Mockito.when(mockRequest.getMethod()).thenReturn("POST"); filter.doFilter(mockRequest, mockResponse, mockChain); Assert.assertEquals(CurrentUser.getUser(), "doAsProxyUser"); }
private void LocadLocalData() { DBManager dbManager = new DBManager(this); BaseActivity.imageLoader.displayImage( BaseActivity.CurrentUser.getProfileImage(), avatorImageView, o); if (BaseActivity.CurrentUser.getName() != BaseActivity.CurrentUser.getEmail()) { nickTextView.setText(BaseActivity.CurrentUser.getName()); } else { } gendarTextView.setText(BaseActivity.CurrentUser.getGendar()); String locationString = ""; if (BaseActivity.CurrentUser.getCity() != null) { locationString += BaseActivity.CurrentUser.getCity(); } if (BaseActivity.CurrentUser.getDistrict() != null) { locationString += " " + BaseActivity.CurrentUser.getDistrict(); } locationTextView.setText(locationString); birthdayTextView.setText(CurrentUser.getBirthday()); List<Building> localBuildings = dbManager.GetLocalBuildings(CurrentUser.getId()); if (localBuildings != null) { for (Building building : localBuildings) { if (building.getHome() == 1) { homeImageView.setVisibility(View.VISIBLE); hometTextView.setText(R.string.more_fun_one); BaseActivity.imageLoader.displayImage(building.getFaceUrl(), homeImageView); } else if (building.getWork() == 1) { workImageView.setVisibility(View.VISIBLE); workTextView.setText(R.string.more_fun_two); BaseActivity.imageLoader.displayImage(building.getFaceUrl(), workImageView); } } } dbManager.closeDB(); }
/** * Called when the user clicks the Book ticket button. Books a ticket for the current user to * the selected performance (adds a booking to the database). * * @param e The event object (not used). */ public void actionPerformed(ActionEvent e) { if (nameList.isSelectionEmpty() || dateList.isSelectionEmpty()) { return; } if (!CurrentUser.instance().isLoggedIn()) { displayMessage("Must login first"); return; } String movieName = (String) nameList.getSelectedValue(); String date = (String) dateList.getSelectedValue(); /* --- insert own code here --- */ Performance p = db.getPerformance(movieName, date); boolean result = db.makeReservation(p); Performance pUpdated = db.getPerformance(movieName, date); fields[FREE_SEATS].setText((pUpdated.getTotalSeats() - pUpdated.getBookedSeats()) + ""); if (result) displayMessage("1 ticket booked for " + movieName); else displayMessage("Error!"); }
@SuppressWarnings("unchecked") @Override public void handleMessage(Message message) { DBManager dbManager = new DBManager(MyDashboardActivity.this); if (message.what != -1) { List<Building> buildings = (ArrayList<Building>) message.obj; if (buildings.size() > 0) { dbManager.SyncLocalBuildings(CurrentUser.getId(), buildings); for (Building building : buildings) { if (building.getHome() == 1) { myHomeImageView.setVisibility(View.VISIBLE); BaseActivity.imageLoader.displayImage(building.getFaceUrl(), myHomeImageView, o); } else if (building.getWork() == 1) { myWorkImageView.setVisibility(View.VISIBLE); BaseActivity.imageLoader.displayImage(building.getFaceUrl(), myWorkImageView, o); } } } } dbManager.closeDB(); }
@SuppressWarnings("unchecked") @Override public void handleMessage(Message message) { DBManager dbManager = new DBManager(UserSettingsActivity.this); if (message.what != -1) { List<Building> buildings = (ArrayList<Building>) message.obj; if (buildings.size() > 0) { dbManager.SyncLocalBuildings(CurrentUser.getId(), buildings); for (Building building : buildings) { if (building.getHome() == 1) { homeImageView.setVisibility(View.VISIBLE); hometTextView.setText(R.string.more_fun_one); BaseActivity.imageLoader.displayImage(building.getFaceUrl(), homeImageView); } else if (building.getWork() == 1) { workImageView.setVisibility(View.VISIBLE); workTextView.setText(R.string.more_fun_two); BaseActivity.imageLoader.displayImage(building.getFaceUrl(), workImageView); } } } } dbManager.closeDB(); }
public void logOut() { currentUser.username = ""; currentUser.password = ""; }
@Override public boolean canReveal() { return currentUser.isLoggedIn(); }
/** * Perform the entry actions of this pane: clear all fields, fetch the movie names from the * database and display them in the name list. */ public void entryActions() { clearMessage(); currentUserNameLabel.setText(CurrentUser.instance().getCurrentUserId()); fillNameList(); clearFields(); }
public void changePassword(String password) { dataController.changePassword(currentUser.username, password); currentUser.password = password; }
@Override public void onClick(View view) { switch (view.getId()) { case R.id.my_topics_rl: String user_id = String.valueOf(CurrentUser.getId()); Intent intent = new Intent(this, UserTopicsActivity.class); intent.putExtra("user_id", Integer.parseInt(user_id)); intent.putExtra("uname", ""); startActivity(intent); break; case R.id.my_favorite_rl: break; case R.id.my_related_rl: Intent intentAt = new Intent(this, UserTopicsActivity.class); intentAt.putExtra(Constant.RELATED_TOPIC_TYPE, UserRelatedTopicType.at.getCode()); startActivity(intentAt); break; case R.id.my_comment_rl: Intent intentComment = new Intent(this, UserTopicsActivity.class); intentComment.putExtra(Constant.RELATED_TOPIC_TYPE, UserRelatedTopicType.comment.getCode()); startActivity(intentComment); break; case R.id.my_follow_points: Intent intentPoints = new Intent(MyDashboardActivity.this, SearchPointsActivity.class); intentPoints.putExtra("user_follow", true); Bundle bundlePoints = new Bundle(); bundlePoints.putSerializable("desUser", CurrentUser); intentPoints.putExtras(bundlePoints); intentPoints.putExtra("search_type", PointSearchType.User_Follow.getCode()); startActivity(intentPoints); break; case R.id.my_home_rl: if (myHome.getTag() != null) { Building building = (Building) myHome.getTag(); // Intent intentHome = new Intent(MyDashboardActivity.this,BuildingHomeActivity.class); Intent intentHome = new Intent(MyDashboardActivity.this, BuildingCardActivity.class); Bundle bundle = new Bundle(); bundle.putSerializable("building", building); Log.v(TAG, "Home:" + building.getHome()); intentHome.putExtras(bundle); startActivity(intentHome); } break; case R.id.my_work_rl: if (myWork.getTag() != null) { Building building = (Building) myWork.getTag(); // Intent intentWork = new Intent(MyDashboardActivity.this,BuildingHomeActivity.class); Intent intentWork = new Intent(MyDashboardActivity.this, BuildingCardActivity.class); Bundle bundle = new Bundle(); bundle.putSerializable("building", building); intentWork.putExtras(bundle); startActivity(intentWork); } break; case R.id.my_personal_rl: Intent intentSetting = new Intent(this, UserSettingsActivity.class); startActivity(intentSetting); break; case R.id.my_setting_rl: Intent appSetting = new Intent(this, AppSettingActivity.class); startActivity(appSetting); break; case R.id.my_quit_rl: DBManager dbManager = new DBManager(this); dbManager.Logout(BaseActivity.CurrentUser.getId()); dbManager.closeDB(); // dbManager.deleteAllAccounts(); // finish(); System.exit(0); break; default: break; } }