public static void writePrincipal(GenericPrincipal p, ObjectOutput out) throws IOException { out.writeUTF(p.getName()); out.writeBoolean(p.getPassword()!=null); if ( p.getPassword()!= null ) out.writeUTF(p.getPassword()); String[] roles = p.getRoles(); if ( roles == null ) roles = new String[0]; out.writeInt(roles.length); for ( int i=0; i<roles.length; i++ ) out.writeUTF(roles[i]); boolean hasUserPrincipal = (p != p.getUserPrincipal() && p.getUserPrincipal() instanceof Serializable); out.writeBoolean(hasUserPrincipal); if (hasUserPrincipal) out.writeObject(p.getUserPrincipal()); }
public static void writePrincipal(GenericPrincipal p, ObjectOutput out) throws IOException { out.writeUTF(p.getName()); out.writeBoolean(p.getPassword()!=null); if ( p.getPassword()!= null ) out.writeUTF(p.getPassword()); String[] roles = p.getRoles(); if ( roles == null ) roles = new String[0]; out.writeInt(roles.length); for ( int i=0; i<roles.length; i++ ) out.writeUTF(roles[i]); boolean hasUserPrincipal = (p != p.getUserPrincipal() && p.getUserPrincipal() instanceof Serializable); out.writeBoolean(hasUserPrincipal); if (hasUserPrincipal) out.writeObject(p.getUserPrincipal()); }
public Object getContext(String key, Object data) throws PolicyContextException { Request req = currentRequest.get(); if (req == null || req.getPrincipal() == null) { return null; } Set<Principal> principals = new HashSet<Principal>(); principals.add(req.getPrincipal()); principals.add(getGroup(req.getPrincipal())); if (req.getPrincipal() instanceof GenericPrincipal) { try { String name = ((GenericPrincipal) req.getPrincipal()).getName(); String password = ((GenericPrincipal) req.getPrincipal()).getPassword(); String basicAuthHeader = "Basic " + Base64.getEncoder().encodeToString((name + ":" + password).getBytes("UTF-8")); principals.add(new BasicAuthorizationPrincipal(basicAuthHeader)); } catch (UnsupportedEncodingException e) { logger.warn("UnsupportedEncodingException while preparing basic auth principal"); } } final Subject s = new Subject(false, principals , Collections.EMPTY_SET, Collections.EMPTY_SET); return s; } }, false);
public static SerializablePrincipal createPrincipal(GenericPrincipal principal) { if ( principal==null) return null; return new SerializablePrincipal(principal.getName(), principal.getPassword(), principal.getRoles()!=null?Arrays.asList(principal.getRoles()):null, principal.getUserPrincipal()!=principal?principal.getUserPrincipal():null); }
public static SerializablePrincipal createPrincipal(GenericPrincipal principal) { if ( principal==null) return null; return new SerializablePrincipal(principal.getName(), principal.getPassword(), principal.getRoles()!=null?Arrays.asList(principal.getRoles()):null, principal.getUserPrincipal()!=principal?principal.getUserPrincipal():null); }
public SecuritySubject authenticate(AuthenticationToken<?, ?> token) throws AuthenticationException { if (delegate != null) { // if a security extension is installed, delegate to it return delegate.authenticate(token); } if (realm != null) { if (token instanceof UsernamePasswordToken) { UsernamePasswordToken usernamePassword = (UsernamePasswordToken) token; String username = usernamePassword.getPrincipal(); String password = usernamePassword.getCredentials(); Principal principal = realm.authenticate(username, password); if (principal instanceof GenericPrincipal) { GenericPrincipal generic = (GenericPrincipal) principal; Set<Role> roles = new HashSet<Role>(); for (String name : generic.getRoles()) { roles.add(new Role(name)); } return new BasicSecuritySubject(generic.getName(), generic.getPassword(), roles); } else { return new BasicSecuritySubject(username, password, Collections.<Role>emptySet()); } } } throw new AuthenticationException("Unable to authenticate because a Tomcat Realm or Fabric3 Security extension has not been configured"); } }
else if (samlSession.getPrincipal().getName().equals(principal.getName())){ if (!principal.getUserPrincipal().getName().equals(samlSession.getPrincipal().getName())) { throw new RuntimeException("Unknown State");
client.setName(genericPrincipal.getName()); client.setRoles(Stream.of(genericPrincipal.getRoles()).collect(toSet()));
protected SkeletonKeyToken buildToken(GenericPrincipal gp) { SkeletonKeyToken token = new SkeletonKeyToken(); token.id(generateId()); token.principal(gp.getName()); token.audience(skeletonKeyConfig.getRealm()); int expiration = skeletonKeyConfig.getAccessCodeLifetime() == 0 ? 3600 : skeletonKeyConfig.getAccessCodeLifetime(); if (skeletonKeyConfig.getTokenLifetime() > 0) { token.expiration((System.currentTimeMillis() / 1000) + expiration); } SkeletonKeyToken.Access realmAccess = new SkeletonKeyToken.Access(); for (String role : gp.getRoles()) { realmAccess.addRole(role); } token.setRealmAccess(realmAccess); return token; }
protected void logoutCurrentUser(Request request, HttpServletResponse response) throws IOException { if (request.getSessionInternal() == null || request.getSessionInternal().getPrincipal() == null) { redirectToWelcomePage(request, response); return; } GenericPrincipal principal = (GenericPrincipal) request.getSessionInternal().getPrincipal(); String username = principal.getName(); String admin = username; userSessionManagement.logout(username); request.setUserPrincipal(null); request.setAuthType(null); // logout user on all declared authenticated resources logoutResources(username, admin); redirectToWelcomePage(request, response); }