SecurityContext
Code IndexAdd Codota to your IDE (free)

Best code snippets using org.apache.cxf.security.SecurityContext(Showing top 20 results out of 315)

Refine search

  • Principal
  • Message
  • Common ways to obtain SecurityContext
private void myMethod () {
SecurityContext s =
  • Message message;message.get(SecurityContext.class)
  • Principal p;new DefaultSecurityContext(p, subject)
  • SoapMessage soapMessage;soapMessage.get(SecurityContext.class)
  • Smart code suggestions by Codota
}
origin: apache/cxf

protected String getUserName(Crypto crypto, Message message) {
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    return sc.getUserPrincipal().getName();
  }
  return RSSecurityUtils.getUserName(crypto, null);
}
origin: org.apache.cxf/cxf-core

public void handleMessage(Message message) throws Fault {
  Method method = getTargetMethod(message);
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    if (authorize(sc, method)) {
      return;
    }
  } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) {
    return;
  }
  throw new AccessDeniedException("Unauthorized");
}
origin: org.apache.cxf/cxf-core

@Override
public void handleMessage(Message message) throws Fault {
  OperationInfo opinfo = getTargetOperationInfo(message);
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    if (opinfo.getName() != null
      && authorize(sc, opinfo.getName().getLocalPart())) {
      return;
    }
  } else if (!isMethodProtected(opinfo.getName().getLocalPart()) && isAllowAnonymousUsers()) {
    return;
  }
  throw new AccessDeniedException("Unauthorized");
}
origin: apache/cxf

protected boolean authorize(SecurityContext sc, String key) {
  List<String> expectedRoles = getExpectedRoles(key);
  if (expectedRoles.isEmpty()) {
    List<String> denyRoles = getDenyRoles(key);
    return denyRoles.isEmpty() ? true : isUserInRole(sc, denyRoles, true);
  }
  if (isUserInRole(sc, expectedRoles, false)) {
    return true;
  }
  if (LOG.isLoggable(Level.FINE)) {
    LOG.fine(sc.getUserPrincipal().getName() + " is not authorized");
  }
  return false;
}
origin: apache/cxf

@GET
@Produces("text/html")
public LogoutResponse logout(@CookieParam(SSOConstants.SECURITY_CONTEXT_TOKEN) Cookie context,
          @Context SecurityContext sc) {
  doLogout(context, sc);
  // Use View Handler to tell the user that the logout has been successful,
  // optionally listing the user login name and/or linking to the main application address,
  // the user may click on it, will be redirected to IDP and the process will start again
  return new LogoutResponse(sc.getUserPrincipal().getName(), mainApplicationAddress);
}
origin: apache/cxf

private String getPrincipal(Message message) {
  String principal = getJAASPrincipal();
  if (principal != null) {
    return principal;
  }
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    return sc.getUserPrincipal().getName();
  }
  AuthorizationPolicy authPolicy = message.get(AuthorizationPolicy.class);
  if (authPolicy != null) {
    return authPolicy.getUserName();
  }
  return null;
}
origin: org.apache.cxf/cxf-bundle

public static UserSubject createSubject(SecurityContext securityContext) {
  List<String> roleNames = Collections.emptyList();
  if (securityContext instanceof LoginSecurityContext) {
    roleNames = new ArrayList<String>();
    Set<Principal> roles = ((LoginSecurityContext)securityContext).getUserRoles();
    for (Principal p : roles) {
      roleNames.add(p.getName());
    }
  }
  return 
    new UserSubject(securityContext.getUserPrincipal().getName(), roleNames);
}

origin: apache/cxf

protected UserSubject getGrantSubject(Message message, SamlAssertionWrapper wrapper) {
  SecurityContext sc = scProvider.getSecurityContext(message, wrapper);
  if (sc instanceof SAMLSecurityContext) {
    SAMLSecurityContext jaxrsSc = (SAMLSecurityContext)sc;
    Set<Principal> rolesP = jaxrsSc.getUserRoles();
    List<String> roles = new ArrayList<>();
    if (roles != null) {
      for (Principal p : rolesP) {
        roles.add(p.getName());
      }
    }
    return new SamlUserSubject(jaxrsSc.getUserPrincipal().getName(),
                  roles,
                  jaxrsSc.getClaims());
  }
  return new UserSubject(sc.getUserPrincipal().getName());
}
origin: org.apache.cxf/cxf-rt-rs-security-sso-saml

private void doLogout(Cookie context, SecurityContext sc) {
  if (context == null || sc.getUserPrincipal() == null || sc.getUserPrincipal().getName() == null) {
    reportError("MISSING_RESPONSE_STATE");
    throw ExceptionUtils.toBadRequestException(null, null);
  }
  stateProvider.removeResponseState(context.getValue());
}
origin: org.apache.camel/camel-cxf

SecurityContext securityContext = cxfMessage.get(SecurityContext.class);
if (securityContext instanceof LoginSecurityContext
  && ((LoginSecurityContext)securityContext).getSubject() != null) {
  camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, 
                      ((LoginSecurityContext)securityContext).getSubject());
} else if (securityContext != null && securityContext.getUserPrincipal() != null) {
  Subject subject = new Subject();
  subject.getPrincipals().add(securityContext.getUserPrincipal());
  camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, subject);
origin: org.apache.cxf/cxf-core

