{"action":"created","issue":{"url":"https://api.github.com/repos/payara/Payara/issues/290","labels_url":"https://api.github.com/repos/payara/Payara/issues/290/labels{/name}","comments_url":"https://api.github.com/repos/payara/Payara/issues/290/comments","events_url":"https://api.github.com/repos/payara/Payara/issues/290/events","html_url":"https://github.com/payara/Payara/issues/290","id":78411572,"number":290,"title":"request.getUserPrincipal() does not return CustomPrincipal","user":{"login":"Sultry","id":800078,"avatar_url":"https://avatars.githubusercontent.com/u/800078?v=3","gravatar_id":"","url":"https://api.github.com/users/Sultry","html_url":"https://github.com/Sultry","followers_url":"https://api.github.com/users/Sultry/followers","following_url":"https://api.github.com/users/Sultry/following{/other_user}","gists_url":"https://api.github.com/users/Sultry/gists{/gist_id}","starred_url":"https://api.github.com/users/Sultry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sultry/subscriptions","organizations_url":"https://api.github.com/users/Sultry/orgs","repos_url":"https://api.github.com/users/Sultry/repos","events_url":"https://api.github.com/users/Sultry/events{/privacy}","received_events_url":"https://api.github.com/users/Sultry/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-20T07:29:51Z","updated_at":"2015-05-20T07:31:12Z","closed_at":null,"body":"I've an own javax.security.auth.message.module.ServerAuthModule implementation.\r\nIn validateRequest() I put an instance of custom Principal to the callbackhandler\r\n```java\r\nCustomPrincipal myprincipal = ...;\r\ncallbackHandler.handle(new Callback[]\r\n{ new CallerPrincipalCallback(clientSubject, myprincipal), new GroupPrincipalCallback(...) }\r\n);\r\n```\r\nIn the application request.getUserPrincipal() returns an instance of com.sun.enterprise.security.web.integration.WebPrincipal and NOT an instance of CustomPrincipal!\r\nIn an ejb the call of ejbContext.getCallerPrincipal() does return an instance of CustomPrincipal!\r\n\r\nThat is strange, request.getUserPrincipal() should return the principal which is set in the ServerAuthModule"},"comment":{"url":"https://api.github.com/repos/payara/Payara/issues/comments/103793115","html_url":"https://github.com/payara/Payara/issues/290#issuecomment-103793115","issue_url":"https://api.github.com/repos/payara/Payara/issues/290","id":103793115,"user":{"login":"Sultry","id":800078,"avatar_url":"https://avatars.githubusercontent.com/u/800078?v=3","gravatar_id":"","url":"https://api.github.com/users/Sultry","html_url":"https://github.com/Sultry","followers_url":"https://api.github.com/users/Sultry/followers","following_url":"https://api.github.com/users/Sultry/following{/other_user}","gists_url":"https://api.github.com/users/Sultry/gists{/gist_id}","starred_url":"https://api.github.com/users/Sultry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sultry/subscriptions","organizations_url":"https://api.github.com/users/Sultry/orgs","repos_url":"https://api.github.com/users/Sultry/repos","events_url":"https://api.github.com/users/Sultry/events{/privacy}","received_events_url":"https://api.github.com/users/Sultry/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T07:31:12Z","updated_at":"2015-05-20T07:31:12Z","body":"Depends on this bug made that workaround:\r\n```java\r\nprivate static Principal glassfishWorkAround(HttpServletRequest request) {\r\n        Principal principal = null;\r\n        try {\r\n            Principal webPrincipal = request.getUserPrincipal();\r\n            if (webPrincipal != null) {\r\n                Class glassfishWrapper = Class.forName(\"com.sun.enterprise.security.web.integration.WebPrincipal\");\r\n                if (glassfishWrapper.isInstance(webPrincipal)) {\r\n                    Field customPrincipal = glassfishWrapper.getDeclaredField(\"customPrincipal\");\r\n                    customPrincipal.setAccessible(true);\r\n                    principal = (Principal) customPrincipal.get(webPrincipal);\r\n                } else {\r\n                    principal = webPrincipal;\r\n                }\r\n            }\r\n        } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException | ClassNotFoundException ex) {\r\n            LOGGER.throwing(\"SecurityConstraint\", \"glassfishWorkAround\", ex);\r\n        }\r\n        return principal;\r\n}\r\n\r\npublic static Principal getPrincipal(HttpServletRequest request) {\r\n        return glassfishWorkAround(request);\r\n}\r\n```\r\nHope it helps somebody! Anyway hope this bug will be resolved soon."}}