GithubHelp home page GithubHelp logo

example-spring-boot-security's Introduction

example-spring-boot-security's People

Contributors

bkielczewski 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  avatar  avatar  avatar

example-spring-boot-security's Issues

Getting a popup for credential

Hi,

When I used the same approach in my application I'm getting window popup for authentication. Not able go on login screen.
Also I'm using HTML 5 Angular JS and Rest Controller. Please suggest if I need to do some extraa configuration.

Thanks,
Nirmal

add oauth2 config, but post to /oauth/token get error: org.springframework.security.core.userdetails.User cannot be cast to com.pingenie.mgt.domain.CurrentUser

@configuration
@EnableAuthorizationServer
public class OAuth2AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

private static final Logger LOGGER = LoggerFactory.getLogger(OAuth2AuthorizationServerConfig.class);

@Value("${config.oauth2.privateKey}")
private String privateKey;

@Value("${config.oauth2.publicKey}")
private String publicKey;

@Autowired
private AuthenticationManager authenticationManager;

@Bean
public JwtAccessTokenConverter tokenEnhancer() {
    LOGGER.info("Initializing JWT with public key:\n" + publicKey);
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    converter.setSigningKey(privateKey);
    converter.setVerifierKey(publicKey);
    return converter;
}

@Bean
public JwtTokenStore tokenStore() {
    return new JwtTokenStore(tokenEnhancer());
}

/**
 * Defines the security constraints on the token endpoints /oauth/token_key and /oauth/check_token
 * Client credentials are required to access the endpoints
 *
 * @param oauthServer
 * @throws Exception
 */
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
    oauthServer
            .tokenKeyAccess("isAnonymous() || hasRole('ROLE_TRUSTED_CLIENT')") // permitAll()
            .checkTokenAccess("hasRole('TRUSTED_CLIENT')"); // isAuthenticated()

    // oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()"); // 另外一种写法!
}

/**
 * Defines the authorization and token endpoints and the token services
 *
 * @param endpoints
 * @throws Exception
 */
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints

            // Which authenticationManager should be used for the password grant
            // If not provided, ResourceOwnerPasswordTokenGranter is not configured
            .authenticationManager(authenticationManager)

            // Use JwtTokenStore and our jwtAccessTokenConverter
            .tokenStore(tokenStore())
            .accessTokenConverter(tokenEnhancer())
    ;
}

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()

            // Confidential client where client secret can be kept safe (e.g. server side)
            .withClient("confidential").secret("secret")
            .authorizedGrantTypes("client_credentials", "authorization_code", "refresh_token")
            .scopes("read", "write")
            .redirectUris("http://192.168.1.99:8080/")

            .and()

            // Public client where client secret is vulnerable (e.g. mobile apps, browsers)
            .withClient("public") // No secret!
            .authorizedGrantTypes("client_credentials", "implicit")
            .scopes("read")
            .redirectUris("http://192.168.1.99:8080/")

            .and()

            // Trusted client: similar to confidential client but also allowed to handle user password
            .withClient("trusted").secret("secret")
            .authorities("ROLE_TRUSTED_CLIENT")
            .authorizedGrantTypes("client_credentials", "password", "authorization_code", "refresh_token")
            .scopes("read", "write")
            .redirectUris("http://192.168.1.99:8080/")
    ;
}

}


@configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private UserDetailsService userDetailsService;

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .antMatchers("/", "/oauth/**", "/respond/**", "/html5shiv/**", "/images/**", "/css/**", "/js/**", "/jquery/**", "/bootstrap-3.3.6/**", "/angularjs/**").permitAll()
            .antMatchers("/users/**").hasAuthority("ADMIN")
            .anyRequest().fullyAuthenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .failureUrl("/login?error")
            .usernameParameter("email")
            .permitAll()
            .and()
            .logout()
            .logoutUrl("/logout")
            .deleteCookies("remember-me")
            .logoutSuccessUrl("/")
            .permitAll()
            .and()
            .rememberMe();
}

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
            .userDetailsService(userDetailsService)
            .passwordEncoder(new BCryptPasswordEncoder());

}

}

session

did you implemented the session??

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.