@Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { this.subject = subject; this.callbackHandler = callbackHandler; debug = "true".equalsIgnoreCase((String)options.get("debug")); credentialsInvalidate = "true".equalsIgnoreCase((String)options.get("credentialsInvalidate")); if (options.get(GUEST_USER) != null) { userName = (String)options.get(GUEST_USER); } if (options.get(GUEST_GROUP) != null) { groupName = (String)options.get(GUEST_GROUP); } principals.add(new UserPrincipal(userName)); principals.add(new GroupPrincipal(groupName)); if (debug) { LOG.debug("Initialized debug=" + debug + " guestUser=" + userName + " guestGroup=" + groupName); } }
@Override public SecurityContext authenticate(String username, String password, X509Certificate[] peerCertificates) throws SecurityException { try { CallbackHandler callback = new JaasCertificateCallbackHandler(peerCertificates); LoginContext lc = new LoginContext(jaasConfiguration, callback); lc.login(); Subject subject = lc.getSubject(); String dnName = ""; for (Principal principal : subject.getPrincipals()) { if (principal instanceof UserPrincipal) { dnName = ((UserPrincipal)principal).getName(); break; } } return new JaasCertificateSecurityContext(dnName, subject, peerCertificates); } catch (Exception e) { throw new SecurityException("User name [" + username + "] or password is invalid. " + e.getMessage(), e); } } }
@Override public boolean commit() throws LoginException { if (!succeeded) { clear(); if (debug) { LOG.debug("commit, result: false"); } return false; } principals.add(new UserPrincipal(user)); Set<String> matchedGroups = groups.get(user); if (matchedGroups != null) { for (String entry : matchedGroups) { principals.add(new GroupPrincipal(entry)); } } subject.getPrincipals().addAll(principals); if (debug) { LOG.debug("commit, result: true"); } commitSucceeded = true; return true; }
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { final ConnectionContext context = producerExchange.getConnectionContext(); String userID = context.getUserName(); if (isUseAuthenticatePrincipal()) { SecurityContext securityContext = context.getSecurityContext(); if (securityContext != null) { Set<?> principals = securityContext.getPrincipals(); if (principals != null) { for (Object candidate : principals) { if (candidate instanceof UserPrincipal) { userID = ((UserPrincipal)candidate).getName(); break; } } } } } messageSend.setUserID(userID); super.send(producerExchange, messageSend); }
/** * Overriding to complete login process. Standard JAAS. */ @Override public boolean commit() throws LoginException { if (debug) { LOG.debug("commit"); } if (!succeeded) { clear(); return false; } principals.add(new UserPrincipal(username)); for (String group : getUserGroups(username)) { principals.add(new GroupPrincipal(group)); } subject.getPrincipals().addAll(principals); username = null; commitSucceeded = true; return true; }
@Override public SecurityContext authenticate(String username, String password, X509Certificate[] peerCertificates) throws SecurityException { try { CallbackHandler callback = new JaasCertificateCallbackHandler(peerCertificates); LoginContext lc = new LoginContext(jaasConfiguration, callback); lc.login(); Subject subject = lc.getSubject(); String dnName = ""; for (Principal principal : subject.getPrincipals()) { if (principal instanceof UserPrincipal) { dnName = ((UserPrincipal)principal).getName(); break; } } return new JaasCertificateSecurityContext(dnName, subject, peerCertificates); } catch (Exception e) { throw new SecurityException("User name [" + username + "] or password is invalid. " + e.getMessage(), e); } } }
@Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("User name"); callbacks[1] = new PasswordCallback("Password", false); try { handler.handle(callbacks); } catch (IOException ioe) { throw (LoginException)new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException)new LoginException().initCause(uce); } String password; String username = ((NameCallback)callbacks[0]).getName(); if (username == null) return false; if (((PasswordCallback)callbacks[1]).getPassword() != null) password = new String(((PasswordCallback)callbacks[1]).getPassword()); else password=""; // authenticate will throw LoginException // in case of failed authentication authenticate(username, password); user = new UserPrincipal(username); succeeded = true; return true; }
@Override public SecurityContext authenticate(String username, String password, X509Certificate[] peerCertificates) throws SecurityException { try { CallbackHandler callback = new JaasCertificateCallbackHandler(peerCertificates); LoginContext lc = new LoginContext(jaasConfiguration, callback); lc.login(); Subject subject = lc.getSubject(); String dnName = ""; for (Principal principal : subject.getPrincipals()) { if (principal instanceof UserPrincipal) { dnName = ((UserPrincipal)principal).getName(); break; } } return new JaasCertificateSecurityContext(dnName, subject, peerCertificates); } catch (Exception e) { throw new SecurityException("User name [" + username + "] or password is invalid. " + e.getMessage(), e); } } }
members.add(new UserPrincipal(principalName));
@Override public SecurityContext authenticate(String username, String password, X509Certificate[] peerCertificates) throws SecurityException { try { CallbackHandler callback = new JaasCertificateCallbackHandler(peerCertificates); LoginContext lc = new LoginContext(jaasConfiguration, callback); lc.login(); Subject subject = lc.getSubject(); String dnName = ""; for (Principal principal : subject.getPrincipals()) { if (principal instanceof UserPrincipal) { dnName = ((UserPrincipal)principal).getName(); break; } } return new JaasCertificateSecurityContext(dnName, subject, peerCertificates); } catch (Exception e) { throw new SecurityException("User name [" + username + "] or password is invalid. " + e.getMessage(), e); } } }
@Override public boolean commit() throws LoginException { Set<Principal> principals = subject.getPrincipals(); principals.add(new UserPrincipal(username)); for (GroupPrincipal gp : groups) { principals.add(gp); } return true; }
Principal nextPrincipal = (Principal)iter.next(); if (nextPrincipal instanceof UserPrincipal) { dnName = ((UserPrincipal)nextPrincipal).getName(); break;
@Override public boolean commit() throws LoginException { Set<Principal> principals = subject.getPrincipals(); principals.add(new UserPrincipal(username)); for (GroupPrincipal gp : groups) { principals.add(gp); } return true; }
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { final ConnectionContext context = producerExchange.getConnectionContext(); String userID = context.getUserName(); if (isUseAuthenticatePrincipal()) { SecurityContext securityContext = context.getSecurityContext(); if (securityContext != null) { Set<?> principals = securityContext.getPrincipals(); if (principals != null) { for (Object candidate : principals) { if (candidate instanceof UserPrincipal) { userID = ((UserPrincipal)candidate).getName(); break; } } } } } messageSend.setUserID(userID); super.send(producerExchange, messageSend); }
@Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { this.subject = subject; this.callbackHandler = callbackHandler; debug = "true".equalsIgnoreCase((String)options.get("debug")); credentialsInvalidate = "true".equalsIgnoreCase((String)options.get("credentialsInvalidate")); if (options.get(GUEST_USER) != null) { userName = (String)options.get(GUEST_USER); } if (options.get(GUEST_GROUP) != null) { groupName = (String)options.get(GUEST_GROUP); } principals.add(new UserPrincipal(userName)); principals.add(new GroupPrincipal(groupName)); if (debug) { LOG.debug("Initialized debug=" + debug + " guestUser=" + userName + " guestGroup=" + groupName); } }
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { final ConnectionContext context = producerExchange.getConnectionContext(); String userID = context.getUserName(); if (isUseAuthenticatePrincipal()) { SecurityContext securityContext = context.getSecurityContext(); if (securityContext != null) { Set<?> principals = securityContext.getPrincipals(); if (principals != null) { for (Object candidate : principals) { if (candidate instanceof UserPrincipal) { userID = ((UserPrincipal)candidate).getName(); break; } } } } } messageSend.setUserID(userID); super.send(producerExchange, messageSend); }
@Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { this.subject = subject; this.callbackHandler = callbackHandler; debug = "true".equalsIgnoreCase((String)options.get("debug")); credentialsInvalidate = "true".equalsIgnoreCase((String)options.get("credentialsInvalidate")); if (options.get(GUEST_USER) != null) { userName = (String)options.get(GUEST_USER); } if (options.get(GUEST_GROUP) != null) { groupName = (String)options.get(GUEST_GROUP); } principals.add(new UserPrincipal(userName)); principals.add(new GroupPrincipal(groupName)); if (debug) { LOG.debug("Initialized debug=" + debug + " guestUser=" + userName + " guestGroup=" + groupName); } }
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { final ConnectionContext context = producerExchange.getConnectionContext(); String userID = context.getUserName(); if (isUseAuthenticatePrincipal()) { SecurityContext securityContext = context.getSecurityContext(); if (securityContext != null) { Set<?> principals = securityContext.getPrincipals(); if (principals != null) { for (Object candidate : principals) { if (candidate instanceof UserPrincipal) { userID = ((UserPrincipal)candidate).getName(); break; } } } } } messageSend.setUserID(userID); super.send(producerExchange, messageSend); }
@Override public boolean commit() throws LoginException { boolean result = loginSucceeded; if (result) { principals.add(new UserPrincipal(user)); Set<String> matchedGroups = groups.get(user); if (matchedGroups != null) { for (String entry : matchedGroups) { principals.add(new GroupPrincipal(entry)); } } subject.getPrincipals().addAll(principals); } // will whack loginSucceeded clear(); if (debug) { LOG.debug("commit, result: " + result); } return result; }
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { final ConnectionContext context = producerExchange.getConnectionContext(); String userID = context.getUserName(); if (isUseAuthenticatePrincipal()) { SecurityContext securityContext = context.getSecurityContext(); if (securityContext != null) { Set<?> principals = securityContext.getPrincipals(); if (principals != null) { for (Object candidate : principals) { if (candidate instanceof UserPrincipal) { userID = ((UserPrincipal)candidate).getName(); break; } } } } } messageSend.setUserID(userID); super.send(producerExchange, messageSend); }