Java Code Examples for java.security.Principal#toString()

The following examples show how to use java.security.Principal#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebUtil.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * TODO default proper exception at lams level to replace RuntimeException TODO isTesting should be removed when
    * login is done properly.
    *
    * @param req
    *            -
    * @return username from principal object
    */
   public static String getUsername(HttpServletRequest req, boolean isTesting) throws RuntimeException {
if (isTesting) {
    return "test";
}

Principal prin = req.getUserPrincipal();
if (prin == null) {
    throw new RuntimeException(
	    "Trying to get username but principal object missing. Request is " + req.toString());
}

String username = prin.getName();
if (username == null) {
    throw new RuntimeException("Name missing from principal object. Request is " + req.toString()
	    + " Principal object is " + prin.toString());
}

return username;
   }
 
Example 2
Source File: ExamController.java    From spring-microservice-exam with MIT License 4 votes vote down vote up
@GetMapping("sayHello")
public String sayHello(Principal principal, String name) {
    return "hello, " + name + ", principal: " + principal.toString();
}