Search in sources :

Example 1 with MyPrincipal

use of org.javaee7.jaspic.customprincipal.sam.MyPrincipal in project javaee7-samples by javaee-samples.

the class PublicServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.getWriter().write("This is a public servlet \n");
    String webName = null;
    boolean isCustomPrincipal = false;
    if (request.getUserPrincipal() != null) {
        Principal principal = request.getUserPrincipal();
        isCustomPrincipal = principal instanceof MyPrincipal;
        webName = principal.getName();
    }
    boolean webHasRole = request.isUserInRole("architect");
    response.getWriter().write("isCustomPrincipal: " + isCustomPrincipal + "\n");
    response.getWriter().write("web username: " + webName + "\n");
    response.getWriter().write("web user has role \"architect\": " + webHasRole + "\n");
}
Also used : MyPrincipal(org.javaee7.jaspic.customprincipal.sam.MyPrincipal) Principal(java.security.Principal) MyPrincipal(org.javaee7.jaspic.customprincipal.sam.MyPrincipal)

Example 2 with MyPrincipal

use of org.javaee7.jaspic.customprincipal.sam.MyPrincipal in project javaee7-samples by javaee-samples.

the class ProtectedServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.getWriter().write("This is a protected servlet \n");
    String webName = null;
    boolean isCustomPrincipal = false;
    if (request.getUserPrincipal() != null) {
        Principal principal = request.getUserPrincipal();
        isCustomPrincipal = principal instanceof MyPrincipal;
        webName = request.getUserPrincipal().getName();
    }
    boolean webHasRole = request.isUserInRole("architect");
    response.getWriter().write("isCustomPrincipal: " + isCustomPrincipal + "\n");
    response.getWriter().write("web username: " + webName + "\n");
    response.getWriter().write("web user has role \"architect\": " + webHasRole + "\n");
}
Also used : MyPrincipal(org.javaee7.jaspic.registersession.sam.MyPrincipal) Principal(java.security.Principal) MyPrincipal(org.javaee7.jaspic.registersession.sam.MyPrincipal)

Example 3 with MyPrincipal

use of org.javaee7.jaspic.customprincipal.sam.MyPrincipal in project javaee7-samples by javaee-samples.

the class PublicServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.getWriter().write("This is a public servlet \n");
    String webName = null;
    boolean isCustomPrincipal = false;
    if (request.getUserPrincipal() != null) {
        Principal principal = request.getUserPrincipal();
        isCustomPrincipal = principal instanceof MyPrincipal;
        webName = principal.getName();
    }
    boolean webHasRole = request.isUserInRole("architect");
    response.getWriter().write("isCustomPrincipal: " + isCustomPrincipal + "\n");
    response.getWriter().write("web username: " + webName + "\n");
    response.getWriter().write("web user has role \"architect\": " + webHasRole + "\n");
}
Also used : MyPrincipal(org.javaee7.jaspic.registersession.sam.MyPrincipal) Principal(java.security.Principal) MyPrincipal(org.javaee7.jaspic.registersession.sam.MyPrincipal)

Example 4 with MyPrincipal

use of org.javaee7.jaspic.customprincipal.sam.MyPrincipal in project javaee7-samples by javaee-samples.

the class ProtectedServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.getWriter().write("This is a protected servlet \n");
    String webName = null;
    boolean isCustomPrincipal = false;
    if (request.getUserPrincipal() != null) {
        Principal principal = request.getUserPrincipal();
        isCustomPrincipal = principal instanceof MyPrincipal;
        webName = request.getUserPrincipal().getName();
    }
    boolean webHasRole = request.isUserInRole("architect");
    response.getWriter().write("isCustomPrincipal: " + isCustomPrincipal + "\n");
    response.getWriter().write("web username: " + webName + "\n");
    response.getWriter().write("web user has role \"architect\": " + webHasRole + "\n");
}
Also used : MyPrincipal(org.javaee7.jaspic.customprincipal.sam.MyPrincipal) Principal(java.security.Principal) MyPrincipal(org.javaee7.jaspic.customprincipal.sam.MyPrincipal)

Aggregations

Principal (java.security.Principal)4 MyPrincipal (org.javaee7.jaspic.customprincipal.sam.MyPrincipal)2 MyPrincipal (org.javaee7.jaspic.registersession.sam.MyPrincipal)2