public void handleMessage(Message message) throws Fault {
  SecurityToken token = message.get(SecurityToken.class);
  if (token == null) {
    reportSecurityException("Security Token is not available on the current message");
  }
  SecurityContext context = message.get(SecurityContext.class);
  if (context == null || context.getUserPrincipal() == null) {
    reportSecurityException("User Principal is not available on the current message");
  }
  Subject subject = null;
  try {
    subject = createSubject(token);
  } catch (Exception ex) {
    reportSecurityException("Failed Authentication : Subject has not been created, "
                + ex.getMessage());
  }
  if (subject == null || subject.getPrincipals().isEmpty()) {
    reportSecurityException("Failed Authentication : Invalid Subject");
  }
  Principal principal = getPrincipal(context.getUserPrincipal(), subject);
  SecurityContext sc = createSecurityContext(principal, subject);
  message.put(SecurityContext.class, sc);
}
origin: apache/cxf

public static UserSubject createSubject(SecurityContext securityContext) {
  List<String> roleNames = Collections.emptyList();
  if (securityContext instanceof LoginSecurityContext) {
    roleNames = new ArrayList<>();
    Set<Principal> roles = ((LoginSecurityContext)securityContext).getUserRoles();
    for (Principal p : roles) {
      roleNames.add(p.getName());
    }
  }
  UserSubject subject = new UserSubject(securityContext.getUserPrincipal().getName(), roleNames);
  Message m = JAXRSUtils.getCurrentMessage();
  if (m != null && m.get(AuthenticationMethod.class) != null) {
    subject.setAuthenticationMethod(m.get(AuthenticationMethod.class));
  }
  return subject;
}
origin: org.apache.cxf/cxf-core

protected boolean authorize(SecurityContext sc, Method method) {
  List<String> expectedRoles = getExpectedRoles(method);
  if (expectedRoles.isEmpty()) {
    List<String> denyRoles = getDenyRoles(method);
    return denyRoles.isEmpty() ? true : isUserInRole(sc, denyRoles, true);
  }
  if (isUserInRole(sc, expectedRoles, false)) {
    return true;
  }
  if (LOG.isLoggable(Level.FINE)) {
    LOG.fine(sc.getUserPrincipal().getName() + " is not authorized");
  }
  return false;
}
protected boolean isMethodProtected(Method method) {
origin: org.apache.cxf/cxf-bundle-jaxrs

public void handleMessage(Message message) throws Fault {
  SecurityToken token = message.get(SecurityToken.class);
  if (token == null) {
    reportSecurityException("Security Token is not available on the current message");
  }
  
  SecurityContext context = message.get(SecurityContext.class);
  if (context == null || context.getUserPrincipal() == null) {
    reportSecurityException("User Principal is not available on the current message");
  }
  
  Subject subject = null;
  try {
    subject = createSubject(token);
  } catch (Exception ex) {
    reportSecurityException("Failed Authentication : Subject has not been created, " 
                + ex.getMessage()); 
  }
  if (subject == null || subject.getPrincipals().size() == 0) {
    reportSecurityException("Failed Authentication : Invalid Subject");
  }
  
  Principal principal = getPrincipal(context.getUserPrincipal(), subject);        
  SecurityContext sc = createSecurityContext(principal, subject);
  message.put(SecurityContext.class, sc);
}

origin: org.apache.cxf/cxf-rt-rs-security-xml

protected String getUserName(Crypto crypto, Message message) {
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    return sc.getUserPrincipal().getName();
  }
  return RSSecurityUtils.getUserName(crypto, null);
}
origin: org.apache.cxf/cxf-core

public void handleMessage(Message message) throws Fault {
  Method method = getTargetMethod(message);
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    if (authorize(sc, method)) {
      return;
    }
  } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) {
    return;
  }
  throw new AccessDeniedException("Unauthorized");
}
origin: org.apache.cxf/cxf-rt-core

public void handleMessage(Message message) throws Fault {
  Method method = getTargetMethod(message);
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    if (authorize(sc, method)) {
      return;
    }
  } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) {
    return;
  }
  
  
  throw new AccessDeniedException("Unauthorized");
}

origin: org.apache.cxf/cxf-bundle

public void handleMessage(Message message) throws Fault {
  Method method = getTargetMethod(message);
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    if (authorize(sc, method)) {
      return;
    }
  } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) {
    return;
  }
  
  
  throw new AccessDeniedException("Unauthorized");
}

origin: org.apache.cxf/cxf-bundle-minimal

public void handleMessage(Message message) throws Fault {
  Method method = getTargetMethod(message);
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    if (authorize(sc, method)) {
      return;
    }
  } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) {
    return;
  }
  
  
  throw new AccessDeniedException("Unauthorized");
}

origin: apache/cxf

public void handleMessage(Message message) throws Fault {
  Method method = getTargetMethod(message);
  SecurityContext sc = message.get(SecurityContext.class);
  if (sc != null && sc.getUserPrincipal() != null) {
    if (authorize(sc, method)) {
      return;
    }
  } else if (!isMethodProtected(method) && isAllowAnonymousUsers()) {
    return;
  }
  throw new AccessDeniedException("Unauthorized");
}
org.apache.cxf.securitySecurityContext

Javadoc

Provides basic security information about the current message exchange

Most used methods

  • getUserPrincipal
  • isUserInRole

Popular classes and methods

  • setScale (BigDecimal)
    Returns a new BigDecimal instance with the specified scale. If the new scale is greater than the old
  • getSharedPreferences (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • BorderLayout (java.awt)
  • Proxy (java.net)
    This class represents a proxy setting, typically a type (http, socks) and a socket address. A Proxy
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • JLabel (javax.swing)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)