Issuing Token

  • Integrated login issues SSO token and stores token in cookies.
    Token stored in cookies can be passed to other services in the same domain.
    import com.google.gson.Gson;
    import com.rivest.sso.api.SSO;
    
    // Create SSO Object
    SSO sso = new SSO();
    
    // User's Basic Personal Information [Required]
    sso.setUserId("lucas2021");
    sso.setClientIp("192.168.0.122"); // In general request.getRemoteAddr()
    
    // Additional personal information of the user [optional]
    sso.setProfile("userName", "lucas");
    sso.setProfile("deptCode", "A1000");
    sso.setProfile("deptName", "Marketing");
    sso.setProfile("cellphone", "010-0000-0000");
    sso.setProfile("email", "rivestsoft@gmail.com");
    sso.setProfile("age", "20");
    sso.setProfile("birth", "19901215");
    
    // Set IP and PORT for SSO Server [Optional]
    sso.setServerIp("localhost");
    sso.setServerPort((short)8420);
    
    // Token Issue Request
    sso.issueToken();
    
    // Error check
    if(sso.getError() < 0) {
    	System.out.println("Error occurred");
    	return;
    }
    
    // Save token to cookie
    Cookie cookie = new Cookie("ssoToken", sso.getToken()); 
    cookie.setMaxAge(24*3600);
    cookie.setPath("/");
    response.addCookie(cookie);

Verify Token

  • Each service verifies SSO token delivered to the cookie.
    If SSO token validation succeeds, login processing.
    import com.google.gson.Gson;
    import com.rivest.sso.api.SSO;
    
    // Lookup token value in cookie
    String ssoToken = null;
    Cookie[] cookies = request.getCookies();
    for(int i=0; cookies != null && i < cookies.length; i++) {
    	Cookie c = cookies[i] ;
    		
    	// Gets the name of the saved cookie
    	String cName = c.getName();
    		
    	// Gets the value of cookies.
    	if(cName.equals("ssoToken")) {
    		ssoToken = c.getValue();
    	} 
    }
    
    // Create SSO Object
    SSO sso = new SSO();
    
    // Required on Token Verification Request
    sso.setToken(ssoToken);
    sso.setClientIp("192.168.0.122"); // In general request.getRemoteAddr()
    
    // Set the SSO Agent's PORT [Optional]
    sso.setAgentPort((short)8421);
    
    // Token Verification Request
    sso.verifyToken();
    
    // Error check
    if(sso.getError() != 0) {
    	System.out.println("Error occurred");
    	return;
    }
    			
    // User Information
    System.out.println("userId : " + sso.getUserId());
    System.out.println("userName : " + sso.getProfile("userName"));
    System.out.println("age : " + Integer.parseInt(sso.getProfile("age")));
    
    // TODO : Processing logins with user