Giter Site home page Giter Site logo

unicon / cas-client-autoconfig-support Goto Github PK

View Code? Open in Web Editor NEW
164.0 32.0 73.0 262 KB

Annotation-based configuration support for Apereo CAS Java clients

License: Apache License 2.0

Java 100.00%
spring spring-boot central-authentication-service cas cas-client spring-boot-autoconfig spring-boot-starter

cas-client-autoconfig-support's Introduction

cas-client-autoconfig-support

NOTE

The code from this project has been merged into official Apereo Java CAS client library as a module. The maintenance of this project has been discontinued. Please see Official CAS client module

Library providing annotation-based configuration support for CAS Java clients. Primarily designed for super easy CASification of Spring Boot apps.

This project was developed as part of Unicon's Open Source Support program. Professional Support / Integration Assistance for this module is available. For more information visit.

Current version

2.3.0-GA

Usage

  • Define a dependency:

Maven:

<dependency>
    <groupId>net.unicon.cas</groupId>
    <artifactId>cas-client-autoconfig-support</artifactId>
    <version>2.3.0-GA</version>      
</dependency>

Gradle:

dependencies {
      ...
      compile 'net.unicon.cas:cas-client-autoconfig-support:2.3.0-GA'
      ...
}
  • Add the following required properties

in Spring Boot's application.properties or application.yml Example:

   cas.server-url-prefix=https://cashost.com/cas
   cas.server-login-url=https://cashost.com/cas/login
   cas.client-host-url=https://casclient.com
  • Annotate Spring Boot application (or any @Configuration class) with @EnableCasClient annotation
    @SpringBootApplication
    @Controller
    @EnableCasClient
    public class MyApplication { .. }

For CAS3 protocol (authentication and validation filters) - which is default if nothing is specified

   cas.validation-type=CAS3

For CAS2 protocol (authentication and validation filters)

   cas.validation-type=CAS

For SAML protocol (authentication and validation filters)

   cas.validation-type=SAML

Available optional properties

  • cas.authentication-url-patterns
  • cas.validation-url-patterns
  • cas.request-wrapper-url-patterns
  • cas.assertion-thread-local-url-patterns
  • cas.gateway
  • cas.use-session
  • cas.redirect-after-validation
  • cas.allowed-proxy-chains
  • cas.proxy-callback-url
  • cas.proxy-receptor-url
  • cas.accept-any-proxy
  • server.context-parameters.renew

Advanced configuration

This library does not expose ALL the CAS client configuration options via standard Spring property sources, but only most commonly used ones. If there is a need however, to set any number of not exposed, 'exotic' properties, there is a way: just extend CasClientConfigurerAdapter class in your @EnableCasClient annotated class and override appropriate configuration method(s) for CAS client filter(s) in question. For example:

    @SpringBootApplication
    @EnableCasClient
    class CasProtectedApplication extends CasClientConfigurerAdapter {    
        @Override
        void configureValidationFilter(FilterRegistrationBean validationFilter) {           
            validationFilter.getInitParameters().put("millisBetweenCleanUps", "120000");
        }        
        @Override
        void configureAuthenticationFilter(FilterRegistrationBean authenticationFilter) {
            authenticationFilter.getInitParameters().put("artifactParameterName", "casTicket");
            authenticationFilter.getInitParameters().put("serviceParameterName", "targetService");
        }                                
    }

cas-client-autoconfig-support's People

Contributors

dima767 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cas-client-autoconfig-support's Issues

Any example?

Hi
I am pretty new to CAS. I have an Spring-boot application which i want to use CAS to authenticate.
I couldnt find any good and up to date example using CAS on Spring boot. I came across this project and it seems perfect to my use, but i cant use it. I tried to use your guide but it doesnt work. I cant even compile my application anymore. When i remove scope runtime from the maven dependency then i get another compilation error
Error:java: java.lang.NoClassDefFoundError: org/json/JSONException
I dont find where the problem is.

Is there any example using this project?

How do you retrieve the user principal and attributes from the cas client

Hello,

I have successfully configured the cas client, but I fail to retrieve the user principal and attributes.
The following code always show "No user"

    public static String getCurrentLogin() {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        Authentication authentication = securityContext.getAuthentication();
        String userName = "No user";

        if (authentication != null) {
            if (authentication.getPrincipal() instanceof UserDetails) {
                UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal();
                userName = springSecurityUser.getUsername();
            } else if (authentication.getPrincipal() instanceof String) {
                userName = (String) authentication.getPrincipal();
            }
            userName = "No username";
        }

        return userName;
    }

Thank you in advance.

Migrate to @ConfigurationProperties

Hi,

Instead of @Value, could you please migrate these to a simple POJO annotated with @ConfigurationProperties. This not only gives you better support for relaxed binding but if you enable the spring-boot-configuration-processor you'll offer content assist for those keys in the IDE (STS, Intellij IDEA and Netbeans are offering such Spring Boot support now)

I am happy to help you migrating to that model.

See also the documentation

Protecting URLs based on the attributes returned from the principal

I was wondering if there was a way to use the attributes returned from the principal to protect certain URLs globally. Currently I am handling the check in each controller method like this using a custom util class:

Optional<Map> attributes = userUtil.hasAuthority(request); if(!attributes.isPresent()) { return "redirect:/401"; }

The specific attributes I am checking against is the return of certain Active Directory groups. An example of what I want would be something along the lines of what Spring Security offers:

@Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/").hasAuthority("ADGroup");

I really appreciate all of the work you've done on this project, it has helped us out tremendously and would really appreciate some guidance with this step.

Thank you,
Brennan Turner

cas logout url?

Is there a property for cas.server-logout-url? How does one go about configuring/implementing CAS logout functionality?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.