?
Solved

JSP wiat till execute if statment

Posted on 2010-01-04
13
Medium Priority
?
253 Views
Last Modified: 2012-05-08
Hi experts,

i have if statements that set some values than complete code sequence,
my code seems that it continues its sequence while if statement is not done yet:

here is log lines:

[04/Jan/2010:12:31:03] info (20728): else authorized false
[04/Jan/2010:12:31:04] info (20728): session created
[04/Jan/2010:12:31:04] info (20728): 11111111111111111111111111111111111
[04/Jan/2010:12:31:04] info (20728): 222222222222222222222222222222222222222
[04/Jan/2010:12:31:04] info (20728): authorized true


hope it is clear :)


String authorizedGroup1= "invcontrol";
    boolean authorized = false;
    String username = "";
    String displayName = "";

    Person_3 currentUser;

    if (WebUtil.sessionOkay(request, response)) {


        System.out.println("11111111111111111111111111111111111");


        byte[] sessionId = WebUtil.getUserSession( request, response );
        PersonManager_3 pm = (PersonManager_3) ManagerFactory.getManager( PersonManager_3.ID );
        currentUser = pm.getCurrentPerson();


        // check the targetted role
        Iterator e = currentUser.getAccessGroups();
        AccessGroup_4 oGroup;
        while(e.hasNext()) {
            oGroup = (AccessGroup_4)e.next();



            if(oGroup.getId().equalsIgnoreCase(authorizedGroup1)){

               session.setAttribute("isUserAuthorized", "true");
               authorized = true;

                break;
            } // if authorizedGroup
        }


        username = currentUser.getUserId();


        if(username !="" || !username.equals("null")) {

          session.setAttribute("loggedUsername", username);



        }


  System.out.println("222222222222222222222222222222222222222");


   }




        String pageName = "channel index";


        int counterx = 0;
        
      if (authorized) {

              System.out.println("authorized true");
 

 } else {
              System.out.println("else authorized false");

Open in new window

0
Comment
Question by:Web_Admin
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 15

Expert Comment

by:Insoftservice
ID: 26169245
hi,

What i understood is that u don't want to print "2222" when
        if(username !="" || !username.equals("null")) {
is not satisfied. Please confirm.

0
 
LVL 12

Expert Comment

by:geowrian
ID: 26169250
Is this for a Luminis or uPortal system?
0
 

Author Comment

by:Web_Admin
ID: 26169260
geowrian:
yes sucks luminis system :)
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 

Author Comment

by:Web_Admin
ID: 26169269
insoftservice:

here is what i want the code to print:

- 1111
- 222
- authorized ture
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26169281
can you once try after synchronizing the whole outer if block.
Thanks
0
 
LVL 12

Expert Comment

by:geowrian
ID: 26169285
Check out www.lumndev.net for some other examples users have submitted for role-based mechanisms. I switched from the Luminis objects to the IPerson objects in the uPortal framework. If that's a possibility for you, this may accomplish the same things you are trying to do:
// Get the current user
SimplePersonManager spm = new SimplePersonManager();
IPerson currentUser = spm.getPerson(request);

// Check if user is authenticated
if(currentUser == null) {
	out.println("Please Login to the portal first.<br><a href='/'>Click here to login to the portal.</a>");
	return;
}

// Get the user's username, first name, and last name
String username = currentUser.getAttribute("urn:sungardhe:dir:loginId")     == null ? "" : (String) currentUser.getAttribute("urn:sungardhe:dir:loginId");
String FName = currentUser.getAttribute("urn:mace:dir:givenName")           == null ? "" : (String) currentUser.getAttribute("urn:mace:dir:givenName");
String LName = currentUser.getAttribute("urn:mace:dir:sn")                  == null ? "" : (String) currentUser.getAttribute("urn:mace:dir:sn");

// Get and Check the required roles
Vector<String> roles = RoleFactory.getRoles(currentUser);

// Loop through roles and check for GradgStud* role
Iterator i = roles.iterator();
boolean found = false;
while(i.hasNext()) {
	String curRole = ((String) i.next()).toLowerCase();
	if(curRole.Equals("invcontrol")) {
		found = true;
		break;
	}
}

if(!found) {
	out.println("Sorry, but your account does not have permission to blah blah blah.");
	return;
}


//This requires the RoleFactory class (contents below):
<%@ page import="java.util.*" %>
<%@ page import="org.jasig.portal.security.provider.*" %>
<%@ page import="org.jasig.portal.security.*" %>

<%!
public static class RoleFactory {
	public static Vector<String> getRoles(IPerson currentUser) {
          
          //Check for valid session
          if(currentUser == null)
               return null;
          
          // Get the user's roles
          Object[] allRoles = currentUser.getAttributeValues("urn:sungardhe:dir:role");

          // Initialize the roles
          Vector<String> roles = new Vector();

          // All users belong to "all" role
          roles.add("all");

          // Add user roles to vector
          if(allRoles != null)
               for(int i = 0; i < allRoles.length; i++)
                    roles.add(((String) allRoles[i]).toLowerCase());
          return roles;
	}
}
%>

Open in new window

0
 
LVL 12

Expert Comment

by:geowrian
ID: 26169297
I forgot to mention that one of the reasons I switched is due to Access Denied messages with unauthenticated users when using WebUtil.sessionOkay. It worked fine in Luminis III, but in Luminis IV it threw access denied errors.
0
 
LVL 20

Expert Comment

by:a_b
ID: 26169304
Can you please explain - "while if statement is not done yet:"??
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26169305
@Web_Admin: Isn't your code already printing
<<
- 1111
- 222
- authorized ture
>>

Or is it that its also printing
<<
[04/Jan/2010:12:31:03] info (20728): else authorized false
[04/Jan/2010:12:31:04] info (20728): session created
>>
before that?

Please clarify

0
 

Author Comment

by:Web_Admin
ID: 26169349
geowrian:

the code is working perfect in inline frame channel, but not in web proxy , i will try ur code

thanks :)
0
 

