List of usage examples for javax.security.auth Subject getPrincipals
public Set<Principal> getPrincipals()
From source file:fi.csc.mobileauth.shibboleth.rest.MobileServiceLoginHandler.java
protected static final Subject populatePrincipals(final Subject subject, final Map<String, String> attributes, String mobileNumber) {/*w w w .j av a 2 s. co m*/ String age = DatatypeHelper.safeTrimOrNullString(attributes.get(FiComConstants.PERSON_AGE)); String givenName = DatatypeHelper.safeTrimOrNullString(attributes.get(FiComConstants.PERSON_GIVENNAME)); String hetu = DatatypeHelper.safeTrimOrNullString(attributes.get(FiComConstants.PERSON_HETU)); String satu = DatatypeHelper.safeTrimOrNullString(attributes.get(FiComConstants.PERSON_SATU)); String surname = DatatypeHelper.safeTrimOrNullString(attributes.get(FiComConstants.PERSON_SURNAME)); if (age != null) { log.debug("Populating the age={} to the session", age); subject.getPrincipals().add(new FiComAgePrincipal(age)); } if (givenName != null) { log.debug("Populating the givenName={} to the session", givenName); subject.getPrincipals().add(new FiComGivenNamePrincipal(givenName)); } if (hetu != null) { log.debug("Populating the hetu to the session"); subject.getPrincipals().add(new FiComHetuPrincipal(hetu)); } if (satu != null) { log.debug("Populating the satu to the session", age); subject.getPrincipals().add(new FiComSatuPrincipal(satu)); } if (surname != null) { log.debug("Populating the surname={} to the session", surname); subject.getPrincipals().add(new FiComSurNamePrincipal(surname)); } subject.getPrincipals().add(new MobileNumberPrincipal(mobileNumber)); log.debug("Principals populated to the session."); return subject; }
From source file:org.camelcookbook.security.springsecurity.SecuritySubjectLoader.java
@Override public void process(Exchange exchange) throws Exception { Message in = exchange.getIn();/*w w w.ja va 2 s.co m*/ String username = in.getHeader("username", String.class); String password = in.getHeader("password", String.class); Authentication authenticationToken = new UsernamePasswordAuthenticationToken(username, password); Subject subject = new Subject(); subject.getPrincipals().add(authenticationToken); in.setHeader(Exchange.AUTHENTICATION, subject); }
From source file:org.apache.hadoop.security.UserGroupInformation.java
/** * Create a user from a login name. It is intended to be used for remote * users in RPC, since it won't have any credentials. * @param user the full user principal name, must not be empty or null * @return the UserGroupInformation for the remote user. *//*from ww w. j a v a 2s .c om*/ public static UserGroupInformation createRemoteUser(String user) { if (user == null || "".equals(user)) { throw new IllegalArgumentException("Null user"); } Subject subject = new Subject(); subject.getPrincipals().add(new User(user)); UserGroupInformation result = new UserGroupInformation(subject); result.setAuthenticationMethod(AuthenticationMethod.SIMPLE); return result; }
From source file:uk.org.openeyes.oink.security.SimpleIdentityService.java
@Override public String getUserId(Subject s) { for (Principal p : s.getPrincipals()) { if (p instanceof UsernamePasswordAuthenticationToken) { UsernamePasswordAuthenticationToken details = (UsernamePasswordAuthenticationToken) p; String name = details.getName(); String[] parts = name.split("@"); if (parts.length == 2) { return parts[0]; }//from ww w . j a v a 2 s . c o m } } return null; }
From source file:com.muk.services.processor.BearerTokenAuthPrincipalProcessor.java
@Override public void process(Exchange exchange) throws Exception { String bearerToken = RestConstants.Rest.anonymousToken; if (exchange.getIn().getHeaders().containsKey(HttpHeaders.AUTHORIZATION)) { bearerToken = StringUtils/*from w w w . j a v a2 s .co m*/ .substringAfter(exchange.getIn().getHeader(HttpHeaders.AUTHORIZATION, String.class), "Bearer "); } // create an Authentication object // build a new bearer token type final BearerAuthenticationToken authToken = new BearerAuthenticationToken(bearerToken); // wrap it in a Subject final Subject subject = new Subject(); subject.getPrincipals().add(authToken); // place the Subject in the In message exchange.getIn().setHeader(Exchange.AUTHENTICATION, subject); }
From source file:org.apache.coheigea.cxf.x509.authorization.X509AuthorizationValidator.java
public Credential validate(Credential credential, RequestData data) throws WSSecurityException { Credential validatedCredential = super.validate(credential, data); // Validate the Certificate X509Certificate[] certs = validatedCredential.getCertificates(); if (certs == null || certs.length == 0) { if (log.isDebugEnabled()) { log.debug("No X.509 Certificates are found"); }//from w w w. j a v a 2s . co m throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION); } Principal principal = validatedCredential.getPrincipal(); // Mock up a Subject Subject subject = new Subject(); subject.getPrincipals().add(principal); subject.getPrincipals().add(new SimpleGroup("employee")); if (principal.getName().startsWith("CN=Client,O=Apache")) { subject.getPrincipals().add(new SimpleGroup("boss")); } subject.setReadOnly(); credential.setSubject(subject); return credential; }
From source file:com.muk.services.processor.BasicAuthPrincipalProcessor.java
@Override public void process(Exchange exchange) throws Exception { @SuppressWarnings("unchecked") final List<Header> httpHeaders = exchange.getIn().getHeader("org.restlet.http.headers", List.class); String userpass = "bad:creds"; for (final Header header : httpHeaders) { if (header.getName().toLowerCase().equals(HttpHeaders.AUTHORIZATION.toLowerCase())) { userpass = new String(Base64.decodeBase64( (StringUtils.substringAfter(header.getValue(), " ").getBytes(StandardCharsets.UTF_8))), StandardCharsets.UTF_8); break; }/*from www . j av a 2 s . co m*/ } final String[] tokens = userpass.split(":"); // create an Authentication object // build a new bearer token type final UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(tokens[0], tokens[1]); // wrap it in a Subject final Subject subject = new Subject(); subject.getPrincipals().add(authToken); // place the Subject in the In message exchange.getIn().setHeader(Exchange.AUTHENTICATION, subject); }
From source file:uk.org.openeyes.oink.security.HttpBasicPreauthProcessor.java
public void extractAuthenticationDetailsFromHttp(Exchange exchange) throws SecurityException { // get the username and password from the HTTP header // http://en.wikipedia.org/wiki/Basic_access_authentication String authorizationHeader = exchange.getIn().getHeader("Authorization", String.class); if (authorizationHeader == null) { throw new SecurityException("No HttpBasic Authorization Header was found in the request"); }/*from w w w. j a va2 s.co m*/ String basicPrefix = "Basic "; String userPassword = authorizationHeader.substring(basicPrefix.length()); byte[] header = Base64.decodeBase64(userPassword.getBytes()); if (header == null) { throw new SecurityException("Invalid Http Basic Authorization Header found in the request"); } String userpass = new String(header); String[] tokens = userpass.split(":"); // create an Authentication object UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(tokens[0], tokens[1]); // wrap it in a Subject Subject subject = new Subject(); subject.getPrincipals().add(authToken); // place the Subject in the In message exchange.getIn().setHeader(Exchange.AUTHENTICATION, subject); logger.debug("Found HttpBasic Authentication header"); // Spring security will intercept this and authenticate }
From source file:org.apache.hadoop.security.UserGroupInformation.java
/** * Create a proxy user using username of the effective user and the ugi of the * real user./* w w w .j a va2 s . c o m*/ * @param user * @param realUser * @return proxyUser ugi */ public static UserGroupInformation createProxyUser(String user, UserGroupInformation realUser) { if (user == null || "".equals(user)) { throw new IllegalArgumentException("Null user"); } if (realUser == null) { throw new IllegalArgumentException("Null real user"); } Subject subject = new Subject(); Set<Principal> principals = subject.getPrincipals(); principals.add(new User(user)); principals.add(new RealUser(realUser)); UserGroupInformation result = new UserGroupInformation(subject); result.setAuthenticationMethod(AuthenticationMethod.PROXY); return result; }
From source file:eu.openanalytics.rsb.security.JmxSecurityAuthenticator.java
@Override public Subject authenticate(final Object credentials) { try {//from www. j a v a2s . com final String[] info = (String[]) credentials; final Authentication authentication = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken(info[0], info[1])); final User authenticatedUser = (User) authentication.getPrincipal(); if ((isRsbAdminPrincipal(authenticatedUser)) || (isRsbAdminRole(authenticatedUser))) { final Subject s = new Subject(); s.getPrincipals().add(new JMXPrincipal(authentication.getName())); return s; } else { throw new SecurityException("Authenticated user " + authenticatedUser + " is not an RSB admin"); } } catch (final Exception e) { LOGGER.error("Error when trying to authenticate JMX credentials of type: " + credentials.getClass(), e); throw new SecurityException(e); } }