public Principal getUserPrincipal() { return SubjectHelper.getBestPrincipal(getSubject(), User.class); }
public boolean isUserInRole(String roleName) { if (subject == null) { return false; } return SubjectHelper.getPrincipal(subject, Role.class, roleName) != null; }
/** * Default setup of the logged on Subject Principals for Tomcat * @param subject * @param user */ protected void commitSubject(Subject containerSubject, Subject jetspeedSubject, AuthenticatedUser user) { // add user specific portal user name and roles subject.getPrincipals().add(SubjectHelper.getPrincipal(jetspeedSubject, UserSubjectPrincipal.class)); subject.getPrincipals().add(SubjectHelper.getPrincipal(jetspeedSubject, User.class)); boolean hasPortalUserRole = false; for (Principal role : SubjectHelper.getPrincipals(jetspeedSubject, Role.class)) { subject.getPrincipals().add(role); if (role.getName().equals(portalUserRole)) { hasPortalUserRole = true; } } if (!hasPortalUserRole) { // add portal user role: used in web.xml authorization to // detect authenticated portal users subject.getPrincipals().add(new RoleImpl(portalUserRole)); } } }
throws NodeException Principal principal = SubjectHelper.getBestPrincipal(subject, User.class); if (principal == null) for (Principal role : SubjectHelper.getPrincipals(subject, Role.class))
protected String combinePrincipals(RequestContext context, RuleCriterion criterion, Subject subject, String jptName) { StringBuffer result = new StringBuffer(); int count = 0; for (JetspeedPrincipal principal : SubjectHelper.getPrincipals(subject, jptName)) { if (count > 0) { result.append(COMBO_DELIMITER); } result.append(principal.getName()); count++; } if (count == 0) { return null; } return result.toString(); }
UserCredential userCredential = SubjectHelper.getUserCredential(subject); Integer passwordDaysValid = null;
protected String resolvePrincipals(RequestContext context, RuleCriterion criterion, Subject subject, String jptName) { StringBuffer result = new StringBuffer(); int count = 0; for (JetspeedPrincipal principal : SubjectHelper.getPrincipals(subject, jptName)) { if (count > 0) { result.append(VALUE_DELIMITER); } result.append(principal.getName()); count++; } if (count == 0) { return null; } return result.toString(); }
UserCredential userCredential = SubjectHelper.getUserCredential(um.getSubject(user)); if ( userCredential == null || !userCredential.isEnabled() )
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { // portal request filter if (servletRequest instanceof HttpServletRequest) { // retrieve current subject from session and wrap portal // request to support principal access HttpServletRequest request = (HttpServletRequest)servletRequest; Subject subject = (Subject)request.getSession().getAttribute(PortalReservedParameters.SESSION_KEY_SUBJECT); if (subject != null) { Principal principal = SubjectHelper.getPrincipal(subject, User.class); if ((principal == null) || !principal.getName().equals(guest)) { servletRequest = new PortalRequestWrapper(request, subject, principal); } } // tag request as filtered servletRequest.setAttribute(PortalReservedParameters.PORTAL_FILTER_ATTRIBUTE, "true"); } // continue request filter processing if (filterChain != null) { filterChain.doFilter(servletRequest, servletResponse); } } }
/** * Lookup current default user scope value. * * @return current user principal name */ public static String getCurrentUserScopeValue() { // lookup current user principal using subject Subject subject = JSSubject.getSubject(AccessController.getContext()); if (subject != null) { Principal userPrincipal = SubjectHelper.getBestPrincipal(subject, User.class); if (userPrincipal != null) { return userPrincipal.getName(); } } return null; } }
protected void commitSubject(Subject containerSubject, Subject jetspeedSubject, AuthenticatedUser user) { // add user specific portal user name and roles Principal userSubjectPrincipal = SubjectHelper.getPrincipal(jetspeedSubject, UserSubjectPrincipal.class); subject.getPrincipals().add(userSubjectPrincipal); boolean hasPortalUserRole = false; JBossGroup roles = new JBossGroup("Roles"); for (Principal role : SubjectHelper.getPrincipals(jetspeedSubject, Role.class)) { roles.addMember(role); if (role.getName().equals(portalUserRole)) { hasPortalUserRole = true; } } if (!hasPortalUserRole) { // add portal user role: used in web.xml authorization to // detect authenticated portal users roles.addMember(new RoleImpl(portalUserRole)); } subject.getPrincipals().add(roles); } }
public String resolve(RequestContext context, RuleCriterion criterion) { String value = super.resolve(context, criterion); if (value != null) { return value; } Subject subject = context.getSubject(); if (subject == null) { String msg = "Invalid (null) Subject in request pipeline"; log.error(msg); return null; } Principal principal = SubjectHelper.getPrincipal(subject, User.class); if (principal != null) { return principal.getName(); } return null; }
/** * Lookup current user scope value used to default new fragment properties. * * @return current user principal name */ public static String getCurrentUserScopeValue() { // lookup current user principal using subject Subject subject = JSSubject.getSubject(AccessController.getContext()); if (subject != null) { Principal userPrincipal = SubjectHelper.getBestPrincipal(subject, User.class); if (userPrincipal != null) { return userPrincipal.getName(); } } return null; } }
public Map<String, String> getUserAttributeMap(Subject subject, Collection<UserAttributeRef> userAttributeRefs, RequestContext context) { Map<String,String> userAttributeMap = new HashMap<String,String>(); Principal userPrincipal = SubjectHelper.getPrincipal(subject, User.class); if (null != userPrincipal) { log.debug("Got user principal: " + userPrincipal.getName()); Map<String, String> userInfo = ((User)userPrincipal).getInfoMap(); if (userAttributeRefs != null) { for (UserAttributeRef currentAttributeRef : userAttributeRefs) { String key = currentAttributeRef.getNameLink(); String name = currentAttributeRef.getName(); if (key == null) { key = name; } if (userInfo.containsKey(key)) { userAttributeMap.put(name, userInfo.get(key)); } } } } return userAttributeMap; } }
public Subject getSubject(RequestContext context) { Subject currentSubject = context.getSubject(); Iterator roles = currentSubject.getPrincipals(Role.class).iterator(); StringBuffer combo = new StringBuffer(); int count = 0; while (roles.hasNext()) { Role role = (Role)roles.next(); if (count > 0) { combo.append("-"); } combo.append(role.getName()); count++; } Set principals = new HashSet(); principals.add(SubjectHelper.getBestPrincipal(currentSubject, User.class)); principals.add(new TransientRole(combo.toString())); Subject subject = new Subject(true, principals, new HashSet(), new HashSet()); return subject; }
protected Principal getUserPrincipal(RequestContext context) throws Exception { Subject subject = getSubjectFromSession(context); if (subject != null) { return SubjectHelper.getPrincipal(subject, User.class); } // otherwise return anonymous principal return userMgr.newTransientUser(userMgr.getAnonymousUser()); }
userPrincipal = SubjectHelper.getBestPrincipal(subject, User.class);
public void sessionDestroyed(HttpSessionEvent se) { Subject subject = (Subject)se.getSession().getAttribute(PortalReservedParameters.SESSION_KEY_SUBJECT); if (subject == null) return; if (firstInit) { // Servlet already destroyed, // Can't reliably access ComponentManager (Spring) anymore // as for instance WAS 6.0.2 has a bug invoking this method with a wrong classLoader (not the one for the WebApp) return; } Principal subjectUserPrincipal = SubjectHelper.getPrincipal(subject, UserSubjectPrincipal.class); PortalStatistics statistics = engine.getComponentManager().lookupComponent("PortalStatistics"); long sessionLength = System.currentTimeMillis() - se.getSession().getCreationTime(); String ipAddress = (String)se.getSession().getAttribute(SecurityValve.IP_ADDRESS); statistics.logUserLogout(ipAddress, subjectUserPrincipal.getName(), sessionLength); UserContentCacheManager userContentCacheManager = engine.getComponentManager().lookupComponent("userContentCacheManager"); userContentCacheManager.evictUserContentCache(subjectUserPrincipal.getName(), se.getSession().getId()); // clear preferences cache PortletPreferencesProvider preferencesProvider = engine.getComponentManager().lookupComponent("portletPreferencesProvider"); if (preferencesProvider != null) { preferencesProvider.sessionDestroyedEvent(se.getSession()); } }
/** * Setup and maintain profiler context to be used to reap rule caches * for principals on session end. * * @param context request context * @throws ProfilerException when subject or principal not available */ private void setupProfilerContext(RequestContext context) throws ProfilerException { // validate profiler context ProfilerContext profilerContext = (ProfilerContext) context.getSessionAttribute(PROFILER_CONTEXT_ATTRIBUTE_NAME); try { // access session principal and test for change Principal principal = SubjectHelper.getBestPrincipal(context.getSubject(), UserSubjectPrincipal.class); if (principal == null) { throw new NullPointerException("Principal not found"); } if ((profilerContext == null) || (profilerContext.getPrincipal() != principal)) { // setup/reset profiler context context.setSessionAttribute(PROFILER_CONTEXT_ATTRIBUTE_NAME, new ProfilerContext(this, principal)); } } catch (Exception e) { String message = "Unable to access principal in pipeline: " + e; log.error(message, e); throw new ProfilerException(message, e); } }
if (subject != null) Principal principal = SubjectHelper.getPrincipal(subject, User.class); if (principal != null && principal.getName().equals(this.guest))