Author Comment

by:Web_Admin
ID: 26169440
wat i want the code to print following:

- enter if 1
- session created
- exist if1
- authorized true

wat the code printing is

- authorized false
- enter if 1
- session created
- exist if1
- authorized true

String authorizedGroup1= "invcontrol";
    boolean authorized = false;
    String username = "";
    String displayName = "";

    Person_3 currentUser;

    if (WebUtil.sessionOkay(request, response)) {


        System.out.println("enter if 1");


        byte[] sessionId = WebUtil.getUserSession( request, response );
        PersonManager_3 pm = (PersonManager_3) ManagerFactory.getManager( PersonManager_3.ID );
        currentUser = pm.getCurrentPerson();


        // check the targetted role
        Iterator e = currentUser.getAccessGroups();
        AccessGroup_4 oGroup;
        while(e.hasNext()) {
            oGroup = (AccessGroup_4)e.next();



            if(oGroup.getId().equalsIgnoreCase(authorizedGroup1)){

               session.setAttribute("isUserAuthorized", "true");
               authorized = true;
               System.out.println("session created");

                break;
            } // if authorizedGroup
        }


        username = currentUser.getUserId();


        if(username !="" || !username.equals("null")) {

          session.setAttribute("loggedUsername", username);



        }


  System.out.println("exist if1");


   }




        String pageName = "channel index";


        int counterx = 0;
        
      if (authorized) {

              System.out.println("authorized true");
 

 } else {
              System.out.println("authorized false");

Open in new window

0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 26169482
if loop from 61-69 is outside the while loop. Any specific reasons for the same.

Can you put it in the inner if loop only 27-34, given that you are breaking out of the while loop anyway after that. you can also place line 38-43 in the inner if loop itself.

0
 

Author Closing Comment

by:Web_Admin
ID: 31672286
Thanks it works :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SingleRun is a tool that ensures that only one instance of an application is started, running it again brings the application to focus.
In-App Messaging has revolutionized the way we look at marketing. It has also changed the way we use Apps. If In-App Messaging is used well then you will find that it can drive a lot of traffic to specific areas of your site. It also helps to improv…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question